diff options
author | Ferenc Arn <tagcup@yahoo.com> | 2017-03-29 11:51:31 -0500 |
---|---|---|
committer | Ferenc Arn <tagcup@yahoo.com> | 2017-03-29 12:04:49 -0500 |
commit | 97d510531a56acba1898a863efe113bf24acc0a2 (patch) | |
tree | b353e10ee5bfcd38ef9d2d95d0b40a37a44d0f7a /core | |
parent | 000e8730088ed241439a311c1bd0167f741ffbd1 (diff) |
Fix polar decomposition in 2D.
When performing polar decomposition in 2D as B = R.S, where R is rotation (with determinant +1) and S is scaling, use the convention that reflections are absorbed into S through a reflection around y axis.
In 3D, this is done by using a reflection along all three axes, but since the dimensionality is even in 2D, one axis needs to be chosen.
Fixes Matrix32::get_rotation and Matrix32::get_scale (which weren't properly fixed in #7445).
Diffstat (limited to 'core')
-rw-r--r-- | core/math/math_2d.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 021b1fbf55..8f942c423f 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -449,7 +449,7 @@ real_t Transform2D::get_rotation() const { real_t det = basis_determinant(); Transform2D m = orthonormalized(); if (det < 0) { - m.scale_basis(Size2(-1, -1)); + m.scale_basis(Size2(1, -1)); // convention to separate rotation and reflection for 2D is to absorb a flip along y into scaling. } return Math::atan2(m[0].y, m[0].x); } @@ -477,7 +477,7 @@ Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) { Size2 Transform2D::get_scale() const { real_t det_sign = basis_determinant() > 0 ? 1 : -1; - return det_sign * Size2(elements[0].length(), elements[1].length()); + return Size2(elements[0].length(), det_sign * elements[1].length()); } void Transform2D::scale(const Size2 &p_scale) { |