# OpenGL Up vector?

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

## Recommended Posts

Well, I've been studying OpenGL through Beginning OpenGL Game Programming. Everything is good and all, except this: gluLookAt() I understand what the eye vector is (the position of the camera), what the center vector is (it's reference point or what it's looking at), but I do NOT understand what the up vector is. I'm thinking is a few units up of the camera or something? I've looked at several places google told me to look at but I still do not understand what the up vector is for or how to get it. Can you please tell me what it means and how to get it given that I know the camera's position and what it's looking at?

##### Share on other sites
It's the up direction which for FPS style games is typically (0,1,0).

Hope that helps,

Dave

##### Share on other sites
Quote:
 Original post by DaveIt's the up direction which for FPS style games is typically (0,1,0).Hope that helps,Dave

So it's basically a direction? So 1 for y would mean "up". Ahh, yes I see. I thought I had to set it to some weird position.

Thanks.

##### Share on other sites
The "up" vector is not necessarily pointing directly up. To obtain a non-distorted image, the up vector should be perpendicular to the forward vector and the right vector.

Therefore, if you are a P and are looking at Q, the up vector may not be (0,1,0) (For example if P and Q are at different heights)

There is some vaguely clever way of calculating it sensibly that I've used before, but I can't remember exactly what it is - someone's bound to have documented a sensible method.

Mark

##### Share on other sites
Quote:
 Original post by markrThe "up" vector is not necessarily pointing directly up. To obtain a non-distorted image, the up vector should be perpendicular to the forward vector and the right vector.Therefore, if you are a P and are looking at Q, the up vector may not be (0,1,0) (For example if P and Q are at different heights)There is some vaguely clever way of calculating it sensibly that I've used before, but I can't remember exactly what it is - someone's bound to have documented a sensible method.Mark

Yes, I see. That's what I thought, because if for example you look up in an FPS, your forward would be your previous up, and your up would be behind you.

But, how do I calculate it I don't know...

##### Share on other sites
The up vector is not a position like the other two vectors. It is merely a direction. Basically, imagine that your head has an array sticking out of it straight up. If you're standing upright, looking straight ahead, then it will indeed be sticking straight up. But if you're laying on your side, then it is no longer straight up, but also point to the side as well. You're still looking that the same location, and your head is still in the same spot (imagine you constructed a five-foot high platform where you were previously standing), but your up vector is different, and causes your view to be rotated. Make sense?

##### Share on other sites
If you use lookat anyway you don't have to case, as long as it is at least pointing into the right half space. The function will go and adjust all your vectors anyway, so as long as you don't look more than 90° up or down you can ALWAYS use (0,1,0).

If you want to do it yourself, you calculate "forward", use a cross product with the temporary "up" to get the correct "right" and then use another cross product between forward and right to get the correct "up". Make sure all three are normalized and plug them into the matrix.

##### Share on other sites
If you've played the Prey demo, think about those walkways that went all over the walls and ceilings. When you get on one and start walking up onto a wall, for example, the direction that is "up" to you changes -- it rotates so that it's perpendicular to the walkway.

##### Share on other sites
Quote:
 Original post by TriencoIf you want to do it yourself, you calculate "forward", use a cross product with the temporary "up" to get the correct "right" and then use another cross product between forward and right to get the correct "up". Make sure all three are normalized and plug them into the matrix.

To wit, the forward, right and up are orthogonal to each other and so if you have two vectors you can derive the third one by cross multiplying the first two. Ex:

1) up = forward.Cross(right); //where Cross is a function that performs vector cross multiplaction

2) up.Normalize(); //Remember to normalize since it's the direction you are interested in.

##### Share on other sites
Just to add to that to calculate a normal(normal is a perpendicular to a line) you use a cross product of the 2 vectors(start and end)

1. 1
Rutin
73
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633426
• Total Posts
3011812
• ### Who's Online (See full list)

There are no registered users currently online

×