Jump to content
  • Advertisement
Sign in to follow this  

can you teach me gluLookAt() ???

This topic is 4669 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
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!