- optimize VSMatrix::Translate.

- use FVector3 for sprite rotations.
This commit is contained in:
Christoph Oelckers 2016-05-01 12:39:08 +02:00
parent 47064e24c9
commit 4fb17561bc
3 changed files with 28 additions and 23 deletions

View file

@ -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)
{

View file

@ -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;

View file

@ -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];