finding the up an right vector...
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
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]
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]
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;
}
}
{
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;
}
}
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 ?
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 ?
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
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
Thanks for all the answers !
Ups... i have understood aggregate wrong...
my fault, sorry.
i''ll try this out, thanks !
Ups... i have understood aggregate wrong...
my fault, sorry.
i''ll try this out, thanks !
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement