get rid of the matrix stack; use opengl's

This commit is contained in:
Glenn Maynard
2003-01-08 22:30:32 +00:00
parent 19ced1fdc3
commit 7e45cabbb1
3 changed files with 29 additions and 51 deletions
+28 -49
View File
@@ -30,8 +30,6 @@ RageDisplay* DISPLAY = NULL;
//////////// ////////////
const int MAX_NUM_VERTICIES = 1000; const int MAX_NUM_VERTICIES = 1000;
SDL_Surface *g_screen = NULL; // this class is a singleton, so there can be only one SDL_Surface *g_screen = NULL; // this class is a singleton, so there can be only one
vector<RageMatrix> g_matModelStack; // model matrix stack
RageMatrix& GetTopModelMatrix() { return g_matModelStack.back(); }
int g_flags = 0; /* SDL video flags */ int g_flags = 0; /* SDL video flags */
GLenum g_vertMode = GL_TRIANGLES; GLenum g_vertMode = GL_TRIANGLES;
RageVertex g_vertQueue[MAX_NUM_VERTICIES]; RageVertex g_vertQueue[MAX_NUM_VERTICIES];
@@ -42,7 +40,7 @@ int g_iFPS, g_iVPF, g_iDPF;
int g_PerspectiveMode = 0; int g_PerspectiveMode = 0;
int g_CurrentHeight, g_CurrentWidth, g_CurrentBPP; int g_CurrentHeight, g_CurrentWidth, g_CurrentBPP;
int g_ModelMatrixCnt=0;
int RageDisplay::GetFPS() const { return g_iFPS; } int RageDisplay::GetFPS() const { return g_iFPS; }
int RageDisplay::GetVPF() const { return g_iVPF; } int RageDisplay::GetVPF() const { return g_iVPF; }
int RageDisplay::GetDPF() const { return g_iDPF; } int RageDisplay::GetDPF() const { return g_iDPF; }
@@ -67,7 +65,6 @@ void GetGLExtensions(set<string> &ext)
RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, int rate, bool vsync ) RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, int rate, bool vsync )
{ {
// LOG->Trace( "RageDisplay::RageDisplay()" ); // LOG->Trace( "RageDisplay::RageDisplay()" );
m_oglspecs = new oglspecs_t; m_oglspecs = new oglspecs_t;
SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO);
@@ -404,7 +401,9 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth
* if both scale factors in the matrix are ~0. (Actually, I think * if both scale factors in the matrix are ~0. (Actually, I think
* it's true if two of the three scale factors are ~0, but we don't * it's true if two of the three scale factors are ~0, but we don't
* use this for anything 3d at the moment anyway ...) */ * use this for anything 3d at the moment anyway ...) */
RageMatrix &mat = GetTopModelMatrix(); RageMatrix mat;
glGetFloatv( GL_MODELVIEW_MATRIX, (float*)mat );
if(mat.m[0][0] < 1e-5 && mat.m[1][1] < 1e-5) if(mat.m[0][0] < 1e-5 && mat.m[1][1] < 1e-5)
return; return;
@@ -425,8 +424,7 @@ void RageDisplay::AddVerts( const RageVertex v[], int iNumVerts )
if( g_iNumVerts+1 > MAX_NUM_VERTICIES ) if( g_iNumVerts+1 > MAX_NUM_VERTICIES )
FlushQueue(); FlushQueue();
// transform the verticies as we copy g_vertQueue[g_iNumVerts].p = v[i].p;
RageVec3TransformCoord( &g_vertQueue[g_iNumVerts].p, &v[i].p, &GetTopModelMatrix() );
g_vertQueue[g_iNumVerts].c = v[i].c; g_vertQueue[g_iNumVerts].c = v[i].c;
g_vertQueue[g_iNumVerts].t = v[i].t; g_vertQueue[g_iNumVerts].t = v[i].t;
g_iNumVerts++; g_iNumVerts++;
@@ -447,24 +445,16 @@ void RageDisplay::FlushQueue()
g_iDrawsSinceLastCheck++; g_iDrawsSinceLastCheck++;
} }
void RageDisplay::ResetMatrixStack()
{
RageMatrix ident;
RageMatrixIdentity( &ident );
g_matModelStack.clear();
g_matModelStack.push_back(ident);
}
void RageDisplay::PushMatrix() void RageDisplay::PushMatrix()
{ {
g_matModelStack.push_back( GetTopModelMatrix() ); glPushMatrix();
ASSERT(g_matModelStack.size()<20); // check for infinite loop ASSERT(++g_ModelMatrixCnt<20);
} }
void RageDisplay::PopMatrix() void RageDisplay::PopMatrix()
{ {
g_matModelStack.erase( g_matModelStack.end()-1, g_matModelStack.end() ); glPopMatrix();
ASSERT(g_matModelStack.size()>=1); // popped a matrix we didn't push ASSERT(g_ModelMatrixCnt-->0);
} }
/* Switch from orthogonal to perspective view. /* Switch from orthogonal to perspective view.
@@ -508,7 +498,9 @@ void RageDisplay::EnterPerspective(float fov, bool preserve_loc)
glScalef(1, -1, 1); glScalef(1, -1, 1);
if(preserve_loc) { if(preserve_loc) {
RageMatrix &matTop = GetTopModelMatrix(); RageMatrix matTop;
glGetFloatv( GL_MODELVIEW_MATRIX, (float*)matTop );
{ {
/* Pull out the 2d translation. */ /* Pull out the 2d translation. */
float x = matTop.m[3][0], y = matTop.m[3][1]; float x = matTop.m[3][0], y = matTop.m[3][1];
@@ -539,7 +531,7 @@ void RageDisplay::EnterPerspective(float fov, bool preserve_loc)
matTop.m[2][2] == 1.f && matTop.m[3][2] == 0.f && matTop.m[3][3] == 1.f); matTop.m[2][2] == 1.f && matTop.m[3][2] == 0.f && matTop.m[3][3] == 1.f);
/* Reset the matrix back to identity. */ /* Reset the matrix back to identity. */
RageMatrixIdentity( &matTop ); glLoadIdentity();
} }
glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW );
@@ -573,62 +565,49 @@ void RageDisplay::LookAt(const RageVector3 &Eye, const RageVector3 &At, const Ra
glGetFloatv( GL_MODELVIEW_MATRIX, (float*)view ); /* cheesy :) */ glGetFloatv( GL_MODELVIEW_MATRIX, (float*)view ); /* cheesy :) */
glPopMatrix(); glPopMatrix();
RageMatrix& matTop = GetTopModelMatrix(); smPostMultMatrixf(view);
RageMatrixMultiply( &matTop, &view, &matTop );
} }
void RageDisplay::Translate( float x, float y, float z ) void RageDisplay::Translate( float x, float y, float z )
{ {
RageMatrix matTemp; glTranslatef(x, y, z);
RageMatrixTranslation( &matTemp, x, y, z );
RageMatrix& matTop = GetTopModelMatrix();
RageMatrixMultiply( &matTop, &matTemp, &matTop );
} }
void RageDisplay::TranslateLocal( float x, float y, float z ) void RageDisplay::TranslateLocal( float x, float y, float z )
{ {
RageMatrix matTemp; RageMatrix matTemp;
RageMatrixTranslation( &matTemp, x, y, z ); RageMatrixTranslation( &matTemp, x, y, z );
RageMatrix& matTop = GetTopModelMatrix(); smPostMultMatrixf(matTemp);
RageMatrixMultiply( &matTop, &matTop, &matTemp );
} }
void RageDisplay::Scale( float x, float y, float z ) void RageDisplay::Scale( float x, float y, float z )
{ {
RageMatrix matTemp; glScalef(x, y, z);
RageMatrixScaling( &matTemp, x, y, z );
RageMatrix& matTop = GetTopModelMatrix();
RageMatrixMultiply( &matTop, &matTemp, &matTop );
} }
void RageDisplay::RotateX( float r ) void RageDisplay::RotateX( float r )
{ {
RageMatrix matTemp; glRotatef(r* 180/PI, 1, 0, 0);
RageMatrixRotationX( &matTemp, r );
RageMatrix& matTop = GetTopModelMatrix();
RageMatrixMultiply( &matTop, &matTemp, &matTop );
} }
void RageDisplay::RotateY( float r ) void RageDisplay::RotateY( float r )
{ {
RageMatrix matTemp; glRotatef(r* 180/PI, 0, 1, 0);
RageMatrixRotationY( &matTemp, r );
RageMatrix& matTop = GetTopModelMatrix();
RageMatrixMultiply( &matTop, &matTemp, &matTop );
} }
void RageDisplay::RotateZ( float r ) void RageDisplay::RotateZ( float r )
{ {
RageMatrix matTemp; glRotatef(r* 180/PI, 0, 0, 1);
RageMatrixRotationZ( &matTemp, r ); }
RageMatrix& matTop = GetTopModelMatrix(); void RageDisplay::smPostMultMatrixf( const RageMatrix &f )
RageMatrixMultiply( &matTop, &matTemp, &matTop ); {
RageMatrix m;
glGetFloatv( GL_MODELVIEW_MATRIX, (float*)m );
RageMatrixMultiply( &m, &f, &m );
glLoadMatrixf((const float*) m);
} }
void RageDisplay::SetTexture( RageTexture* pTexture ) void RageDisplay::SetTexture( RageTexture* pTexture )
+1 -1
View File
@@ -41,7 +41,6 @@ public:
int GetHeight() const; int GetHeight() const;
int GetBPP() const; int GetBPP() const;
void ResetMatrixStack();
void PushMatrix(); void PushMatrix();
void PopMatrix(); void PopMatrix();
void Translate( float x, float y, float z ); void Translate( float x, float y, float z );
@@ -50,6 +49,7 @@ public:
void RotateX( float r ); void RotateX( float r );
void RotateY( float r ); void RotateY( float r );
void RotateZ( float r ); void RotateZ( float r );
void smPostMultMatrixf( const RageMatrix &f );
void SetTexture( RageTexture* pTexture ); void SetTexture( RageTexture* pTexture );
-1
View File
@@ -436,7 +436,6 @@ static void GameLoop()
* Render * Render
*/ */
DISPLAY->Clear(); DISPLAY->Clear();
DISPLAY->ResetMatrixStack();
SCREENMAN->Draw(); // draw the game SCREENMAN->Draw(); // draw the game