# calculating the "up" vector...

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

## Recommended Posts

Greetings all, I am having some mental block, and I can't see what I am doing wrong with the way I am calculating the up vector. I calculate my up vector like so
up.x = cos(roll) * sin(yaw) * sin(pitch)  - sin(roll) * cos(roll);
up.y = cos(roll) * cos(pitch) ;
up.z = sin(roll) * sin(yaw)   + cos(roll)  * cos(yaw) *  sin(pitch) ;

I know I am doing something stupid, so if someone can shed some light on this, it will be most appreciated! TIA!

##### Share on other sites
I haven't really examined the details of your formulation, but I wanted to note that you may not actually need the precise up vector.

If you are just passing to a lookat type function, it most likely only has to be "up" to the extent that UP dot TRUE_UP is positive (those lookat funcs will compute the true up vector for you based on what you pass in). In otherwords, <0,1,0> is fine for any orientation that isn't "upside down" and <0,-1,0> is fine for anything that IS "upside down".

Of course, that may not be why you need it, in which case you can ignore me. :-)

(fixed the UP dot TRUE_UP bit)

##### Share on other sites
this assumes up is (0, 1, 0)

up.x = cos(yaw)*sin(pitch)*sin(roll) - sin(yaw)*cos(roll)
up.y = sin(yaw)*sin(pitch)*sin(roll) + cos(yaw)*cos(roll)+
up.z = cos(pitch)*sin(roll)

Looking at what you got maybe z is up?

This is how I worked that out (I've no idea if its right :P)

http://planning.cs.uiuc.edu/node102.html

see the 4th matrix on that page, that rotates by yaw/putch/roll so if you multiply your normal up vector by that it should be the rotated up vector that you want. (I also notice if the up vector is only one axis then the result is just one column of that matrix)

##### Share on other sites
Quote:
 Original post by smitty1276I haven't really examined the details of your formulation, but I wanted to note that you may not actually need the precise up vector. If you are just passing to a lookat type function, it most likely only has to be "up" to the extent that UP dot TRUE_UP is positive (those lookat funcs will compute the true up vector for you based on what you pass in). In otherwords, <0,1,0> is fine for any orientation that isn't "upside down" and <0,-1,0> is fine for anything that IS "upside down". Of course, that may not be why you need it, in which case you can ignore me. :-)(fixed the UP dot TRUE_UP bit)

Come to think of it, your correct.

That will show me to not overthink the issue at hand.[embarrass]

Thanks guys! [smile]

Nanoha, yeah, for me, up is 0,0,1

##### Share on other sites
a simpler way that i use to find the up vector is by

finding out the distance between two objects.

delta = object2 - object1;
delta.noramlise;

then find out the right vector
right = vector(-delta.z, 0, delta.x);
right.normalise;

then to find the up vector just find the angle between delta and right using the crossproduct.
up = delta.crossproject(right);
up.normalise;

since you have all three vectors now you could build a quternion off these. But i hope this helps.

##### Share on other sites
If you know the forward and right (or left) vectors you could do a cross product.

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013175
×