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 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: