glLoadIdentity() and models.

Started by
3 comments, last by GekkoCube 22 years ago
I''m using DigiBen''s MD2 loader. I loaded a model (a monster) - and would like to display it 10 times in different locations in my world. This is what I did (this is basically pseudocode): for (int i=0; i<100; i++) { glTranslate(loc.x, loc.y, loc.z); g_Model.Draw(); } The problem: The models drawn from indices 1 to 99 all accumulate from the previous render! So I tried inserted a glLoadIdentity() before the translation. This should work, but apparantly it will ruin my viewmatrix - in other words my camera movements are lost. So how can I do a loadidentity for the models (modelmatrix?)being drawn but maintain my viewmatrix??? I hope that makes sense. </i> ~ I am a DirectX to OpenGL convert! ~
Advertisement
Every time you translate it gets multipled by the current matrices so they are combined. I don''t think you viewport will be affected by the glIdentity() expecially if your in glMatrixMode(GL_MODELVIEW). But if it does just translate back after you draw(-x,-y,-z)
There is only one MODELVIEW matrix in OpenGL. In Direct 3D there is a separate view and world matrix. Typically in OpenGL you set the view first, then push the matrix, draw an object, pop the matrix etc.

//Set up view ( gluLookAt, etc.)For Each Object:{  glPushMatrix();  //save the view matrix  //Set object transformation  //Render Object  //glPopMatrix(); //restore the view matrix} 
A simpler solution is to use a camera based on the projection matrix.

My camera currently uses the following basic Apply() routine:


    glMatrixMode(GL_PROJECTION);glLoadIdentity();switch(_viewMode){case ORTHO:    gluOrtho2D(-2.0f, 2.0f, -2.0f, 2.0f);      // 2.0 has no special meaning here    break;... (other modes)default:    break;}gluLookAt(_position.x, _position.y, _position.z,          _direction.x, _direction.y, _direction.z,          _up.x, _up.y, _up.z);    


{edit}This only applies, of course, if you're using a "simple" (ie singular, world-relative) camera {/edit}

HTH,
ld


[edited by - liquiddark on March 23, 2002 2:23:22 PM]
No Excuses
pushing and popping the matrices work!
But I''m suprised that this works.

What does pushmatrix and popmatrix do?

Im guessing the current matrix is pushed to some matrix stack.
And so we''ll be using a fresh new matrix.

But if this is the case, shouldn''t the objects loose the view information since the we''re using a new matrix?




~ I am a DirectX to OpenGL convert! ~

This topic is closed to new replies.

Advertisement