Skip to main content
GameDev.net gamedev.net
🔒 Locked

calculating the "up" vector...

Started by Clancy Sep 10, 2009 at 12:19 AM 4 replies 6.5k views
Original Post
Clancy
Clancy
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!
smitty1276
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)
Nanoha
Nanoha
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)
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.
Clancy
Clancy
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
Evo89
Evo89
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.
Platinum314
Platinum314
If you know the forward and right (or left) vectors you could do a cross product.
The sentence below is true.The sentence above is false.And by the way, this sentence only exists when you are reading it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.