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

A cube has sides not visible from the curr<strong>en</strong>t viewpoint<br />

So, the Graphics.drawTriangles() method has a fourth parameter to establish a culling value:<br />

public function drawTriangles(vertices:Vector., indices:Vector. = null,<br />

uvtData:Vector. = null, culling:String = "none"):void<br />

The culling parameter is a value from the TriangleCulling <strong>en</strong>umeration class: TriangleCulling.NONE,<br />

TriangleCulling.POSITIVE, and TriangleCulling.NEGATIVE. These values are dep<strong>en</strong>d<strong>en</strong>t upon the direction of<br />

the triangle path defining the surface of the object. The ActionScript API for determining the culling assumes that all<br />

out-facing triangles of a 3D shape are drawn with the same path direction. Once a triangle face is turned around, the<br />

path direction also changes. At that point, the triangle can be culled (removed from r<strong>en</strong>dering).<br />

So, a TriangleCulling value of POSITIVE removes triangles with positive path direction (clockwise). A<br />

TriangleCulling value of NEGATIVE removes triangles with a negative (counterclockwise) path direction. In the case<br />

of a cube, while the front facing surfaces have a positive path direction, the back facing surfaces have a negative path<br />

direction:<br />

A cube “unwrapped” to show the path direction. Wh<strong>en</strong> “wrapped”, the back side path direction is reversed.<br />

To see how culling works, start with the earlier example from “UV mapping” on page 364, set the culling parameter of<br />

the drawTriangles() method to TriangleCulling.NEGATIVE:<br />

container.graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NEGATIVE);<br />

Notice the “back” side of the image is not r<strong>en</strong>dered as the object rotates.<br />

Last updated 6/6/2012<br />

370

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

Saved successfully!

Ooh no, something went wrong!