Sign in to follow this  
DjMaSh

gluLookAt() - wats the point?

Recommended Posts

Hello, Ive just found this function, gluLookAt, though I dont fully understand how to use it. Firsty, wats the point in having an 'up' vector? Would you not just change reference point where you were looking to be shifted up or down? Why can the up vector not be parallel with the line of sight created? Say I wanted to look straight ahead (from the origin). We would pass the following parameters to the function: gluLookAt(0, 0, 0, 0, 0, -1, 0, 0, -1); Though this causes the up vector to be parallel with the line of sight. How can we look straight ahead using this function? So yeah, any explanation on the point in this 'up' vector and how to use this function properly would help. Mash

Share this post


Link to post
Share on other sites
Quote:
Original post by DjMaSh
Firsty, wats the point in having an 'up' vector? Would you not just change reference point where you were looking to be shifted up or down?
A position and target is not enough information to uniquely determine an orientation for the camera (the camera can roll freely about its forward axis while still looking at the target, so there is an infinite number of orientations that satisfy these requirements). The 'up' vector provides an extra bit of information that allows the orientation to be uniquely determined.
Quote:
Why can the up vector not be parallel with the line of sight created?
The 'look at' algorithm computes the side vector (and, indirectly, the 'actual' up vector) by taking the cross product of the reference up vector and the line-of-sight vector. If these two vectors are parallel or nearly parallel, the cross product yeilds the zero vector (or nearly so), and the algorithm fails.
Quote:
Say I wanted to look straight ahead (from the origin). We would pass the following parameters to the function:

gluLookAt(0, 0, 0, 0, 0, -1, 0, 0, -1);

Though this causes the up vector to be parallel with the line of sight. How can we look straight ahead using this function?
Just submit (e.g.) the positive y axis for the reference up vector:
gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);
Does that help?

Share this post


Link to post
Share on other sites
The up vector is used to tilt the camera to the side. It is the direction the top of the camera should face. If you want the image to be upside-down, you make the up vector point down. If you want the image to be sideways, you make the up vector point to the side. If you want the image to be right-side-up, you make the up vector point up.

Share this post


Link to post
Share on other sites
AHHH! Of course, I forget that cameras can roll. Im making a snowboarding game so this doesn't happen, but in a plane or something it would. Wiked, that makes sense
for the up vector being there now.

Quote:
Just submit (e.g.) the positive y axis for the reference up vector:
gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);
Does that help?


Right, so the up vector determines the orientation. I was thinking that providing an up vector of {0, 1, 0} would lift the camera's angle up by 1 in the y axis. Excellent, this all makes sense now.

Thanx!!!

Share this post


Link to post
Share on other sites

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