diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-08-08 07:55:21 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-08-08 07:55:21 -0300 |
commit | 5e1116da4ce052acc64f45ba4bd71310b4826aea (patch) | |
tree | d112c1c4a0e8a5f6ced7a9e75f962cbf9773af47 /editor/plugins/spatial_editor_plugin.cpp | |
parent | 1939e83a653b3263eeac820a9e36d751a314068b (diff) |
Added proper local transform snapping, closes #4985
Diffstat (limited to 'editor/plugins/spatial_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 50d2f193ed..0dba1f12a2 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1190,17 +1190,47 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { motion = motion_mask.dot(motion) * motion_mask; } + //set_message("Translating: "+motion); + + List<Node *> &selection = editor_selection->get_selected_node_list(); + float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { snap = spatial_editor->get_translate_snap(); - motion.snap(Vector3(snap, snap, snap)); - } + bool local_coords = spatial_editor->are_local_coords_enabled(); + + if (local_coords) { + bool multiple = false; + Spatial *node = NULL; + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + + Spatial *sp = E->get()->cast_to<Spatial>(); + if (!sp) { + continue; + } + if (node) { + multiple = true; + break; + } else { + node = sp; + } + } - //set_message("Translating: "+motion); + if (multiple) { + motion.snap(Vector3(snap, snap, snap)); + } else { + Basis b = node->get_global_transform().basis.orthonormalized(); + Vector3 local_motion = b.inverse().xform(motion); + local_motion.snap(Vector3(snap, snap, snap)); + motion = b.xform(local_motion); + } - List<Node *> &selection = editor_selection->get_selected_node_list(); + } else { + motion.snap(Vector3(snap, snap, snap)); + } + } for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { |