Jump to content
  • Advertisement
Sign in to follow this  
dpadam450

gluLookAt problems

This topic is 4670 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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!