From 6b1252cdfa5988b77917518bc291a0cc34e5066e Mon Sep 17 00:00:00 2001 From: Ferenc Arn Date: Thu, 5 Jan 2017 11:31:39 -0600 Subject: Fix the order in which additional transformations are applied in Matrix3 and Transform. This is a part of the breaking changes proposed in PR #6865, solving the issue regarding the order of affine transformations described in #2565. This PR also fixes the affected code within Godot codebase. Includes improvements to documentation too. Another change is, Matrix3::get_scale() will now return negative scaling when the determinant of the matrix is negative. The rationale behind this is simple: when performing a polar decomposition on a basis matrix M = R.S, we have to ensure that the determinant of R is +1, such that it is a proper rotation matrix (with no reflections) which can be represented by Euler angles or a quaternion. Also replaced the few instances of float with real_t in Matrix3 and Transform. Furthermore, this PR fixes an issue introduced due to the API breakage in #6865. Namely Matrix3::get_euler() now only works with proper rotation matrices. As a result, the code that wants to get the rotation portion of a transform needs to use Matrix3::get_rotation() introduced in this commit, which complements Matrix3::get_scaled(), providing both parts of the polar decomposition. Finally, it is now possible to construct a rotation matrix from Euler angles using the new constructor Matrix3::Matrix3(const Vector3 &p_euler). --- scene/3d/spatial.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'scene/3d/spatial.cpp') diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index b5e80c48a..50f9e4501 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -83,9 +83,9 @@ void Spatial::_notify_dirty() { void Spatial::_update_local_transform() const { - - data.local_transform.basis.set_euler(data.rotation); + data.local_transform.basis = Matrix3(); data.local_transform.basis.scale(data.scale); + data.local_transform.basis.rotate(data.rotation); data.dirty&=~DIRTY_LOCAL; } @@ -376,7 +376,7 @@ void Spatial::_set_rotation_deg(const Vector3& p_euler_deg) { void Spatial::set_scale(const Vector3& p_scale){ if (data.dirty&DIRTY_VECTORS) { - data.rotation=data.local_transform.basis.get_euler(); + data.rotation=data.local_transform.basis.get_rotation(); data.dirty&=~DIRTY_VECTORS; } @@ -398,7 +398,8 @@ Vector3 Spatial::get_rotation() const{ if (data.dirty&DIRTY_VECTORS) { data.scale=data.local_transform.basis.get_scale(); - data.rotation=data.local_transform.basis.get_euler(); + data.rotation=data.local_transform.basis.get_rotation(); + data.dirty&=~DIRTY_VECTORS; } @@ -422,7 +423,8 @@ Vector3 Spatial::get_scale() const{ if (data.dirty&DIRTY_VECTORS) { data.scale=data.local_transform.basis.get_scale(); - data.rotation=data.local_transform.basis.get_euler(); + data.rotation=data.local_transform.basis.get_rotation(); + data.dirty&=~DIRTY_VECTORS; } -- cgit v1.2.3-70-g09d2