From f271591ac22bd07e1b2316448dd6e9af879c218f Mon Sep 17 00:00:00 2001 From: Ferenc Arn Date: Thu, 5 Jan 2017 23:27:48 -0600 Subject: Various corrections in 2D math. This is the follow up for the 2D changes mentioned in PR #6865. It fixes various mistakes regarding the order of matrix indices, order of transformation operations, usage of atan2 function and ensures that the sense of rotation is compatible with a left-handed coordinate system with Y-axis pointing down (which flips the sense of rotations along the z-axis). Also replaced float with real_t, and tried to make use of Matrix32 methods rather than accessing its elements directly. Affected code in the Godot code base is also fixed in this commit. The user code using functions involving angles such as atan2, angle_to, get_rotation, set_rotation will need to be updated to conform with the new behavior. Furthermore, the sign of the rotation angles in existing 2D scene files need to be flipped as well. --- tools/editor/plugins/canvas_item_editor_plugin.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 5fa0d88ca5..df33651684 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -1601,10 +1601,8 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (node) { - Matrix32 rot; - rot.elements[1] = (dfrom - center).normalized(); - rot.elements[0] = rot.elements[1].tangent(); - node->set_rotation(snap_angle(rot.xform_inv(dto-center).angle() + node->get_rotation(), node->get_rotation())); + real_t angle = node->get_rotation(); + node->set_rotation(snap_angle( angle + (dfrom - center).angle_to(dto-center), angle )); display_rotate_to = dto; display_rotate_from = center; viewport->update(); @@ -1616,10 +1614,8 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (node) { - Matrix32 rot; - rot.elements[1] = (dfrom - center).normalized(); - rot.elements[0] = rot.elements[1].tangent(); - node->set_rotation(snap_angle(rot.xform_inv(dto-center).angle() + node->get_rotation(), node->get_rotation())); + real_t angle = node->get_rotation(); + node->set_rotation(snap_angle( angle + (dfrom - center).angle_to(dto-center), angle )); display_rotate_to = dto; display_rotate_from = center; viewport->update(); -- cgit v1.2.3