Pārlūkot izejas kodu

Removed unused Matrix operations.
Optimized defining a Matrix4x3 transform.

Lasse Öörni 14 gadi atpakaļ
vecāks
revīzija
f0fecccacb
3 mainītis faili ar 19 papildinājumiem un 29 dzēšanām
  1. 0 17
      Engine/Math/Matrix3.cpp
  2. 17 4
      Engine/Math/Matrix3.h
  3. 2 8
      Engine/Math/Matrix4x3.cpp

+ 0 - 17
Engine/Math/Matrix3.cpp

@@ -34,23 +34,6 @@ const Matrix3 Matrix3::sIdentity(
     0.0f, 1.0f, 0.0f,
     0.0f, 0.0f, 1.0f);
 
-void Matrix3::setRotation(float angle, const Vector3& axis)
-{
-    Vector3 normAxis = axis.getNormalized();
-    float sinAngle = sinf(angle * M_DEGTORAD);
-    float cosAngle = cosf(angle * M_DEGTORAD);
-    
-    m00 = normAxis.mX * normAxis.mX + cosAngle * (1.0f - normAxis.mX * normAxis.mX);
-    m01 = normAxis.mX * normAxis.mY * (1.0f - cosAngle) - sinAngle * normAxis.mZ;
-    m02 = normAxis.mX * normAxis.mZ * (1.0f - cosAngle) + sinAngle * normAxis.mY;
-    m10 = normAxis.mX * normAxis.mY * (1.0f - cosAngle) + sinAngle * normAxis.mZ;
-    m11 = normAxis.mY * normAxis.mY + cosAngle * (1.0f - normAxis.mY * normAxis.mY);
-    m12 = normAxis.mY * normAxis.mZ * (1.0f - cosAngle) - sinAngle * normAxis.mX;
-    m20 = normAxis.mX * normAxis.mZ * (1.0f - cosAngle) - sinAngle * normAxis.mY;
-    m21 = normAxis.mY * normAxis.mZ * (1.0f - cosAngle) + sinAngle * normAxis.mX;
-    m22 = normAxis.mZ * normAxis.mZ + cosAngle * (1.0f - normAxis.mZ * normAxis.mZ);
-}
-
 Matrix3 Matrix3::getInverse() const
 {
     float det = m00 * m11 * m22 +

+ 17 - 4
Engine/Math/Matrix3.h

@@ -95,7 +95,7 @@ public:
         return *this;
     }
     
-    //! Multiply a Vector4
+    //! Multiply a Vector3
     Vector3 operator * (const Vector3& rhs) const
     {
         return Vector3(
@@ -185,9 +185,6 @@ public:
         m22 = scale;
     }
     
-    //! Set rotation from an angle (in degrees) and axis
-    void setRotation(float angle, const Vector3& axis);
-    
     //! Return transpose
     Matrix3 getTranspose() const
     {
@@ -204,6 +201,22 @@ public:
         );
     }
     
+    //! Return scaled by a vector
+    Matrix3 getScaled(const Vector3& scale) const
+    {
+        return Matrix3(
+            m00 * scale.mX,
+            m01 * scale.mY,
+            m02 * scale.mZ,
+            m10 * scale.mX,
+            m11 * scale.mY,
+            m12 * scale.mZ,
+            m20 * scale.mX,
+            m21 * scale.mY,
+            m22 * scale.mZ
+        );
+    }
+    
     //! Return inverse
     Matrix3 getInverse() const;
     

+ 2 - 8
Engine/Math/Matrix4x3.cpp

@@ -46,19 +46,13 @@ Matrix4x3::Matrix4x3(const Vector3& translation, const Quaternion& rotation, con
 
 void Matrix4x3::define(const Vector3& translation, const Quaternion& rotation, float scale)
 {
-    Matrix3 scaleMatrix(Matrix3::sIdentity);
-    scaleMatrix.setScale(scale);
-    
-    *this = rotation.getRotationMatrix() * scaleMatrix;
+    setRotation(rotation.getRotationMatrix() * scale);
     setTranslation(translation);
 }
 
 void Matrix4x3::define(const Vector3& translation, const Quaternion& rotation, const Vector3& scale)
 {
-    Matrix3 scaleMatrix(Matrix3::sIdentity);
-    scaleMatrix.setScale(scale);
-    
-    *this = rotation.getRotationMatrix() * scaleMatrix;
+    setRotation(rotation.getRotationMatrix().getScaled(scale));
     setTranslation(translation);
 }