Преглед изворни кода

add operator* in aiQuaterniont

cywang пре 4 година
родитељ
комит
f6dd11ca1a
2 измењених фајлова са 23 додато и 0 уклоњено
  1. 3 0
      include/assimp/quaternion.h
  2. 20 0
      include/assimp/quaternion.inl

+ 3 - 0
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<TReal>& mat);
+
     bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const;
 
 public:

+ 20 - 0
include/assimp/quaternion.inl

@@ -57,6 +57,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <cmath>
 
+// ------------------------------------------------------------------------------------------------
+/** Transformation of a quaternion by a 4x4 matrix */
+template <typename TReal>
+AI_FORCE_INLINE
+aiQuaterniont<TReal> operator * (const aiMatrix4x4t<TReal>& 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<typename TReal>
 bool aiQuaterniont<TReal>::operator== (const aiQuaterniont& o) const
@@ -71,6 +83,14 @@ bool aiQuaterniont<TReal>::operator!= (const aiQuaterniont& o) const
     return !(*this == o);
 }
 
+// ------------------------------------------------------------------------------------------------
+template <typename TReal>
+AI_FORCE_INLINE
+aiQuaterniont<TReal>& aiQuaterniont<TReal>::operator *= (const aiMatrix4x4t<TReal>& mat){
+    return (*this = mat * (*this));
+}
+// ------------------------------------------------------------------------------------------------
+
 // ---------------------------------------------------------------------------
 template<typename TReal>
 inline bool aiQuaterniont<TReal>::Equal(const aiQuaterniont& o, TReal epsilon) const {