Permalink
Browse files

flag transforms that are the identity as such and skip any multiplica…

…tion
  • Loading branch information...
1 parent 095319c commit a077c84992a0c9edb445cf46dea6e87982aa93d0 Jonathan Marshall committed Jun 29, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 xbmc/guilib/TransformMatrix.h
@@ -48,6 +48,7 @@ class TransformMatrix
m[1][0] = m[1][2] = m[1][3] = 0.0f; m[1][1] = 1.0f;
m[2][0] = m[2][1] = m[2][3] = 0.0f; m[2][2] = 1.0f;
alpha = 1.0f;
+ identity = true;
};
static TransformMatrix CreateTranslation(float transX, float transY, float transZ = 0)
{
@@ -61,13 +62,15 @@ class TransformMatrix
m[1][0] = m[1][2] = 0.0f; m[1][1] = 1.0f; m[1][3] = transY;
m[2][0] = m[2][1] = 0.0f; m[2][2] = 1.0f; m[2][3] = transZ;
alpha = 1.0f;
+ identity = (transX == 0 && transY == 0 && transZ == 0);
}
static TransformMatrix CreateScaler(float scaleX, float scaleY, float scaleZ = 1.0f)
{
TransformMatrix scaler;
scaler.m[0][0] = scaleX;
scaler.m[1][1] = scaleY;
scaler.m[2][2] = scaleZ;
+ scaler.identity = (scaleX == 1 && scaleY == 1 && scaleZ == 1);
return scaler;
};
void SetScaler(float scaleX, float scaleY, float centerX, float centerY)
@@ -78,6 +81,7 @@ class TransformMatrix
m[1][0] = 0.0f; m[1][1] = scaleY; m[1][2] = 0.0f; m[1][3] = centerY*(1-scaleY);
m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = scaleZ; m[2][3] = centerZ*(1-scaleZ);
alpha = 1.0f;
+ identity = (scaleX == 1 && scaleY == 1);
};
void SetXRotation(float angle, float y, float z, float ar = 1.0f)
{ // angle about the X axis, centered at y,z where our coordinate system has aspect ratio ar.
@@ -87,6 +91,7 @@ class TransformMatrix
m[1][0] = 0.0f; m[1][1] = c/ar; m[1][2] = -s/ar; m[1][3] = (-y*c+s*z)/ar + y;
m[2][0] = 0.0f; m[2][1] = s; m[2][2] = c; m[2][3] = (-y*s-c*z) + z;
alpha = 1.0f;
+ identity = (angle == 0);
}
void SetYRotation(float angle, float x, float z, float ar = 1.0f)
{ // angle about the Y axis, centered at x,z where our coordinate system has aspect ratio ar.
@@ -96,6 +101,7 @@ class TransformMatrix
m[1][0] = 0.0f; m[1][1] = 1.0f; m[1][2] = 0.0f; m[1][3] = 0.0f;
m[2][0] = ar*s; m[2][1] = 0.0f; m[2][2] = c; m[2][3] = -ar*x*s - c*z + z;
alpha = 1.0f;
+ identity = (angle == 0);
}
static TransformMatrix CreateZRotation(float angle, float x, float y, float ar = 1.0f)
{ // angle about the Z axis, centered at x,y where our coordinate system has aspect ratio ar.
@@ -112,6 +118,7 @@ class TransformMatrix
m[1][0] = s*ar; m[1][1] = c; m[1][2] = 0.0f; m[1][3] = -ar*x*s - c*y + y;
m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = 1.0f; m[2][3] = 0.0f;
alpha = 1.0f;
+ identity = (angle == 0);
}
static TransformMatrix CreateFader(float a)
{
@@ -125,11 +132,19 @@ class TransformMatrix
m[1][0] = 0.0f; m[1][1] = 1.0f; m[1][2] = 0.0f; m[1][3] = 0.0f;
m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = 1.0f; m[2][3] = 0.0f;
alpha = a;
+ identity = (a == 1.0f);
}
// multiplication operators
const TransformMatrix &operator *=(const TransformMatrix &right)
{
+ if (right.identity)
+ return *this;
+ if (identity)
+ {
+ *this = right;
+ return *this;
+ }
float t00 = m[0][0] * right.m[0][0] + m[0][1] * right.m[1][0] + m[0][2] * right.m[2][0];
float t01 = m[0][0] * right.m[0][1] + m[0][1] * right.m[1][1] + m[0][2] * right.m[2][1];
float t02 = m[0][0] * right.m[0][2] + m[0][1] * right.m[1][2] + m[0][2] * right.m[2][2];
@@ -146,11 +161,16 @@ class TransformMatrix
m[2][3] = m[2][0] * right.m[0][3] + m[2][1] * right.m[1][3] + m[2][2] * right.m[2][3] + m[2][3];
m[2][0] = t00; m[2][1] = t01; m[2][2] = t02;
alpha *= right.alpha;
+ identity = false;
return *this;
}
TransformMatrix operator *(const TransformMatrix &right) const
{
+ if (right.identity)
+ return *this;
+ if (identity)
+ return right;
TransformMatrix result;
result.m[0][0] = m[0][0] * right.m[0][0] + m[0][1] * right.m[1][0] + m[0][2] * right.m[2][0];
result.m[0][1] = m[0][0] * right.m[0][1] + m[0][1] * right.m[1][1] + m[0][2] * right.m[2][1];
@@ -165,6 +185,7 @@ class TransformMatrix
result.m[2][2] = m[2][0] * right.m[0][2] + m[2][1] * right.m[1][2] + m[2][2] * right.m[2][2];
result.m[2][3] = m[2][0] * right.m[0][3] + m[2][1] * right.m[1][3] + m[2][2] * right.m[2][3] + m[2][3];
result.alpha = alpha * right.alpha;
+ result.identity = false;
return result;
}
@@ -223,4 +244,5 @@ class TransformMatrix
float m[3][4];
float alpha;
+ bool identity;
};

0 comments on commit a077c84

Please sign in to comment.