Recreating Grant Skinner's sphereTest Part 1 — how 3D rotation in Flash treats each axis differently

A few months back, Flash guru Grant Skinner tweeted about a "little" sphereTest he had been working on while playing with the new 3D rotation api in Flash Player 10. He has since added several variations to it, but I thought it would be a fun exercise to try an re-create the original demo, for my own edification. Here is the first part of my journey.

So I initially just created a bunch of discs at equidistant points from the center; randomly rotated them along the X and Y axes; and started incrementing those rotation values over time. Weird stuff happened. things moved in bizarre directions. I did the same with the X and Z axes. More weird stuff. Y and Z. Even more. I tried putting the discs on different axes. Still more weirdness.  Obviously I needed to understand how 3D rotation worked. So I built the following test harness to better understand the interactions between each axis.

The interface is a little clunky (it IS a test harness, after all) but essentially it works thusly: given three different sets of discs — initially positioned out on either the X, Y, or Z axis — you can randomly rotate these discs along one or more axis, and then increment the rotation value along one of those axes. Randomizing or reseting initial rotation positions will stop and recenter each sphere.

After playing with this for a while, I realized what was happening. The X axis is the runt of the litter. Rotating an object along the X axis has no affect on the position of the other axes, but rotating the along the Y and Z axis also rotates the relative position of the X axis in space. Also, rotation along the Y axis doesn't affect the position of the Z axis, but the Y axis is rotated with changes to the Z Axis rotation.

All that to say, if I was to recreate Grant's sphereTest, I would most likely need to initially position the discs along the Z axis, randomize around the X and Y axes, and incremently rotate along the Y and Z. But how, exactly t do that wasn't exactly easy. More on that in the next posts.

Tags: , ,
2009.12.09 11:11 AM | Permalink 0 Comments