summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-05-27 17:42:43 +0200
committerGitHub <noreply@github.com>2019-05-27 17:42:43 +0200
commit7487d2f8521d895df2f16b36d21992f8fde99f75 (patch)
tree11c3a0405e0eb249b77e238d82e34abd660debb8 /core/math
parent9f6eb3882c933ea4049e110f2aed333f692d2d41 (diff)
parent9ff708f0087531c18d7d13cbc24751fe88f2dfa4 (diff)
Merge pull request #28957 from aaronfranke/basis-optimize
Optimize Basis constructor for Axis Angle
Diffstat (limited to 'core/math')
-rw-r--r--core/math/basis.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 9fcecd1ba6..1540bc8fe1 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -813,21 +813,28 @@ void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
ERR_FAIL_COND(!p_axis.is_normalized());
#endif
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);
- real_t sine = Math::sin(p_phi);
-
elements[0][0] = axis_sq.x + cosine * (1.0 - axis_sq.x);
- elements[0][1] = p_axis.x * p_axis.y * (1.0 - cosine) - p_axis.z * sine;
- elements[0][2] = p_axis.z * p_axis.x * (1.0 - cosine) + p_axis.y * sine;
-
- elements[1][0] = p_axis.x * p_axis.y * (1.0 - cosine) + p_axis.z * sine;
elements[1][1] = axis_sq.y + cosine * (1.0 - axis_sq.y);
- elements[1][2] = p_axis.y * p_axis.z * (1.0 - cosine) - p_axis.x * sine;
-
- elements[2][0] = p_axis.z * p_axis.x * (1.0 - cosine) - p_axis.y * sine;
- elements[2][1] = p_axis.y * p_axis.z * (1.0 - cosine) + p_axis.x * sine;
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
+
+ real_t sine = Math::sin(p_phi);
+ real_t t = 1 - cosine;
+
+ real_t xyzt = p_axis.x * p_axis.y * t;
+ real_t zyxs = p_axis.z * sine;
+ elements[0][1] = xyzt - zyxs;
+ elements[1][0] = xyzt + zyxs;
+
+ xyzt = p_axis.x * p_axis.z * t;
+ zyxs = p_axis.y * sine;
+ elements[0][2] = xyzt + zyxs;
+ elements[2][0] = xyzt - zyxs;
+
+ xyzt = p_axis.y * p_axis.z * t;
+ zyxs = p_axis.x * sine;
+ elements[1][2] = xyzt - zyxs;
+ elements[2][1] = xyzt + zyxs;
}
void Basis::set_axis_angle_scale(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) {