gluLookAt problems

Started by
4 comments, last by Axesor 18 years, 2 months ago
I start my program at (0,0,3). When I move the camera to (0,0,-z), everything that should be drawn behind me is now drawn in front of me and my z and x axis flip (z-positive is now z-negative). Anyone know why this would happen? Walk is set to 3 at start and when 'UP' is hit, walk--; glEnable(GL_DEPTH_TEST); glClearColor (.4f, 0.0f, .5f, 0.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0f,1,.1f,50.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,1,walk, 0,1,0, 0,1,0); //draw axes glBegin(GL_LINES); //x glColor3f(.4,.4,1); glVertex3f(0,0,0); glVertex3f(2,0,0); //y glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(0,2,0); //z glColor3f(.1,.4,.3); glVertex3f(0,0,0); glVertex3f(0,0,-2); glEnd();

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Advertisement
its because your not specifying the look at coordinates, your only specifying the camera coordinates. so what is happening is that your looking at 0,0,0 even when your all the way at 0,0,-100. try doing this.

float cameraZ = 20;float lookAtZ = 0;gluLookAt(0,0,cameraZ,0,0,lookAtZ,0,1,0);


that will make it look 20 units in front of it, so try that. your if statement for input should be something like:
if(keyPressed[VK_UP]){    cameraZ--;    lookAtZ--;}

that should do the trick :]

--nathan
Thanks a lot. I kept having the same problem when strafing left and right. Forgot that I was always looking at 0,0,0.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Can somebody explain me what are the last 3 parameters in gluLookAt(0,0,cameraZ,0,0,lookAtZ,0,1,0) ?
I know that the first 3 are camera position, the other 3 the location of the object you are trying to look at and the last... ?
There is only one thing that makes a dream impossible to achieve: the fear of failure.
The direction that is up relative to the viewer.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

The function gluLookAt is defined as:

gluLookAt(GLDouble eyex, GLDouble eyey, GLDouble eyez, GLDouble centerx,
GLDouble centery, GLDouble centerz, GLDouble upx, GLDouble upy, GLDouble upz);

(eyex, eyey, eyez) specifies the location of the camera
(centerx, centery, centerz) specifies where the camera is pointing
(upx, upy, upz) is a vector that tells which direction is up.

Got it?
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward

This topic is closed to new replies.

Advertisement