Skip to main content
gamedev.net
🔒 Locked

vector math

Started by kill 6 replies 600+ views
Original Post
kill
kill
Hi. I have a number of questions that all follow from each other. 1. I have a unit vector that holds a direction of a mesh. I also have an angle around it. How do I get the up vector based on this angle and vector? 2. If I have two orthogonal unit vectors, how do I rotate one around the other by a certain number of degrees? Thanks.
shankel
shankel
quote:
Original post by kill

Hi. I have a number of questions that all follow from each other.

1. I have a unit vector that holds a direction of a mesh. I also have an angle around it. How do I get the up vector based on this angle and vector?
2. If I have two orthogonal unit vectors, how do I rotate one around the other by a certain number of degrees?

Thanks.


1. Why are you storing orientations this way? When you say you have an "angle around" this vector, from what reference point is this angle taken? From the y (up) axis? What happens when the vector-part points along the y-axis?

You should look into storing orientations with matrices or as net rotation about an axis.

The "up" vector can be derived from the second column of a rotation matrix (the first three columns define the three axes of the transformed space; the second column is the y-axis).

The up vector can be derived from an axis-angle (or quaternion) orientation by converting it to a matrix and following the above directions.

For more info on the relationship between matrices, quaternions and axis-angle representations, check out the matrix and quaternion faq at:

http://skal.planet-d.net/demo/matrixfaq.htm

2. To rotate P about V by angle theta, producing R (assuming P and V are orthogonal):

R = Pcos(theta) + (V cross P)sin(theta)


Jason



Edited by - shankel on November 10, 2000 2:25:40 PM
Jason ShankelMaxis/EA
kill
kill
An axis and an angle around an axis = angle-axis

Thanks a lot.
shankel
shankel
quote:
Original post by kill

An axis and an angle around an axis = angle-axis

Thanks a lot.



Well, I hope this is helping. The main thing is that axis-angle rotations do not represent a facing vector and roll angle. While you can represent orientations this way, you are subject to the same difficulties that Euler angles have.

It's more like you're impaling your model on a spear and rotating it around the spear. The spear can come in at any angle; it doesn't have to go in the front and out the back luau-style.

I'm not sure that metaphor helped much; but it's been a long day. I get nervous when we don't have a President-Elect.

The important thing to keep in mind is that with axis-angle representations, if the angle is 0, then this *always* represents an identity transform (no rotation whatsoever). If the angle is zero, it will keep the object at the origin looking down the z-axis (or whatever your 'non-rotated' state is), regardless of how you modify the axis vector.

That's why with quaternions the vector-part is always (0,0,0) when the angle is 0. Because if the angle is 0 then it just doesn't matter what the axis is.

If you impale an object but don't rotate it, it's orientation doesn't change (though it might get mad).


Jason



Edited by - shankel on November 9, 2000 9:03:03 PM
Jason ShankelMaxis/EA
kill
kill
Thanks. Your comments helped a LOT.

Thanks for the 0-angle comment. I guess the angle doesn''t have to be 0, it can always be some really really small value close to zero. I''m sure the player won''t notice...

Again, thanks for your help.
shankel
shankel
quote:
Original post by shankel


2. To rotate P about V by angle theta, producing R (assuming P and V are orthogonal):

R = Pcos(theta) + V cross P


Jason




Oops oops oops, make that:

R = Pcos(theta) + (V cross P)sin(theta)

My bad. I''ll also edit the original to avoid confusion.

Jason
Jason ShankelMaxis/EA
kill
kill
Are there any code samples I can look at that implement some kind of a system that hold''s object''s orientation in 3D space. This is taking me a LONG time to figure out, and for some reason I can''t get it to work
shankel
shankel
quote:
Original post by kill

Are there any code samples I can look at that implement some kind of a system that hold''s object''s orientation in 3D space. This is taking me a LONG time to figure out, and for some reason I can''t get it to work


If you''ve got DirectX, there are some code samples on the disk for displaying 3d objects. There are also some good tutorials on www.opengl.org

Jason

Jason ShankelMaxis/EA

Topic Locked

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

Sign in to reply to this topic.