summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFerenc Arn <tagcup@yahoo.com>2016-10-18 15:50:21 -0500
committerFerenc Arn <tagcup@yahoo.com>2017-01-03 17:41:04 -0600
commitbd7ba0b664fa98381db9ef8edb69ba211213d595 (patch)
tree8e313066ce55a3366cd6b972ff429372583cda28 /tools
parentf2e99826c0b1e8227644bfab0795d858c504d279 (diff)
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/collada/collada.cpp6
-rw-r--r--tools/editor/plugins/cube_grid_theme_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/editor_preview_plugins.cpp4
-rw-r--r--tools/editor/plugins/material_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/mesh_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/multimesh_editor_plugin.cpp10
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.cpp22
7 files changed, 27 insertions, 27 deletions
diff --git a/tools/collada/collada.cpp b/tools/collada/collada.cpp
index c62affe5ad..204de45082 100644
--- a/tools/collada/collada.cpp
+++ b/tools/collada/collada.cpp
@@ -144,7 +144,7 @@ Transform Collada::Node::compute_transform(Collada &state) const {
case XForm::OP_ROTATE: {
if (xf.data.size()>=4) {
- xform_step.rotate(Vector3(xf.data[0],xf.data[1],xf.data[2]),-Math::deg2rad(xf.data[3]));
+ xform_step.rotate(Vector3(xf.data[0],xf.data[1],xf.data[2]),Math::deg2rad(xf.data[3]));
}
} break;
case XForm::OP_SCALE: {
@@ -1604,7 +1604,7 @@ Collada::Node* Collada::_parse_visual_instance_camera(XMLParser& parser) {
cam->camera= _uri_to_id(parser.get_attribute_value_safe("url"));
if (state.up_axis==Vector3::AXIS_Z) //collada weirdness
- cam->post_transform.basis.rotate(Vector3(1,0,0),Math_PI*0.5);
+ cam->post_transform.basis.rotate(Vector3(1,0,0),-Math_PI*0.5);
if (parser.is_empty()) //nothing else to parse...
return cam;
@@ -1625,7 +1625,7 @@ Collada::Node* Collada::_parse_visual_instance_light(XMLParser& parser) {
cam->light= _uri_to_id(parser.get_attribute_value_safe("url"));
if (state.up_axis==Vector3::AXIS_Z) //collada weirdness
- cam->post_transform.basis.rotate(Vector3(1,0,0),Math_PI*0.5);
+ cam->post_transform.basis.rotate(Vector3(1,0,0),-Math_PI*0.5);
if (parser.is_empty()) //nothing else to parse...
return cam;
diff --git a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp
index 0c2ec15367..a5f447cfd9 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<MeshLibrary> 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 fbda0776b0..c07eacf69e 100644
--- a/tools/editor/plugins/editor_preview_plugins.cpp
+++ b/tools/editor/plugins/editor_preview_plugins.cpp
@@ -807,8 +807,8 @@ Ref<Texture> 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 9c279fa967..3ef1818135 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 785efebfc8..13f3204a05 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 22981a2877..a548f26f1e 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<instance_count;i++) {
@@ -238,9 +238,9 @@ void MultiMeshEditor::_populate() {
Matrix3 post_xform;
- post_xform.rotate(xform.basis.get_axis(0),Math::random(-_tilt_random,_tilt_random)*Math_PI);
- post_xform.rotate(xform.basis.get_axis(2),Math::random(-_tilt_random,_tilt_random)*Math_PI);
- post_xform.rotate(xform.basis.get_axis(1),Math::random(-_rotate_random,_rotate_random)*Math_PI);
+ post_xform.rotate(xform.basis.get_axis(0),-Math::random(-_tilt_random,_tilt_random)*Math_PI);
+ post_xform.rotate(xform.basis.get_axis(2),-Math::random(-_tilt_random,_tilt_random)*Math_PI);
+ post_xform.rotate(xform.basis.get_axis(1),-Math::random(-_rotate_random,_rotate_random)*Math_PI);
xform.basis = post_xform * xform.basis;
//xform.basis.orthonormalize();
diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp
index 44d3b63335..70a256fd2c 100644
--- a/tools/editor/plugins/spatial_editor_plugin.cpp
+++ b/tools/editor/plugins/spatial_editor_plugin.cpp
@@ -61,8 +61,8 @@ void SpatialEditorViewport::_update_camera() {
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);
if (orthogonal)
camera_transform.translate(0, 0, 4096);
@@ -474,8 +474,8 @@ Vector3 SpatialEditorViewport::_get_screen_to_space(const Vector3& p_pos) {
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);
camera_transform.translate(0,0,cursor.distance);
return camera_transform.xform(Vector3( ((p_pos.x/get_size().width)*2.0-1.0)*screen_w, ((1.0-(p_pos.y/get_size().height))*2.0-1.0)*screen_h,-get_znear()));
@@ -1484,7 +1484,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
Transform r;
- r.basis.rotate(plane.normal,-angle);
+ r.basis.rotate(plane.normal,angle);
List<Node*> &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);