Site hosted by Angelfire.com: Build your free website today!

Wireframe Objects and 3D Rotations

by Bill Tagliaferro

[Download Source]

In an article entitled "Do We Really Need Quaternion", Diana Gruber says: "The rotation matrix R is so intrinsically useful, it is worth taking the time to look at the derivation."

Even thought I'm not a Game Developer this topic interested me, when a number of threads appeared at the Flashkit message board because of a need to produce wireframe objects for simulations in which 3D motion is displayed. Well actually it's 6D motion, 3 translation (position) and 3 rotation (attitude)

The rotation matrix R that Diana talks about can be separated into the product of three rotations, one about each axis of the three dimensional system (e.g. X, Y, Z). What follows is NOT meant to be a mathematical derivation of these rotation matricies. This tutorial is meant for the "Mathematically Impaired" as a simple and practical method of 3D rotational motion and its use with wireframe objects.



Mathematical Definitions

Rotational matrices are often most easily conceptualized as noncommuting products of rotations about a single coordinate axes. These rotations are defined as:

(CCW rotation about forward axis, +x, produces roll)

(CCW rotation about down axis, +y, produces yaw or heading)

(CCW rotation about out axis, +z, produces pitch)

The combined result of rotations about all three coordinate axes is:

Then, to rotate the coordinates of a point about some arbitrary origin the equation is:

Where:

XO, YO, and ZO are the origin coordinates, and X, Y, and Z are the display coordinates of the point to be rotated.



How this looks in actionscript is:

Each of these functions receives the coordinates of a point P in display space, converts to object space, performs the rotation, converts back to display space, and returns the rotated point in the same vactor as input "P".



How they work:

The lines are drawn by attaching a line to point 1 and scaling it to point 2 (see source).



Initialization and "Connecting the Dots":



Make sure that you download the source file and study it carefully.

[Download Source]