Archived

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

How best to align objects' orientations

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

Objects in my game have their own right, up, and forward vectors. I often need to align them. I figure I can align the right vectors, then rotate the objects about the right vectors until their up vectors are aligned. I''m wondering if there''s a more efficient or easier method of doing this. If there''s not, then that''s okay. I just want to be sure. Thanks yckx

Share this post


Link to post
Share on other sites
There is a very good way to do this, but it might involve changing your code considerably.

First, represent your orientation using quaternions - your direction vectors (or an orientation matrix) can be extracted from the quaternion.

Then, there''s a function called ShortestArc in Game Programming Gems I (I think) that gives you a quaternion that rotates from one vector to another. Multiply that quaternion by your current quaternion to get your ''goal'' quaternion. Then you can slerp to the new quaternion at whatever speed you want.

That may be more than you want to tackle, and your method may be sufficient. This method is elegant, though, and should always produce smooth and consistent results.

Share this post


Link to post
Share on other sites
Like jyk says, quaternions are a very good way to handle rotations. But they are very difficult!

If you''re new at this, I think it''s better to first write a few simple functions to modify your matrix (translate/rotate/scale/lookat/..). And use matrices only, for all your objects.

When you already can juggle matrices like a clown (translation: can do anything with matrices)..
A better way is to represent rotations with a simple angle-axis. OpenGL''s standard rotation function (glRotate()) uses this angle-axis representation. These are relatively simple and intuitive.

After that I would implement classes for matrices, angle-axis, and quaternions. And make typecasting operators, so ''juggling'' rotations becomes as easy as can be

Share this post


Link to post
Share on other sites