From f6dd11ca1aca77a8422c410cfb3d0a84f8dbf2a1 Mon Sep 17 00:00:00 2001 From: cywang Date: Thu, 17 Dec 2020 15:07:03 +0800 Subject: [PATCH 1/3] add operator* in aiQuaterniont --- include/assimp/quaternion.h | 3 +++ include/assimp/quaternion.inl | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index 9a14bd413..b3802e572 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -88,6 +88,9 @@ public: bool operator== (const aiQuaterniont& o) const; bool operator!= (const aiQuaterniont& o) const; + // transform vector by matrix + aiQuaterniont& operator *= (const aiMatrix4x4t& mat); + bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const; public: diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index 32549db3b..998996d93 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -57,6 +57,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +// ------------------------------------------------------------------------------------------------ +/** Transformation of a quaternion by a 4x4 matrix */ +template +AI_FORCE_INLINE +aiQuaterniont operator * (const aiMatrix4x4t& pMatrix, const aiQuaterniont& pQuaternion) { + aiQuaterniont res; + res.x = pMatrix.a1 * pQuaternion.x + pMatrix.a2 * pQuaternion.y + pMatrix.a3 * pQuaternion.z + pMatrix.a4 * pQuaternion.w; + res.y = pMatrix.b1 * pQuaternion.x + pMatrix.b2 * pQuaternion.y + pMatrix.b3 * pQuaternion.z + pMatrix.b4 * pQuaternion.w; + res.z = pMatrix.c1 * pQuaternion.x + pMatrix.c2 * pQuaternion.y + pMatrix.c3 * pQuaternion.z + pMatrix.c4 * pQuaternion.w; + res.w = pMatrix.d1 * pQuaternion.x + pMatrix.d2 * pQuaternion.y + pMatrix.d3 * pQuaternion.z + pMatrix.d4 * pQuaternion.w; + return res; +} // --------------------------------------------------------------------------- template bool aiQuaterniont::operator== (const aiQuaterniont& o) const @@ -71,6 +83,14 @@ bool aiQuaterniont::operator!= (const aiQuaterniont& o) const return !(*this == o); } +// ------------------------------------------------------------------------------------------------ +template +AI_FORCE_INLINE +aiQuaterniont& aiQuaterniont::operator *= (const aiMatrix4x4t& mat){ + return (*this = mat * (*this)); +} +// ------------------------------------------------------------------------------------------------ + // --------------------------------------------------------------------------- template inline bool aiQuaterniont::Equal(const aiQuaterniont& o, TReal epsilon) const { From b6f8448b7883d2d571158d5fd14decc895a8f857 Mon Sep 17 00:00:00 2001 From: cywang Date: Thu, 17 Dec 2020 16:13:35 +0800 Subject: [PATCH 2/3] add operator* in aiQuaterniont --- include/assimp/quaternion.h | 1 + include/assimp/quaternion.inl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index b3802e572..ee733ba2d 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. template class aiVector3t; template class aiMatrix3x3t; +template class aiMatrix4x4t; // --------------------------------------------------------------------------- /** Represents a quaternion in a 4D vector. */ diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index 998996d93..ae67f2126 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -61,7 +61,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Transformation of a quaternion by a 4x4 matrix */ template AI_FORCE_INLINE -aiQuaterniont operator * (const aiMatrix4x4t& pMatrix, const aiQuaterniont& pQuaternion) { +aiQuaterniont operator * (const aiMatrix4x4t& pMatrix, const aiQuaterniont& pQuaternion) { aiQuaterniont res; res.x = pMatrix.a1 * pQuaternion.x + pMatrix.a2 * pQuaternion.y + pMatrix.a3 * pQuaternion.z + pMatrix.a4 * pQuaternion.w; res.y = pMatrix.b1 * pQuaternion.x + pMatrix.b2 * pQuaternion.y + pMatrix.b3 * pQuaternion.z + pMatrix.b4 * pQuaternion.w; From 15cff9492643e8bc6d7f26116616d0554f6e3afa Mon Sep 17 00:00:00 2001 From: cywang Date: Thu, 17 Dec 2020 17:08:06 +0800 Subject: [PATCH 3/3] add operator* in aiQuaterniont --- include/assimp/quaternion.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index ae67f2126..95e5d8cf7 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -62,7 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. template AI_FORCE_INLINE aiQuaterniont operator * (const aiMatrix4x4t& pMatrix, const aiQuaterniont& pQuaternion) { - aiQuaterniont res; + aiQuaterniont res; res.x = pMatrix.a1 * pQuaternion.x + pMatrix.a2 * pQuaternion.y + pMatrix.a3 * pQuaternion.z + pMatrix.a4 * pQuaternion.w; res.y = pMatrix.b1 * pQuaternion.x + pMatrix.b2 * pQuaternion.y + pMatrix.b3 * pQuaternion.z + pMatrix.b4 * pQuaternion.w; res.z = pMatrix.c1 * pQuaternion.x + pMatrix.c2 * pQuaternion.y + pMatrix.c3 * pQuaternion.z + pMatrix.c4 * pQuaternion.w;