Intermediate 3D scripting for Flash part 2/5:
Learn how to build a rotating cube in Flash 5 and also using the latest Flash MX drawing API
You can easily find tutorial
about 3d "wire-framed" cube. Just setup 8 points in 3d space. Then
apply the 3d equation to calculate the x,y of 2D, then connect
them with lines. Now how to make "face" instead of frames
?
In Flash MX, we can use the draw api to draw a filled face. In
Flash 5, it is more complex. I use 3 skewed triangle to fill a
face. So, I need 12 triangles.
Lets talk about the MX draw api first.
The first step is setting up the 8 points in 3d space.
The second step is setting
up the 6 faces. Store the corners point to the face.
Of course, I need 3D functions and rotation functions. They are described
in other sessions. Well, in Flash 5, the clipArray will contain 12 clip elements.
Each clip element is a triangle, so I store data to its reg array. The reg
array will contain 3 elements instead of 4. Then make triangle skew to fill
the triangle. The technique is similar to the movie "3d pyramid" that I describe
in another sessions.