Sign in to follow this  
Clancy

calculating the "up" vector...

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by smitty1276
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)


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 this post


Link to post
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 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