Intermission in the Third Dimension

I spent yesterday and today building a 3D engine for my Vector classes. This turned out to be some of the most difficult math I’ve ever wrapped my brain around. Here’s a screenshot:

Play with the .swf. Click the mouse; type some letters; move the mouse for beefy, savory 3D taste. Backspace to clear.

You’ll notice that the letters flicker; this is intentional. It’s a step towards simulating the “old cathode ray tube” look and feel that I desire.

I’m creating the flicker using one of my favorite tricks: flash.geom.ColorTransform . The line segments (and the glow) are being drawn using random shades of grey (including black and white). The ColorTransform maps black to a new color, and white to another color; in doing so, shades of grey are automatically mapped to color values ranging between the two.

The 3D action is, in a word, complicated. Many websites were consulted; many mathematical formulas were borrowed.

One of the biggest challenges was extending flash.geom.Point to a new class: “Point3D”. Also (especially) difficult was extending flash.geom.Matrix to “Matrix3D”. Of course, I wanted all my Vector drawing methods to support both 2D and 3D geometry, so there were issues with inheritance and casting. ActionScript 2.0 can’t tell you what class an object belongs to (all the classes mentioned in this paragraph evaluate to “Object”. Not helpful!) so I had to improvise. The 3D classes return true if you evaluate myObject[‘is3D’].

Also I added static create() methods to the 3D objects: these accept a Point/Point3D, or a Matrix/Matrix3D, and verifiably return a 3D equivalent of whatever you passed in.

I did this because I had issues with casting. This cast did not work for me, and I don’t yet understand why:

var myMatrix3D:Matrix3D = Matrix3D( myMatrix2D );

The 3D algorithm took a day and a half to get right. I relearned matrix multiplication along the way. I was giddy and cheering when it finally worked. This is a major step forward.

One thought on “Intermission in the Third Dimension

Leave a Reply

Your email address will not be published.