summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/math/basis.cpp19
-rw-r--r--core/math/basis.h6
-rw-r--r--core/math/vector3.cpp6
-rw-r--r--core/math/vector3.h1
-rw-r--r--core/variant/variant_call.cpp2
5 files changed, 16 insertions, 18 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;
diff --git a/core/math/basis.h b/core/math/basis.h
index 9d8ed16e29..eb107d7e4e 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -35,6 +35,9 @@
#include "core/math/vector3.h"
class Basis {
+private:
+ void _set_diagonal(const Vector3 &p_diag);
+
public:
Vector3 elements[3] = {
Vector3(1, 0, 0),
@@ -166,8 +169,6 @@ public:
int get_orthogonal_index() const;
void set_orthogonal_index(int p_index);
- void set_diagonal(const Vector3 &p_diag);
-
bool is_orthogonal() const;
bool is_diagonal() const;
bool is_rotation() const;
@@ -254,6 +255,7 @@ public:
Basis(const Vector3 &p_axis, real_t p_phi) { set_axis_angle(p_axis, p_phi); }
Basis(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) { set_axis_angle_scale(p_axis, p_phi, p_scale); }
+ static Basis from_scale(const Vector3 &p_scale);
_FORCE_INLINE_ Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) {
elements[0] = row0;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 401c3ccd9c..fa212c178a 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -115,12 +115,6 @@ Basis Vector3::outer(const Vector3 &p_b) const {
return Basis(row0, row1, row2);
}
-Basis Vector3::to_diagonal_matrix() const {
- return Basis(x, 0, 0,
- 0, y, 0,
- 0, 0, z);
-}
-
bool Vector3::is_equal_approx(const Vector3 &p_v) const {
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z);
}
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 6a4c42f41b..e65ac31c02 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -106,7 +106,6 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3 &p_b) const;
Basis outer(const Vector3 &p_b) const;
- Basis to_diagonal_matrix() const;
_FORCE_INLINE_ Vector3 abs() const;
_FORCE_INLINE_ Vector3 floor() const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 39207df9e7..49a0b455df 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1568,7 +1568,6 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3, dot, sarray("with"), varray());
bind_method(Vector3, cross, sarray("with"), varray());
bind_method(Vector3, outer, sarray("with"), varray());
- bind_method(Vector3, to_diagonal_matrix, sarray(), varray());
bind_method(Vector3, abs, sarray(), varray());
bind_method(Vector3, floor, sarray(), varray());
bind_method(Vector3, ceil, sarray(), varray());
@@ -1732,6 +1731,7 @@ static void _register_variant_builtin_methods() {
bind_method(Basis, is_equal_approx, sarray("b"), varray());
bind_method(Basis, get_rotation_quaternion, sarray(), varray());
bind_static_method(Basis, looking_at, sarray("target", "up"), varray(Vector3(0, 1, 0)));
+ bind_static_method(Basis, from_scale, sarray("scale"), varray());
/* AABB */