PDA

View Full Version : Translation question - still don't fully understand the glLoadIdentity function



PSzalapski
03-06-2002, 07:36 PM
I am using GLUT, though I don't think it matters much. I have a preloaded series of coordinates, and I want to get an object (in this case, a bird) to simply move to each coordinate in time. Here's the pseudocode for my display function:

void gDisplay(void){
...
glLoadIdentity();
adjust camera using glLookAt();
glPushMatrix();
update values of birdX, birdY, birdZ;
glLoadIdentity();
glTranslatef(birdX, birdY, birdZ);
drawBird();
glPopMatrix();
draw static objects;
glutSwapBuffers();
}

I had thought that using the second glLoadIdentity would enable me to do this, since birdX, birdY, and birdZ are absolute coordinates. (relative not to the previous values of birdX,Y,Z but to the original values of birdX,Y,Z @ (0,0,0).) However, the bird does not draw at all when I do this! I clearly do not understand the full ramifications of calling glLoadIndentity().

If I omit glLoadIndentity, the bird translates by birdX,Y,Z from its previous location, right? I clearly do not want this.

P-Sz

[This message has been edited by PSzalapski (edited 03-06-2002).]

Rob The Bloke
03-06-2002, 07:39 PM
I bet you it does. It's likely to have gone out of the view of your camera.

PSzalapski
03-06-2002, 07:47 PM
Originally posted by Rob The Bloke:
I bet you it does. It's likely to have gone out of the view of your camera.



I've edited my original message with more code.

If I draw the bird without translating, it gets drawn exactly at the origin. If I call glLoadIdentity and then draw the bird without translating, I don't see it on my screen. Why? I don't understand why calling glLoadIdentity should make any difference.

P-Sz

zeckensack
03-06-2002, 08:20 PM
By calling glLoadIdentity you are cancelling out the settings you made with gluLookAt. In this case, you also won't translate relative to the position of the last frame. If the gluLookAt stuff is required to get your model into view in the first place, it's also clear why the glLoadIdentity call after that makes it invisible again.

Furrage
03-07-2002, 05:30 AM
Drop the glLoadIdentity before glTranslated. You dont have to worry about accumulated translations because you called glLoadIdentity before glLookAt.