# gluLookAt + transformation don't work !

## Recommended Posts

So at the start of the frame I set the camera position with gluLookAt. I then draw my object like this: gluLookAt(); ...etc glPushMatrix(); //model matrix is at the camera which is not what we want DoTransformation(position); //to the object's position DrawObject(); glPopMatrix(); IT WORKS! The object is in the correct position -but it shouldn't be as I haven't done LoadIdentity(). So if I do it properly: gluLookAt(); ...etc glPushMatrix(); glLoadIdentity(); //THIS SHOULD BE REALLY CORRECT DoTransformation(position);//to the correct position DrawObject(); glPopMatrix(); Then none of the objects drawn like this can be seen - although this is the correct way. So what is wrong with the second way of doing things ?

##### Share on other sites
Using OpenGL you have two matrix stack: GL_PROJECTION and GL_MODELVIEW. The idea is to load the projection into the first matrix and the model AND view matrix into the second one. Since the gluLookAt matrix modifies the current matrix, and it represents the view, the correct order would be similar to your first code:

glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(....);glPushMatrix();  DoTransform(...);  RenderObject();glPopMatrix();

##### Share on other sites
You're doing it correctly the first time. When you push a matrix in OpenGL, the current top matrix takes the value of the one beneith. You'd then want to multiply that matrix with the transformation matrix of the object. In the second case, you're clearing the camera transform from the top matrix, then multiplying my your objects transformation matrix, which is like the camera transform never happened.

I don't see what the projection matrix has to do with any of this.

So, for clarity:

glMatrixMode( GL_MODELVIEW );glLoadIdentity(); // may do this internally in gluLookAt, I can't remembergluLookat(); // (1)glPushMatrix();    // the value of the model view matrix is the same here as at (1)    DoTransform();    // (1) * whatever DoTransform does    RenderObject();glPopMatrix();// again, the matrix takes the value of (1)

##### Share on other sites
thanks I understand (sort of !),

cheers

##### Share on other sites
Well, nothing much, just thought it might help to know that there is one, that's all.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627651
• Total Posts
2978407

• 10
• 12
• 22
• 13
• 33