13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working in three dim<strong>en</strong>sions (3D)<br />

(0,0,0)<br />

D<br />

B<br />

A<br />

The positive directions of the x, y, and z axes in the ActionScript 3D coordinate system.<br />

A. + Z axis B. Origin C. +X axis D. +Y axis<br />

Note: Be aware that Flash Player and AIR always repres<strong>en</strong>t 3D in layers. This means that if object A is in front of object<br />

B on the display list, Flash Player or AIR always r<strong>en</strong>ders A in front of B regardless of the z-axis values of the two objects.<br />

To resolve this conflict betwe<strong>en</strong> the display list order and the z-axis order, use the transform.getRelativeMatrix3D()<br />

method to save and th<strong>en</strong> re-order the layers of 3D display objects. For more information, see “Using Matrix3D objects for<br />

reordering display” on page 362.<br />

The following ActionScript classes support the new 3D-related features:<br />

1 The flash.display.DisplayObject class contains the z property and new rotation and scaling properties for<br />

manipulating display objects in 3D space. The DisplayObject.local3DToGlobal() method offers a simple way<br />

to project 3D geometry onto a 2D plane.<br />

2 The flash.geom.Vector3D class can be used as a data structure for managing 3D points. It also supports vector<br />

mathematics.<br />

3 The flash.geom.Matrix3D class supports complex transformations of 3D geometry, such as rotation, scaling, and<br />

translation.<br />

4 The flash.geom.PerspectiveProjection class controls the parameters for mapping 3D geometry onto a 2D view.<br />

There are two differ<strong>en</strong>t approaches to simulating 3D images in ActionScript:<br />

C<br />

1 Arranging and animating planar objects in 3D space. This approach involves animating display objects using the x,<br />

y and z properties of display objects, or setting rotation and scaling properties using the DisplayObject class. More<br />

complex motion can be achieved using the DisplayObject.transform.matrix3D object. The<br />

DisplayObject.transform.perspectiveProjection object customizes how the display objects are drawn in 3D<br />

perspective. Use this approach wh<strong>en</strong> you want to animate 3D objects that consist primarily of planes. Examples of<br />

this approach include 3D image galleries or 2D animation objects arranged in 3D space.<br />

2 G<strong>en</strong>erating 2D triangles from 3D geometry, and r<strong>en</strong>dering those triangles with textures. To use this approach you<br />

must first define and manage data about 3D objects and th<strong>en</strong> convert that data into 2D triangles for r<strong>en</strong>dering.<br />

Bitmap textures can be mapped to these triangles, and th<strong>en</strong> the triangles are drawn to a graphics object using the<br />

Graphics.drawTriangles() method. Examples of this approach include loading 3D model data from a file and<br />

r<strong>en</strong>dering the model on the scre<strong>en</strong>, or g<strong>en</strong>erating and drawing 3D terrain as triangle meshes.<br />

Last updated 6/6/2012<br />

352

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!