From 4fb17561bc2fecc21d2f01f851b659ca75cd05c2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 1 May 2016 12:39:08 +0200 Subject: [PATCH] - optimize VSMatrix::Translate. - use FVector3 for sprite rotations. --- src/gl/data/gl_matrix.cpp | 17 ++++++----------- src/gl/scene/gl_sprite.cpp | 24 ++++++++++++------------ src/gl/utility/gl_geometric.h | 10 ++++++++++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/gl/data/gl_matrix.cpp b/src/gl/data/gl_matrix.cpp index a16dc770f..bc0f4129f 100644 --- a/src/gl/data/gl_matrix.cpp +++ b/src/gl/data/gl_matrix.cpp @@ -121,22 +121,17 @@ VSMatrix::loadMatrix(const float *aMatrix) #endif -// gl Translate implementation with matrix selection +// gl Translate implementation void VSMatrix::translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { - FLOATTYPE mat[16]; - - setIdentityMatrix(mat); - mat[12] = x; - mat[13] = y; - mat[14] = z; - - multMatrix(mat); + mMatrix[12] = mMatrix[0] * x + mMatrix[4] * y + mMatrix[8] * z + mMatrix[12]; + mMatrix[13] = mMatrix[1] * x + mMatrix[5] * y + mMatrix[9] * z + mMatrix[13]; + mMatrix[14] = mMatrix[2] * x + mMatrix[6] * y + mMatrix[10] * z + mMatrix[14]; } -// gl Scale implementation with matrix selection +// gl Scale implementation void VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { @@ -146,7 +141,7 @@ VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) } -// gl Rotate implementation with matrix selection +// gl Rotate implementation void VSMatrix::rotate(FLOATTYPE angle, FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 70669fb33..3f90b251e 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -267,10 +267,10 @@ void GLSprite::Draw(int pass) gl_RenderState.Apply(); - Vector v1; - Vector v2; - Vector v3; - Vector v4; + FVector3 v1; + FVector3 v2; + FVector3 v3; + FVector3 v4; if (drawWithXYBillboard || drawBillboardFacingCamera) { @@ -306,17 +306,17 @@ void GLSprite::Draw(int pass) mat.Rotate(-sin(angleRad), 0, cos(angleRad), -GLRenderer->mAngles.Pitch.Degrees); } mat.Translate(-xcenter, -zcenter, -ycenter); // retreat from sprite center - v1 = mat * Vector(x1, z1, y1); - v2 = mat * Vector(x2, z1, y2); - v3 = mat * Vector(x1, z2, y1); - v4 = mat * Vector(x2, z2, y2); + v1 = mat * FVector3(x1, z1, y1); + v2 = mat * FVector3(x2, z1, y2); + v3 = mat * FVector3(x1, z2, y1); + v4 = mat * FVector3(x2, z2, y2); } else // traditional "Y" billboard mode { - v1 = Vector(x1, z1, y1); - v2 = Vector(x2, z1, y2); - v3 = Vector(x1, z2, y1); - v4 = Vector(x2, z2, y2); + v1 = FVector3(x1, z1, y1); + v2 = FVector3(x2, z1, y2); + v3 = FVector3(x1, z2, y1); + v4 = FVector3(x2, z2, y2); } FFlatVertex *ptr; diff --git a/src/gl/utility/gl_geometric.h b/src/gl/utility/gl_geometric.h index 3691d7740..f1053c430 100644 --- a/src/gl/utility/gl_geometric.h +++ b/src/gl/utility/gl_geometric.h @@ -239,6 +239,16 @@ public: return result; } + FVector3 operator *(const FVector3 &vec) + { + FVector3 result; + + result.X = vec.X*m[0][0] + vec.Y*m[0][1] + vec.Z*m[0][2] + m[0][3]; + result.Y = vec.X*m[1][0] + vec.Y*m[1][1] + vec.Z*m[1][2] + m[1][3]; + result.Z = vec.X*m[2][0] + vec.Y*m[2][1] + vec.Z*m[2][2] + m[2][3]; + return result; + } + void MultiplyVector(float *f3 , float *f3o) { float x = f3[0] * m[0][0] + f3[1] * m[0][1] + f3[2] * m[0][2] + m[0][3];