diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-05-01 13:38:04 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-05-01 13:38:04 -0300 |
commit | efb1f7d76b63d56fc0c097d13b4b6d7b91250611 (patch) | |
tree | 98cda38a73f1e6cf4f20c0ab5acda71dd9e40ad2 /core/math/transform_2d.cpp | |
parent | 316b60aa68bc348b8d6ab125ee2fb7cd3793cb49 (diff) |
Implement Skew in Node2D
Skew is x-axis only, because it must be bidirectionally convertible to a 2x3 matrix, but you can subtract it to the rotation to get the effect on y-axis
Diffstat (limited to 'core/math/transform_2d.cpp')
-rw-r--r-- | core/math/transform_2d.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 97a9216a5a..ed95baa233 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -70,6 +70,18 @@ void Transform2D::rotate(real_t p_phi) { *this = Transform2D(p_phi, Vector2()) * (*this); } +real_t Transform2D::get_skew() const { + + real_t det = basis_determinant(); + return Math::acos(elements[0].normalized().dot(SGN(det) * elements[1].normalized())) - Math_PI * 0.5; +} + +void Transform2D::set_skew(float p_angle) { + + real_t det = basis_determinant(); + elements[1] = SGN(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length(); +} + real_t Transform2D::get_rotation() const { real_t det = basis_determinant(); Transform2D m = orthonormalized(); |