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

Performing complex 3D transformations<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

The Matrix3D class lets you transform 3D points within a coordinate space or map 3D points from one coordinate<br />

space to another.<br />

You don't need to understand matrix mathematics to use the Matrix3D class. Most of the common transformation<br />

operations can be handled using the methods of the class. You don't have to worry about explicitly setting or<br />

calculating the values of each elem<strong>en</strong>t in the matrix.<br />

After you set the z property of a display object to a numeric value, you can retrieve the object’s transformation matrix<br />

using the Matrix3D property of the display object’s Transform object:<br />

var leafMatrix:Matrix3D = this.transform.matrix3D;<br />

You can use the methods of the Matrix3D object to perform translation, rotation, scaling, and perspective projection<br />

on the display object.<br />

Use the Vector3D class with its x, y, and z properties for managing 3D points. It can also repres<strong>en</strong>t a spatial vector in<br />

physics, which has a direction and a magnitude. The methods of the Vector3D class let you perform common<br />

calculations with spatial vectors, such as addition, dot product, and cross product calculations.<br />

Note: The Vector3D class is not related to the ActionScript Vector class. The Vector3D class contains properties and<br />

methods for defining and manipulating 3D points, while the Vector class supports arrays of typed objects.<br />

Creating Matrix3D objects<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

There are three main ways of creating or retrieving Matrix3D objects:<br />

1 Use the Matrix3D() constructor method to instantiate a new matrix. The Matrix3D() constructor takes a Vector<br />

object containing 16 numeric values and places each value into a cell of the matrix. For example:<br />

var rotateMatrix:Matrix3D = new Matrix3D(1,0,0,1, 0,1,0,1, 0,0,1,1, 0,0,0,1);<br />

2 Set the value the z property of a display object. Th<strong>en</strong> retrieve the transformation matrix from the<br />

transform.matrix3D property of that object.<br />

3 Retrieve the Matrix3D object that controls the display of 3D objects on the stage by getting the value of the<br />

perspectiveProjection.matrix3D property of the root display object.<br />

Applying multiple 3D transformations<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

You can apply many 3D transformations at once using a Matrix3D object. For example if you wanted to rotate, scale,<br />

and th<strong>en</strong> move a cube, you could apply three separate transformations to each point of the cube. However it is much<br />

more effici<strong>en</strong>t to precalculate multiple transformations in one Matrix3D object and th<strong>en</strong> perform one matrix<br />

transformation on each of the points.<br />

Note: The order in which matrix transformations are applied is important. Matrix calculations are not commutative. For<br />

example, applying a rotation followed by a translation gives a differ<strong>en</strong>t result than applying the same translation followed<br />

by the same rotation.<br />

Last updated 6/6/2012<br />

360

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

Saved successfully!

Ooh no, something went wrong!