summaryrefslogtreecommitdiffstats
path: root/core/math/vector3.h
diff options
context:
space:
mode:
authortagcup <tagcup@yahoo.com>2018-05-11 20:14:39 -0400
committertagcup <tagcup@yahoo.com>2018-05-12 13:05:04 -0400
commited7aadcd87a64cde70febc8ee313860e8c67dcaf (patch)
tree1c9a682a33463feff010a436caf852d4ad4fdcde /core/math/vector3.h
parent81b1d3c846de263cf843e9e0e9d7c0c0a94f65c8 (diff)
downloadredot-engine-ed7aadcd87a64cde70febc8ee313860e8c67dcaf.tar.gz
Add SLERP to Vector{2,3}, optimize Quat's Vector3 rotation.
Also even out Basis and Quat APIs a little.
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r--core/math/vector3.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 3bbfd7627c..433adf09ee 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -91,6 +91,7 @@ struct Vector3 {
/* Static Methods between 2 vector3s */
_FORCE_INLINE_ Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const;
+ _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
@@ -218,6 +219,15 @@ Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
z + (p_t * (p_b.z - z)));
}
+Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
+#ifdef MATH_CHECKS
+ ERR_FAIL_COND_V(is_normalized() == false, Vector3());
+#endif
+
+ real_t theta = angle_to(p_b);
+ return rotated(cross(p_b), theta * p_t);
+}
+
real_t Vector3::distance_to(const Vector3 &p_b) const {
return (p_b - *this).length();