diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-09-17 19:38:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 19:38:36 +0200 |
commit | 220b69ab564566ca00c8263b629e3d3d3cc64eb5 (patch) | |
tree | e14f4e0c715294ecac8162d88ccde4e06671faad /core/math/basis.cpp | |
parent | 7762e8b1c1fbabc69769e8df9d6aa2443d309892 (diff) | |
parent | bf0213470cbfa63bbcce9f614f2cc2ecaae5fe54 (diff) |
Merge pull request #52450 from aaronfranke/they-came-from-scale
Replace Vector3.to_diagonal_matrix with Basis.from_scale
Diffstat (limited to 'core/math/basis.cpp')
-rw-r--r-- | core/math/basis.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp index eec9caf149..a7f89522d7 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -207,6 +207,10 @@ Basis Basis::transposed() const { return tr; } +Basis Basis::from_scale(const Vector3 &p_scale) { + return Basis(p_scale.x, 0, 0, 0, p_scale.y, 0, 0, 0, p_scale.z); +} + // Multiplies the matrix from left by the scaling matrix: M -> S.M // See the comment for Basis::rotated for further explanation. void Basis::scale(const Vector3 &p_scale) { @@ -246,10 +250,7 @@ void Basis::make_scale_uniform() { } Basis Basis::scaled_local(const Vector3 &p_scale) const { - Basis b; - b.set_diagonal(p_scale); - - return (*this) * b; + return (*this) * Basis::from_scale(p_scale); } Vector3 Basis::get_scale_abs() const { @@ -991,21 +992,23 @@ void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) { } void Basis::set_axis_angle_scale(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) { - set_diagonal(p_scale); + _set_diagonal(p_scale); rotate(p_axis, p_phi); } void Basis::set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale) { - set_diagonal(p_scale); + _set_diagonal(p_scale); rotate(p_euler); } void Basis::set_quaternion_scale(const Quaternion &p_quaternion, const Vector3 &p_scale) { - set_diagonal(p_scale); + _set_diagonal(p_scale); rotate(p_quaternion); } -void Basis::set_diagonal(const Vector3 &p_diag) { +// This also sets the non-diagonal elements to 0, which is misleading from the +// name, so we want this method to be private. Use `from_scale` externally. +void Basis::_set_diagonal(const Vector3 &p_diag) { elements[0][0] = p_diag.x; elements[0][1] = 0; elements[0][2] = 0; |