PDA

View Full Version : Setting up a camera



05-09-2000, 07:51 AM
Whats best to use when setting up camera?, gluLookat, glFrustum, gluPrespective or what?
I'm gonna use data from MAX's ascii exporter to get camera position and angels and so far i haven't succeded to get it completly right.
So, anyony got some hints?

Bob
05-10-2000, 03:28 AM
I suggest you use gluLookAt to set cameraposition, and gluPerspective to set field of view and near/far clipping planes. Two simple functions.
gluLookAt's last three arguments is called the upvector and can be a bit hard to understand. Its a vector pointing upwards relative to the camera.
Also make sure you have the correct matrix active when calling these functions. When calling gluLookAt, you should have the modelview matrix active. When calling gluPerspective, the projectionmatrix should be active.

glMatrixMode(GL_PERSPECTIVE);
gluPerspective(fov, aspect, near, far);
glMatrixMode(GL_MODELVIEW);
gluLookAt(p.x, p.y, p.z, t.x, t.y, t.z, u.x, u.y, u.z);

This will place the camera at position p, pointing towards t, and have u as upvector.
fov is field of view. The angle between the line of sight and the upvector ahould always be 90 degrees.
aspect is the aspect ratio, screen width/screen height (can be height/width... not sure)
near/far is near and far clipping planes.

05-11-2000, 09:48 PM
Thanks, works fine. But i had to use the
glMatrixMode(GL_PERSPECTIVE) when running gluLookAt() otherwise it didn't work!??

MikeC
05-12-2000, 12:25 AM
Don't you mean glMatrixMode(GL_PROJECTION) ?

Bob
05-12-2000, 03:19 AM
http://www.opengl.org/discussion_boards/ubb/eek.gif

Of course i meant GL_PROJECTION. First line in my code above should be what MikeC said, sorry...