Archived

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

hansi pirman

finding the up an right vector...

Recommended Posts

hi again ! I have my own lookAt() routine in my camera code. Now in that function I can easy caculate the new Facing Vector, but is there also a way to find the Up- and Right-Vector for that facing Vector ? I think it must be possible, but i dont know how.. Thanks for any help again ! regards hansi pirman

Share this post


Link to post
Share on other sites
Okay, say we start out with these defaults:
look = (0, 0, -1)
up = (0, 1, 1)
right= (1, 0, 0)

Now, to get the vectors we need to do this:
normalize(look)
right = cross_product(look, up)
normalize(right)
up = cross_product(right, look)
normalize(up)

Should do it.

------------
Nevermind, I read your post incorrectly.

[edited by - aggregate on November 8, 2002 5:23:52 PM]

Share this post


Link to post
Share on other sites
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
{
float angle;
float sr, sp, sy, cr, cp, cy;

angle = angles[YAW] * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
angle = angles[PITCH] * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = angles[ROLL] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);

if (forward)
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if (right)
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*cr*cy);
right[2] = -1*sr*cp;
}
if (up)
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
}
}

Share this post


Link to post
Share on other sites
hm...
I think you misunderstand my question..

the only thing which is given is the facing vector.
there are no angles and so up and right vectors given.

So for example, the facing vector may be
Vector(0.324324f,0.1234f,0.84565);
(lets assume its normalized, i have just put some random values here...
now how can i find the up and right vector for this facing vector ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by hansi pirman
the only thing which is given is the facing vector.
there are no angles and so up and right vectors given.

Do what aggregate said!

You make the UP vector (0, 0, 1) even though it is wrong it doesn''t matter at this stage.

Cross product the FACING and UP vectors and you will get a CORRECT RIGHT vector. Then cross product the FACING and RIGHT vectors and you will get a CORRECT UP vector different from the original (0, 0, 1)

It does work

Share this post


Link to post
Share on other sites
quote:
Original post by hansi pirman
the only thing which is given is the facing vector.
there are no angles and so up and right vectors given.

Do what aggregate said!

You make the UP vector (0, 0, 1) even though it is wrong it doesn''t matter at this stage.

Cross product the FACING and UP vectors and you will get a CORRECT RIGHT vector. Then cross product the FACING and RIGHT vectors and you will get a CORRECT UP vector different from the original (0, 0, 1)

It does work

Share this post


Link to post
Share on other sites
Sorry guys, but this doesn''t work.. when the facing vector is only rotatet about the x OR the y axis, it works fine when i
I use an initial UP Vector of (0,1,0).
but if the facing vector was rotated about the x and y axis, then i get some very funky wrong results..

do i have to use other initial values for the up vector, because i''m using opengl (left handed vs. right handed)...

thanks for any help again

regards
hansi pirman

Share this post


Link to post
Share on other sites
ops... it works, sorry !
my fault, i had implemented the cross product wrong...

but i have still a little problem:

The Vector is always pointing Up (y>=0), but i want i to point down when the facing vector was rotatet about the x axis more then 90°... but if this is the case, the up vector "flips back" and is still pointing up

Share this post


Link to post
Share on other sites
If you are actually using a rotation to find the new facing then you run the up vector through the same rotation. The answer given was more for when you arbitrarily assign a new facing. Lookat which was mentioned is a prime example. You don''t rotate to that direction but rather just switch to it. If your Lookat is actually rotating the camera smoothly to point in that direction then just rotate the up vector along with it. It will still be an orthogonal vector as long as it is a linear transform, i.e. uniform scaling with no shear.

Share this post


Link to post
Share on other sites