Jelajahi Sumber

Simplify Transform::getMatrix() with retained or improved actual performance.

Jon Watte 10 tahun lalu
induk
melakukan
f911325535
1 mengubah file dengan 7 tambahan dan 23 penghapusan
  1. 7 23
      gameplay/src/Transform.cpp

+ 7 - 23
gameplay/src/Transform.cpp

@@ -99,43 +99,27 @@ const char* Transform::getTypeName() const
 
 const Matrix& Transform::getMatrix() const
 {
-    if (_matrixDirtyBits)
+    if (_matrixDirtyBits & (DIRTY_TRANSLATION | DIRTY_ROTATION | DIRTY_SCALE))
     {
         if (!isStatic())
         {
-            bool hasTranslation = !_translation.isZero();
             bool hasScale = !_scale.isOne();
             bool hasRotation = !_rotation.isIdentity();
 
             // Compose the matrix in TRS order since we use column-major matrices with column vectors and
             // multiply M*v (as opposed to XNA and DirectX that use row-major matrices with row vectors and multiply v*M).
-            if (hasTranslation || (_matrixDirtyBits & DIRTY_TRANSLATION) == DIRTY_TRANSLATION)
+            Matrix::createTranslation(_translation, &_matrix);
+            if (hasRotation)
             {
-                Matrix::createTranslation(_translation, &_matrix);
-                if (hasRotation || (_matrixDirtyBits & DIRTY_ROTATION) == DIRTY_ROTATION)
-                {
-                    _matrix.rotate(_rotation);
-                }
-                if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-                {
-                    _matrix.scale(_scale);
-                }
+                _matrix.rotate(_rotation);
             }
-            else if (hasRotation || (_matrixDirtyBits & DIRTY_ROTATION) == DIRTY_ROTATION)
+            if (hasScale)
             {
-                Matrix::createRotation(_rotation, &_matrix);
-                if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-                {
-                    _matrix.scale(_scale);
-                }
-            }
-            else if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-            {
-                Matrix::createScale(_scale, &_matrix);
+                _matrix.scale(_scale);
             }
         }
 
-        _matrixDirtyBits &= ~DIRTY_TRANSLATION & ~DIRTY_ROTATION & ~DIRTY_SCALE;
+        _matrixDirtyBits &= ~(DIRTY_TRANSLATION | DIRTY_ROTATION | DIRTY_SCALE);
     }
 
     return _matrix;