You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
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.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user