Sign in to follow this  

gluLookAt problems

This topic is 4334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 4334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this