From bd7ba0b664fa98381db9ef8edb69ba211213d595 Mon Sep 17 00:00:00 2001 From: Ferenc Arn Date: Tue, 18 Oct 2016 15:50:21 -0500 Subject: Use right handed coordinate system for rotation matrices and quaternions. Also fixes Euler angles (XYZ convention, which is used as default by Blender). Furthermore, functions which expect a rotation matrix will now give an error simply, rather than trying to orthonormalize such matrices. The documentation for such functions has be updated accordingly. This commit breaks code using 3D rotations, and is a part of the breaking changes in 2.1 -> 3.0 transition. The code affected within Godot code base is fixed in this commit. --- .../plugins/cube_grid_theme_editor_plugin.cpp | 4 ++-- tools/editor/plugins/editor_preview_plugins.cpp | 4 ++-- tools/editor/plugins/material_editor_plugin.cpp | 4 ++-- tools/editor/plugins/mesh_editor_plugin.cpp | 4 ++-- tools/editor/plugins/multimesh_editor_plugin.cpp | 10 +++++----- tools/editor/plugins/spatial_editor_plugin.cpp | 22 +++++++++++----------- 6 files changed, 24 insertions(+), 24 deletions(-) (limited to 'tools/editor/plugins') diff --git a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp index 0c2ec1536..a5f447cfd 100644 --- a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -179,8 +179,8 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, Vector3 ofs = aabb.pos + aabb.size*0.5; aabb.pos-=ofs; Transform xform; - xform.basis=Matrix3().rotated(Vector3(0,1,0),Math_PI*0.25); - xform.basis = Matrix3().rotated(Vector3(1,0,0),-Math_PI*0.25)*xform.basis; + xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.25); + xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.25)*xform.basis; AABB rot_aabb = xform.xform(aabb); print_line("rot_aabb: "+rot_aabb); float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; diff --git a/tools/editor/plugins/editor_preview_plugins.cpp b/tools/editor/plugins/editor_preview_plugins.cpp index fbda0776b..c07eacf69 100644 --- a/tools/editor/plugins/editor_preview_plugins.cpp +++ b/tools/editor/plugins/editor_preview_plugins.cpp @@ -807,8 +807,8 @@ Ref EditorMeshPreviewPlugin::generate(const RES& p_from) { Vector3 ofs = aabb.pos + aabb.size*0.5; aabb.pos-=ofs; Transform xform; - xform.basis=Matrix3().rotated(Vector3(0,1,0),Math_PI*0.125); - xform.basis = Matrix3().rotated(Vector3(1,0,0),-Math_PI*0.125)*xform.basis; + xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.125); + xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.125)*xform.basis; AABB rot_aabb = xform.xform(aabb); float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; if (m==0) diff --git a/tools/editor/plugins/material_editor_plugin.cpp b/tools/editor/plugins/material_editor_plugin.cpp index 9c279fa96..3ef181813 100644 --- a/tools/editor/plugins/material_editor_plugin.cpp +++ b/tools/editor/plugins/material_editor_plugin.cpp @@ -129,8 +129,8 @@ MaterialEditor::MaterialEditor() { viewport->add_child(box_instance); Transform box_xform; - box_xform.basis.rotate(Vector3(1,0,0),Math::deg2rad(-25)); - box_xform.basis = box_xform.basis * Matrix3().rotated(Vector3(0,1,0),Math::deg2rad(-25)); + box_xform.basis.rotate(Vector3(1,0,0),Math::deg2rad(25)); + box_xform.basis = box_xform.basis * Matrix3().rotated(Vector3(0,1,0),Math::deg2rad(25)); box_xform.basis.scale(Vector3(0.8,0.8,0.8)); box_instance->set_transform(box_xform); diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp index 785efebfc..13f3204a0 100644 --- a/tools/editor/plugins/mesh_editor_plugin.cpp +++ b/tools/editor/plugins/mesh_editor_plugin.cpp @@ -82,8 +82,8 @@ void MeshEditor::_notification(int p_what) { void MeshEditor::_update_rotation() { Transform t; - t.basis.rotate(Vector3(0, 1, 0), rot_y); - t.basis.rotate(Vector3(1, 0, 0), rot_x); + t.basis.rotate(Vector3(0, 1, 0), -rot_y); + t.basis.rotate(Vector3(1, 0, 0), -rot_x); mesh_instance->set_transform(t); } diff --git a/tools/editor/plugins/multimesh_editor_plugin.cpp b/tools/editor/plugins/multimesh_editor_plugin.cpp index 22981a287..a548f26f1 100644 --- a/tools/editor/plugins/multimesh_editor_plugin.cpp +++ b/tools/editor/plugins/multimesh_editor_plugin.cpp @@ -207,10 +207,10 @@ void MultiMeshEditor::_populate() { Transform axis_xform; if (axis==Vector3::AXIS_Z) { - axis_xform.rotate(Vector3(1,0,0),Math_PI*0.5); + axis_xform.rotate(Vector3(1,0,0),-Math_PI*0.5); } if (axis==Vector3::AXIS_X) { - axis_xform.rotate(Vector3(0,0,1),Math_PI*0.5); + axis_xform.rotate(Vector3(0,0,1),-Math_PI*0.5); } for(int i=0;i &selection = editor_selection->get_selected_node_list(); @@ -1591,8 +1591,8 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { Transform camera_transform; camera_transform.translate(cursor.pos); - camera_transform.basis.rotate(Vector3(0,1,0),cursor.y_rot); - camera_transform.basis.rotate(Vector3(1,0,0),cursor.x_rot); + camera_transform.basis.rotate(Vector3(0,1,0),-cursor.y_rot); + camera_transform.basis.rotate(Vector3(1,0,0),-cursor.x_rot); Vector3 translation(-m.relative_x*pan_speed,m.relative_y*pan_speed,0); translation*=cursor.distance/DISTANCE_DEFAULT; camera_transform.translate(translation); @@ -2810,7 +2810,7 @@ void SpatialEditor::_xform_dialog_action() { continue; Vector3 axis; axis[i]=1.0; - t.basis.rotate(axis,rotate[i]); + t.basis.rotate(axis,rotate[i]); // BUG(?): Angle not flipped; please check during the review of PR #6865. } for(int i=0;i<3;i++) { @@ -3160,7 +3160,7 @@ void SpatialEditor::_init_indicators() { - light_transform.rotate(Vector3(1,0,0),Math_PI/5.0); + light_transform.rotate(Vector3(1,0,0),-Math_PI/5.0); VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); @@ -3773,8 +3773,8 @@ void SpatialEditor::_update_ambient_light_color(const Color& p_color) { void SpatialEditor::_update_default_light_angle() { Transform t; - t.basis.rotate(Vector3(1,0,0),settings_default_light_rot_x); - t.basis.rotate(Vector3(0,1,0),settings_default_light_rot_y); + t.basis.rotate(Vector3(1,0,0),-settings_default_light_rot_x); + t.basis.rotate(Vector3(0,1,0),-settings_default_light_rot_y); settings_dlight->set_transform(t); if (light_instance.is_valid()) { VS::get_singleton()->instance_set_transform(light_instance,t); -- cgit v1.3.1