Jump to content
• Advertisement

#### Archived

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

# finding the up an right vector...

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

If you intended to correct an error in the post then please contact us.

## 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

##### Share on other sites
Advertisement
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

##### 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

##### 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

##### Share on other sites
dude why don t you just use angles much easier !!!!!!!!!

#### Share this 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

##### 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

##### Share on other sites
Thanks for all the answers !

Ups... i have understood aggregate wrong...
my fault, sorry.

i''ll try this out, thanks !

#### Share this 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

##### 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12
• Advertisement

• 9
• 21
• 11
• 9
• 17
• ### Forum Statistics

• Total Topics
632606
• Total Posts
3007381

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!