From 46fbe6b01e095ddb66f3bf6e0516569cfdca8f74 Mon Sep 17 00:00:00 2001 From: Kester Maddock Date: Mon, 22 Nov 2004 10:19:19 +0000 Subject: Fix for bugs: 1788 (forces) and 1799 (python delattr on game objects) Use Polytope collision for faster mesh intersection tests, so SOLID can actually use that qhull lib now. --- intern/moto/include/MT_Quaternion.h | 3 +++ intern/moto/include/MT_Quaternion.inl | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'intern/moto') diff --git a/intern/moto/include/MT_Quaternion.h b/intern/moto/include/MT_Quaternion.h index aa2045fc56f..03b52efe600 100644 --- a/intern/moto/include/MT_Quaternion.h +++ b/intern/moto/include/MT_Quaternion.h @@ -95,6 +95,9 @@ public: void invert(); MT_Quaternion inverse() const; + MT_Scalar angle(const MT_Quaternion& q) const; + MT_Quaternion slerp(const MT_Quaternion& q, const MT_Scalar& t) const; + static MT_Quaternion random(); }; diff --git a/intern/moto/include/MT_Quaternion.inl b/intern/moto/include/MT_Quaternion.inl index 225b95b78ce..8b4fbc93c41 100644 --- a/intern/moto/include/MT_Quaternion.inl +++ b/intern/moto/include/MT_Quaternion.inl @@ -60,3 +60,27 @@ GEN_INLINE MT_Quaternion operator*(const MT_Vector3& w, const MT_Quaternion& q) -w[0] * q[0] - w[1] * q[1] - w[2] * q[2]); } +GEN_INLINE MT_Scalar MT_Quaternion::angle(const MT_Quaternion& q) const +{ + MT_Scalar s = sqrt(length2() * q.length2()); + assert(s != MT_Scalar(0.0)); + return acos(dot(q) / s); +} + +GEN_INLINE MT_Quaternion MT_Quaternion::slerp(const MT_Quaternion& q, const MT_Scalar& t) const +{ + MT_Scalar theta = angle(q); + if (theta != MT_Scalar(0.0)) + { + MT_Scalar d = MT_Scalar(1.0) / sin(theta); + MT_Scalar s0 = sin((MT_Scalar(1.0) - t) * theta); + MT_Scalar s1 = sin(t * theta); + + return d*(*this * s0 + q * s1); + } + else + { + return *this; + } +} + -- cgit v1.2.3