PDA

View Full Version : gluLookAt problems



keelx
04-02-2011, 07:38 PM
Hello, I am having problems using the gluLookAt function. It has worked perfectly before, but now that I have begun a project in C rather than C++, it has started to act weird. I have a scene, it is a basic three-walled cube, the fourth wall is left open for me to see inside. Somewhat like a stage. I am trying to zoom out on it, so instead of viewing from inside the cube, I am viewing from the point of the 'audience'. Before I just used this:
glTranslatef(0.0f, 0.0f, -7.5f);
Which works just as I expected. But now I want a movable camera, so I switched it to this (the movement has not been added yet):
gluLookAt(0, 0, -7.5, 0, 0, 0, 0, 1, 0);
And it gives me some strange view from either the top or bottom (I can't tell) and everything flickers. Shouldn't these two functions do the same thing, at least in this situation and implementation? If not, how can I change it? What am I doing wrong? Also, I have called glLoadIdentity once before the other functions, and I have a glPushMatrix() before and a glPopMatrix after each of the objects in the scene.

BionicBytes
04-03-2011, 04:50 AM
The glulookat should be preceeded with glloadidentity. This sets up the modelview matrix for the scene aka the camera.
This is not the same as gltranslatef which is a modification to the current value of the modelview matrix. When the camera is setup using glulookat ... -7.5 you have positioned your camera into the scene at Z=-7.5 but you wanted to view the stage from the audiences point of view. Therefore you should have used +7.5 instead. Your object should still be drawn using the gltranslatef (0,0,-7.5) to position it into the scene along the negative z axis. OpenGL has a convention that -ve Z is into the scene and +ve Z is towards the viewer.

keelx
04-03-2011, 01:50 PM
It is preceded by glLookAt(). I switched the sign, but now it looks completely wrong, and still flickers.
Here are some screenshots:
With just glTranselatef(0, 0, -7.5);
http://www.kgamesh.uphero.com/Working.png
And with gluLookAt(0, 0, 7.5, 0, 0, 0, 0, 1, 0);
http://www.kgamesh.uphero.com/NotWorking.png
And with gluLookAt(0, 0, -7.5, 0, 0, 0, 0, 1, 0);
http://www.kgamesh.uphero.com/OtherNotWorking.png

Dark Photon
04-03-2011, 04:17 PM
Before I just used this:
glTranslatef(0.0f, 0.0f, -7.5f);
Which works just as I expected. But now...
gluLookAt(0, 0, -7.5, 0, 0, 0, 0, 1, 0);
And it gives me some strange view from either the top or bottom (I can't tell) and everything flickers. Shouldn't these two functions do the same thing
OpenGL eye-space has you at the origin, looking down the -Z axis, with +Y up.

The first leaves you looking down the -Z axis with +Y up.

The second has you looking down the +Z axis with +Y up.

The first takes (0,0,7.5) to the origin (so that's the eyepoint).

The second takes (0.0.-7.5) to the origin (so that's the eyepoint).

...assuming we regard both of these as VIEWING transforms. ...and assuming I'm not missing something obvious.

keelx
04-03-2011, 06:07 PM
Okay, I switched it. same problem. Nothing really changed. I have posted some screenshots in another post in this same topic.