summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-24 22:51:27 +0100
committerGitHub <noreply@github.com>2017-03-24 22:51:27 +0100
commitbeba97c0c34bd4e88d8a1e34d26dad6c2340cc6e (patch)
treea6f0a45dd345fbd2816cf1b969b8de0b9b356e39 /core
parentfb46323022222ab52ab357508a4e96e619baa599 (diff)
parent6bb9b58b09aee7fc543c03844ce51b62c838dadd (diff)
Merge pull request #8122 from tagcup/axis_check_normalization
Explicitly documented that Transform.basis is not necessarily an orth…
Diffstat (limited to 'core')
-rw-r--r--core/math/matrix3.cpp2
-rw-r--r--core/math/vector3.h5
2 files changed, 7 insertions, 0 deletions
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index 98cab39ba3..b31df2fadb 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -575,6 +575,8 @@ Basis::Basis(const Quat &p_quat) {
Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
+ ERR_FAIL_COND(p_axis.is_normalized() == false);
+
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
real_t cosine = Math::cos(p_phi);
diff --git a/core/math/vector3.h b/core/math/vector3.h
index fc02e66c33..097d6b9480 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -75,6 +75,7 @@ struct Vector3 {
_FORCE_INLINE_ void normalize();
_FORCE_INLINE_ Vector3 normalized() const;
+ _FORCE_INLINE_ bool is_normalized() const;
_FORCE_INLINE_ Vector3 inverse() const;
_FORCE_INLINE_ void zero();
@@ -385,6 +386,10 @@ Vector3 Vector3::normalized() const {
return v;
}
+bool Vector3::is_normalized() const {
+ return Math::isequal_approx(length(), (real_t)1.0);
+}
+
Vector3 Vector3::inverse() const {
return Vector3(1.0 / x, 1.0 / y, 1.0 / z);