#### Archived

This topic is now archived and is closed to further replies.

# gluLookAt up vector

This topic is 5771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello, how to store correctly the 3 last parameters of gluLookAt function ? I never succeed doing something good. But that''s may be a geometrical problem ! i explain: consider thses position as vectors (x,y,z coordinates). i have a camera which have a pos (cam_pos) i have a car which have a pos (car_pos) this car moves on a terrain and the camera follow this car but is not at the same height than the car (it''s more heigher). So my up vector is not always 0,1,0 ! how to calculate it correctly please ! Fratt

##### Share on other sites
I believe the up vector is a unit vector, meaning it has a magnitude of 1. It''s used to find the angle of rotation for the vector you give it, and doesn''t have anything to do with the height. You should be able to just leave it as (0, 1, 0).

##### Share on other sites
no, strtok !
you''re wrond, and i''m sure.
the up vector is needed for opengl to draw a correct perspective:

let''s try something like that:
gluLookAt( 40,100,-20, 0,0,0, 0,1,0);
and look at your world: see all your scene is disturbed !

cordially,

Fratt

##### Share on other sites
I may have lost what you were trying to do,

But basically if the car follows the terrain, ie as the terrain goes up or down, the car sits parrallel to the polygon it sits on, then you would be able to get the correct up vector from the polygon it is sitting on''s normal (which can be calculated by taking a CrossProduct of the 3 vertexes of the polygon!!

This would then generate an up vector that is perpendicular to the landscape!!

Paul P.

##### Share on other sites
Nate Robins has a nice set of tutorials on this which lets you play around with the values of each function parameter and you can see it in real time....

Ill try to find the link and post it...

##### Share on other sites
sorry, if you find this question more mathematic than opengl,
i have posted too in math & physic, but best answers here.

yes PaulPrice,

but, the camera (in fact gluLookAt) isn''t on a parallel plan to the ground (not always).
its plan is around the vector defined by the eye and the aim of the gluLookAt

y|
| * top <- the up vector defined by these points
| /
| /
| /
| *Eye
|
| *aim
|
î|______________________________<- assume the ground plane
O j x/z

so, as you can see (sorry for the schema), the vector Eye->aim
is not parallel to the plan.
more, in space, i have the ground plan and this vector: and i lack doing an orthogonal vector to Eye->aim in up vector:
Eye->top

thanks for any help ! a lot

Fratt

##### Share on other sites
sorry, i didn''t know that it won''t respect the space characters.

you may understand anyway.

Fratt

##### Share on other sites
Nate''s opengl tutorial page

http://www.xmission.com/~nate/tutors.html

##### Share on other sites
Do you refer to the perspective demo ? i download all the demos and i ''ll test it this evening.
i don''t think this will help me. the perspective demo, let you change the param values of gluPerspective or gluLookAt but not adapte automatically the parameters if you move the view, and i want to move the view and not the scene.

thankx anyway, the demos seem good and touch some interressant parts of opengl.

Fratt

##### Share on other sites
The up vector for gluLookAt acts like rotating the camera left/right on the z axis... Eventually if you rotate it enough, it will make everything look like it is upside down... At least that how I understand it...

Edited by - ANSI2000 on February 20, 2002 12:08:56 PM

##### Share on other sites
There are two possibilities i''m gonna suggest here:
One, keep track of your up vector. If your camera rotates up by 15 degrees, rotate your up vector by 15 degrees about the same axis.

Two, keep track of your right vector...this may or may not be easier. If you know the direction you''re facing, and you know the vector sticking out of the right side of the car, you can take the cross product to find the up vector.

##### Share on other sites
>>i have a camera which have a pos (cam_pos)
i have a car which have a pos (car_pos)
this car moves on a terrain and the camera follow this car but is not at the same height than the car (it''s more heigher).

So my up vector is not always 0,1,0 ! how to calculate it correctly please !<<

the camera should always be 0,1,0

perhaps u want the vector (cam-car)

but i think u want the vector the cars roof is pointing in (which u will find by finding the orientation of the car) ie it has nothing to do with the heights

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
OK, i''ll try.

in fact, i have to make a rotation around an axis defined by a perpendicular direction to the car''s direction. so, this axis is arbitrary and could be whatever.

my camera is inclined to the bottom and could have any rotation to the default y opengl axis. the only axis that never have rotation around is the z axis of the system coordinate of the car (maybe called roll i think). But this axis is on the plan define by Ox, Oz (default value).

So, i think i have to calculate the angle make my the eye->aim related to the default plane ox,oz. And after find the axis perpendicular to the car''s direction and related to the face on which it''s at this time. So, next rotate the up vector around this axis to the angle found.

OK for that, i know it from a long time, but my calculations always fail, never good (maybe some lacks in mathematics ?!).

So, how would you do a rotation around a default axis ? using some special 1 way matrix (x,y,z) -> so vector.

Thank you all anyway

cordially,

Fratt

##### Share on other sites
Hi, sorry im late and i think people already tried to say this,
but i think youve got the glLookAt function wrong..

If your system has Y as up (most do, but not all)

and the cars possition is car_pos, and yours player_pos

You just use the glLookAt like

glLookAt(player_pos, car_pos, upvector)
where upvector = 0, 1, 0

That will automaticly make the camera follow the car, independent on where its located, up down left right, etc.

Like in a flightsimulator, you could use the upvector to create a rolling effect, if you for example wants to create a loop, you dont need to change the upvector, just the viewpoint.

So if you just want a static camera (which will not fly and roll)
just use upvector 0,1,0 (standing possition)

Later.

##### Share on other sites
I am sure that i need to modify the up vector because it is necessary for opengl to make a correct perspective, otherwise i''ll have an incorrect rendering: wall that are inclined, transformed...
And i don''t want to keep the vector to 0,1,0; this will implies that my camera is only at horizontal view.

Fratt

##### Share on other sites
If I understand the documentation, the up vector is always beeing mapped onto the viewing plane, so a fixed up vector should work for you.

##### Share on other sites
>>I am sure that i need to modify the up vector because ..<<

no it must always stay the same like in real life, if youre walking along up is above your head if u lie down on your back up is straight in front of you, your orientation to up is different but the up vector in both cases remains the same

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
Yes, you DO have to change the up vector - always! it is true that often the upvector is the positive y-axis but if you have moved the camera slighly up in y-axis and still is looking at the e.g. 0, 0, 0 then we need to update the up-vector.

E.g.

consider the point of interest to be 0, 0, 0
move the camera to some point e.g. 7.81, 11.12, 1.70

(sorry about the weired numbers, had my program calculate them for me but it doesnt really matter)

then the up-vector is going to be (i am assuming the we havent rotated the camera around its own axis)

up-vector -0.81, 0.57, -2.0e-8

so how does this work?

This is how i do it, im not saying it is the best way but it works for me...

to put simple, i find the normal to the surface that the line of sight and my own rotation vector (the one that keeps track of how much i have rotated the camera around the line of sight)...

this normal is then my up-vector.

hope it helps... you can find the math for how to do this in any book but if you want code email me...

Regards,

Jonas

##### Share on other sites
hello & thanx jonas !! thousand thanx !

so it has to move !! that is right ! of course this is right.

then, i''ll try it, some math & geometries, and then that''s all !

cordially,

Fratt

##### Share on other sites
hmmm why are u thanking him (perhaps cause its the answer u want to hear perhaps?)
anyways with gluLookAt(......) u do NOT change the up vector
fuck it i give up :D

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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 -

##### Share on other sites
you explained why i need to change the up_vector: seeing up & down .

thanx

Frat

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984334

• 23
• 11
• 10
• 13
• 14