Archived

This topic is now archived and is closed to further replies.

GekkoCube

glLoadIdentity() and models.

Recommended Posts

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[i].y, loc[i].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 am a DirectX to OpenGL convert! ~

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
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
}

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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! ~

Share this post


Link to post
Share on other sites