gluLookAt problems
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();
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.
that will make it look 20 units in front of it, so try that. your if statement for input should be something like:
that should do the trick :]
--nathan
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.
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... ?
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... ?
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement