diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2019-07-24 08:41:09 -0400 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2019-07-25 19:40:35 -0400 |
commit | 53d2a4e9056a967eba625b7b930d87bf8804cc7e (patch) | |
tree | e5846279228b54c7174ca1d1304b92da42396b56 /editor/plugins | |
parent | d483a85a0ff4462fe7bff5d5ff6ea69c66cab417 (diff) |
Snap transform gizmo values in the 3D editor
Snap to step size, and then also be careful to only display that many digits (to avoid numbers like 1.234001)
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 52fadf1e71..630f3ba9e1 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1291,6 +1291,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 ray_pos = _get_ray_pos(m->get_position()); Vector3 ray = _get_ray(m->get_position()); + float snap = EDITOR_GET("interface/inspector/default_float_step"); + int snap_step_decimals = Math::range_step_decimals(snap); switch (_edit.mode) { @@ -1372,18 +1374,14 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { - snap = spatial_editor->get_scale_snap() / 100; - - Vector3 motion_snapped = motion; - motion_snapped.snap(Vector3(snap, snap, snap)); - set_message(TTR("Scaling: ") + motion_snapped); - - } else { - set_message(TTR("Scaling: ") + motion); } + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + // This might not be necessary anymore after issue #288 is solved (in 4.0?). + set_message(TTR("Scaling: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1502,17 +1500,13 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { - snap = spatial_editor->get_translate_snap(); - - Vector3 motion_snapped = motion; - motion_snapped.snap(Vector3(snap, snap, snap)); - set_message(TTR("Translating: ") + motion_snapped); - } else { - set_message(TTR("Translating: ") + motion); } + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + set_message(TTR("Translating: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1601,20 +1595,12 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center)); if (_edit.snap || spatial_editor->is_snap_enabled()) { - - float snap = spatial_editor->get_rotate_snap(); - - if (snap) { - angle = Math::rad2deg(angle) + snap * 0.5; //else it won't reach +180 - angle -= Math::fmod(angle, snap); - set_message(vformat(TTR("Rotating %s degrees."), rtos(angle))); - angle = Math::deg2rad(angle); - } else - set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); - - } else { - set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); + snap = spatial_editor->get_rotate_snap(); } + angle = Math::rad2deg(angle) + snap * 0.5; //else it won't reach +180 + angle -= Math::fmod(angle, snap); + set_message(vformat(TTR("Rotating %s degrees."), String::num(angle, snap_step_decimals))); + angle = Math::deg2rad(angle); List<Node *> &selection = editor_selection->get_selected_node_list(); |