Each Cube has Its Own PerspectiveProjection

In the applet on this page, each cube - this time an instance of a custom class CubeMenu - has its own PerspectiveProjection. Sorting is much easier in this case. The visual result is not quite correct mathematically but in many cases it looks pleasing to the eye.

Download

  • Download all files corresponding to the applets in this tutorial: zsort.zip

The files corresponding to the applet on this page are cube_menu.fla and CubeMenu.as.

Custom Perspective Projection and Sorting

The custom perspective projection assigned to each instance of the CubeMenu class has its center at the center of the cube. Sorting becomes very easy: we sort with respect to the z-coordinate of each side relative to the cube. The five cubes will not be affected even if root's pespective projection settings are changed.

To assign a custom PerspectiveProjection, we put our cube in a 2D container and assign a PerspectiveProjection to the 2D container. You should never assign PerspectiveProjection to 3D objects (that is objects on which AS3 3D methods are used).

Check out CubeMenu.as to see how to assign a custom PerspectiveProjection object. You can also consult our other tutorials devoted to the topic:

Back to Flash CS4 Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.