Jump to content
  • Advertisement


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


Rotation Help for a real newbie?

This topic is 5280 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

I've got a very specific problem that has been driving me crazy for weeks. I have an object placed at an arbitrary point in 3d space. Its movement is derived from the addition of 3 vectors: its current "forward" vector + an "attraction" vector towards an object + an "avoidance" vector from an object. These vectors are recalculated every timer event and the object moves smoothly around the screen. However, I am at a complete loss for how to rotate the object so that it is always facing the direction it is traveling. I've read everything I could get my hands on about vectors and quaternions and this and that and I just can't make it happen. Specific advice on what I need to do would be appreciated. Thanks. (Remember, I'm completely new to this) [edited by - MECHSidhe on April 4, 2004 10:08:30 PM]

Share this post

Link to post
Share on other sites
What i''m going to show you is commonly called the UVN orientation matrix. Basically, you can represent the orientation of an object (which way is it facing), with a 3x3 matrix composed of 3 vectors. The three vectors are given the names Right (U), Up (V), and Forward (N). When performing operations such as rotations on a transformation matrix, you are implicitly treating your data as having an orientation. What you do is you start out with an identity matrix. The identity matrix is itself an orientation matrix with the UVN vectors: (1,0,0), (0,1,0), and (0,0,1). You probably recognize them as the orthonormal basis vectors in 3D. When you transform a point by this matrix, you''ll return the same point b/c the point is already in this orientation. However, if you change the orienation by rotating the identity matrix and then multiply, you''ll end up with a point rotated into the new orientation. If you store this new orientation with the point this you can do neat things such as billboarding or camera, or even have the orientation be a plane''s orientation (roll, pitch, and yaw) and to elevate the plane all you''d do is rotate around its V (right) vector that''s been saved. So, when you perform an transformation on an orientation matrix, you''re moving the basis vectors to whatever that matrix is for.

In your case you don''t need to rotate your object to face the direction it''s travelling per se. Since you''re already storing the object''s position and its forward vector (N), all you need are the up and right vectors V and U, respectively. Now, when you recalculate the forward vector and moving it into it''s new position, you need to perform the same transformation on the U and V vectors. When you "rotated" the foward vector it was probably with respect to the position of the object. So what you do is store the UVN orientation and position vectors as a 3x4 or a 3x3 and vector or 4 vectors, it''s up to you. Then you need to do the update transformation on the UVN orientation. When you multiply every vertex by the matrix and add the object''s position, your object should face it''s proper direction.

Share this post

Link to post
Share on other sites
Keep in mind that it's important for your UVN vectors to stay normalized or the object will appear scaled on whatever axis it's not normalized. You could accomplish the above method without storing the UVN matrix. With the system you have you could generate a new rotation matrix every update. This is how it would work: You'd keep the system you have. When you you change the direction of your forward vector, you save the old direction. You do a cross product between the new and the old forward direction to return a perpendicular rotation axis (one that's perpendicular to the plane made up by the new and old vectors. Then you use what you know about the dot product to retreave the angle between the new and the old. And then you form a rotation matrix, an axis-angle ("arbitrary") form to be exact, using the angle found and the perpendicular axis vector found. Given the matrix you then multiply all vertices in the object by it and they should about face. Note that throughout all of this you don't need to represent using matrices and matrix operations if optimization were important. MathWorld derives the . And i've seen at least 5 new threads started about it including this one just today, so you might wanna check them too.

EDIT: oh yeah, the dot product method of 'angle btw 2 vectors' is
|A| = magnitude of A
vectors A, B
A dot B = |A||B|cos(theta)
theta = arccos((A dot B)/|A||B|)

Hope that helps

[edited by - temp_ie_cant_thinkof_name on April 4, 2004 11:23:36 PM]

  • Advertisement

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!