Sign in to follow this  

can you teach me gluLookAt() ???

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

can you teach me gluLookAt() i didnt understand gluLookAt() this function have too much parameters... Can you teach me this function?:D Thanks to Everybody

Share this post


Link to post
Share on other sites
First 3 are x/y/z for where you are in the world, next 3 are x/y/z for the point you're looking at, last 3 are x/y/z of what you define to be up (doesnt usually change, usually (0,1,0) .

Share this post


Link to post
Share on other sites
Hi !

There are various resources on the net behind the math of gluLookAt. Essentially it boils down to the creation of an orthonormal basis of the camera coordinate system. As we are in 3D and work with 4x4 matrices, we need to specify at least two axis (the 3rd can be automatically computed) and a translation vector.

These vectors (more specifically their components) are the parameters to gluLookAt:

first you have the position of the eye, which is the translation part of the coordinate system 4x4 matrix.
Then you have the lookAt position, which in combination with the eye yields the first axis of your coordinate system (called z by convention) as Vec3 axis_z = (lookAt - eye).
This axis alone doesnt help much, hence this is where the up vector jumps in, being the y-axis of our new system.
Creating the third axis (x) would be just a matter of the cross product, but nobody would use gluLookAt, if things were so simple.

The one requirement we have for our coordinate system is its orthogonality (means all axis are in 90 degree to each other). To fulfill this requirement with any 3 vectors given as arguments, a little more vector arithmetics is involved :

The basic steps are :

a) Cross (lookAt-eye) with up => x_axis
b) Cross x_axis with (lookAt-eye) again, to make sure , up is really 90° to the viewing direction
c) All vectors need to be normalized by the end of the day (hence the name ortho-NORMAL)
d) matrix multiply the translational part

this site explains it more comprised : gluLookAt

There is one thing left though : The matrix build up so far transforms the camera from the center of the world space (0,0,0) to its actual position and orientation. What you actually want is the inverse (called modelview - matrix in OpenGL):
Locate the camera at (0,0,0), align it with the base axis and move/rotate the rest of the world accordingly. Fortunately we dont have to do it the hard way, a little mathematical trick concerning orthonormal matrices helps us out :
Just use the vectors computed at c) as the rows, not the columns (this is called "transposing") of the upper 3x3 matrix and multiply the negated translation to this matrix (as explained in the link above).

This is all there is to gluLookAt ! Googling gives you a lot more resources on the various mathematical topics.


Share this post


Link to post
Share on other sites

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