gluLookAt up vector

Started by
25 comments, last by Fratt 22 years, 1 month ago
Well I don''t actually understand why some want to change the up vector. If I look at a point in world space and then walk to the left ot to the right, still looking at that point, the up vector won''t change in any case, right?
Now if I would move up or down, the up vector would change, it must always be projected onto the plane, where the normal vector is the eye -> look at vector. still right?
Now, when I understand the glu function right, the up vector you pass will always be projected onto that plane, before forming the matrix (at least my OpenGL does it). So could somone tell me why to change the up vector in this case.
Advertisement
hi all !

i created a little demo: a car, a road and skycrapers around the road.
When i''m in the car (the view is horizontal), all the skyscrappers look fine, the wall are right up !
But when i''m outside the car, the camera always move up and down ( of course, follow the car...). And the skyscrappers have got their walls not fine: they are inclined !!!
SO im sure i need to change the up vector in this case !

could someone can convain of this ?

Fratt
jonbo372, you are both right and wrong. If you move the viewpoint upwards, but not the look at point, the up vector will change, that is correct. But the thing is, you do NOT have to update the up vector you pass to gluLookAt (unless the view direction is equal to the up vector, or the inverse of the upvector). The up vector passed to gluLookAt is not THE up vector used, it''s a, how to say it, a "hint" to tell gluLookAt where the up vector''s direction should go. gluLookAt will find the vector closest to the up vector you pass, and use that one as THE up vector.

In short, gluLookAt works like this.

Note that order of operation matters in the crossproduct, and I''m not sure which vector goes first in this case. But the idea is the same.

  front_vector = look_at_point - viewpointside_vector = front_vector cross up_vector (<- this up vector is the one you pass)new_up_vector = front_vector cross side_vector  


If you normalize these three vectors, you have an orthonormalized vector system, ready to be put into the transformation matrix.

And the up vector passed to gluLookAt does not have to be of unit length.
I think your problem is that you want the camera to always give a view ahead of the car''s front hood, so if the car is climbing a steap hill you want the camera to be following and looking up diagonally. Keeping the up vector as (0, 1, 0) is if you want your camera to simulate human head movement. If we look up, then look right it''s not the same as if a plane pitches up, then yaws right. Anyway, what you have to do is keep track of where up is, the normal to the car''s roof. If your car is on a 45deg hill, then your up vector is (0, 1, 1), assuming your car is looking down (0, 0, 1).

------------
- outRider -
you explained why i need to change the up_vector: seeing up & down .

thanx

Frat
And what, in your opinion, would happen, if you just change the look at (center) point (I''m still taking about gluLookAt).
this is what i mean ! if you move your aim but not your eyes, all around yourself, then the upvector won''t be the same !!

i''ll try the cross product method.

Fratt

This topic is closed to new replies.

Advertisement