View Full Version : gluLookAt with different perspectives
12-22-2007, 12:37 PM
Say i have and orthographic projection. And I'm using gluLookAt something like this:
gluLookAt(20, 20, 20, 0, 0, 0, 0, 1, 0);
Can someone explain to me why i get the drawing upside down:
(the dotted lines are the negative axis)
Incorrect Drawing (http://img146.imageshack.us/img146/5247/oglupsidedownnr0.png)
And when i change to this
gluLookAt(20, 20, 20, 0, 0, 0, 0, -1, 0);
i get a correct drawing
Correct Drawing (http://img297.imageshack.us/my.php?image=oglnormalgd0.png)
the same thing happens when I'm using glFrustum
but not with gluPerspective
12-22-2007, 05:58 PM
I'm not 100% sure of exactly why it does that, I tested it too and it did the same thing. I think it may have to do with the distance the lookAt point is from the camera.
if you want, here is some code that will calculate the lookAt point given an X and Y angle in degrees.
Alternatively you can delete all the piover180 references to specify and angle in radians if you want.
#define piover180 0.0174532925
float pointX, pointY, pointZ, temp;
float cameraAngleX = SET THIS TO THE X ANGLE
float cameraAngleY = SET THIS TO THE Y ANGLE
pointY = sin(cameraAngleX*piover180)+cameraPositionY;
temp = cos(cameraAngleX*piover180);
pointX = sin(cameraAngleY*piover180)*temp+cameraPositionX;
pointZ = cos(cameraAngleY*piover180)*temp+cameraPositionZ;
gluLookAt(cameraPositionX, cameraPositionY, cameraPositionZ,
pointX, -pointY, pointZ,
0.0, 1.0, 0.0);
I use that for camera rotation. But if you just use it once it'll give you correct values that you can use.
12-23-2007, 01:46 PM
I am so sorry, I made a mistake in that code.
The lookAt point shout be (pointX, pointY, pointZ) I accidentally had -pointY. And then the calculation for pointY should have a negative in front:
pointY = -sin(cameraAngleX*piover180)+cameraPositionY;
My appoligies. It doesn't seem to allow me to edit my first post.
If you get vertically mirrored projection with glFrustum, you have probably swapped the bottom and top parameters, which is further suggested by the order in which the parameters occur on the screen shots. The order is left, right, bottom, top, near and far. My guess is that you pass top instead of bottom, and bottom instead of top, like in the screen shots.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.