Advertisement

Building a rotation matrix with orientation vectors

Started by February 17, 2003 06:28 AM
0 comments, last by UnknownPlayer 22 years ago
In my game I have the position of an object defined by three orientation vectors - Right, Up, Direction I rotate my object by rotating these vectors respectively by each other - i.e. first we rotate up and direction around right and so on. The problem is, I don''t know then how I should convert these orientation vectors into a rotation matrix that can be applied to the object they store information for. Is there a simple way I can just use these to fill out a matrix structure or is a trigonometric conversion needed? ##UnknownPlayer##
##UnknownPlayer##
Assuming those vectors are all exactly at right angles to each other (orthogonal)...

1) Normalise the 3 vectors ("orthonormal basis")


2) Set the matrix to identity.


3) Put the vectors into the top left 3x3 part of your matrix:

m00 = right.x;
m10 = right.y;
m20 = right.z;
m01 = up.x;
m11 = up.y;
m21 = up.z;
m02 = dir.x;
m12 = dir.y;
m22 = dir.z;


4) Voila, the resultant matrix is a rotation matrix which rotates into the coordinate system ("space") described by the three vectors ("basis vectors")


It''s as simple as that, you already have the hard part which is the three vectors at right angles.

Something worthwhile IMO is to draw the vectors above on the screen for a few common matrices (i.e. create the matrices however you want, then extract the above vectors and render them as lines). I think you''ll find it quite instructional, you''ll see that rotations just preserve the right angle relationship between the vectors, that a scaling matrix changes the lengths of the vectors (thus the normalise in step 1). A translation is effectively moving the location of where the 3 vectors meet (the origin of the coordinate system)

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement