diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-05-16 23:24:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 23:24:56 +0200 |
commit | 36a74696d6751957c1d345ed1c7633d8b68ba827 (patch) | |
tree | 73ca2106917b826f93de8d5048b07db982f6cb79 /core/math/vector3.h | |
parent | 2cf36651b968e99602445678e1fa6ea0adfc078a (diff) | |
parent | ed7aadcd87a64cde70febc8ee313860e8c67dcaf (diff) |
Merge pull request #18804 from tagcup/vec_slerp
Add SLERP to Vector{2,3}, optimize Quat's Vector3 rotation.
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r-- | core/math/vector3.h | 10 |
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(); |