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

}<br />

}<br />

}<br />

t1 = focalL<strong>en</strong>gth/(focalL<strong>en</strong>gth + z1);<br />

t2 = focalL<strong>en</strong>gth/(focalL<strong>en</strong>gth + z2);<br />

t3 = focalL<strong>en</strong>gth/(focalL<strong>en</strong>gth + z3);<br />

t4 = focalL<strong>en</strong>gth/(focalL<strong>en</strong>gth + z4);<br />

// determine triangle vertices based on t values<br />

var vertices:Vector. = new Vector.();<br />

vertices.push(x1*t1,y1*t1, x2*t2,y2*t2, x3*t3,y3*t3, x4*t4,y4*t4);<br />

// set T values allowing perspective to change<br />

// as each vertex moves around in z space<br />

var uvtData:Vector. = new Vector.();<br />

uvtData.push(0,0,t1, 1,0,t2, 1,1,t3, 0,1,t4);<br />

// draw<br />

container.graphics.clear();<br />

container.graphics.beginBitmapFill(bitmapData);<br />

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

To test this example, save these two class files in the same directory as an image named “ocean.jpg”. You can see how<br />

the original bitmap is transformed to appear as if it is vanishing in the distance and rotating in 3D space.<br />

Culling<br />

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

Culling is the process that determines which surfaces of a three-dim<strong>en</strong>sional object the r<strong>en</strong>derer should not r<strong>en</strong>der<br />

because they are hidd<strong>en</strong> from the curr<strong>en</strong>t viewpoint. In 3D space, the surface on the “back” of a three-dim<strong>en</strong>sional<br />

object is hidd<strong>en</strong> from the viewpoint:<br />

A<br />

B<br />

The back of a 3D object is hidd<strong>en</strong> from the viewpoint.<br />

A. viewpoint B. 3D object C. the back of a three dim<strong>en</strong>sional object<br />

C<br />

Inher<strong>en</strong>tly all triangles are always r<strong>en</strong>dered no matter their size, shape, or position. Culling insures that Flash Player<br />

or AIR r<strong>en</strong>ders your 3D object correctly. In addition, to save on r<strong>en</strong>dering cycles, sometimes you want some triangles<br />

to be skipped by the r<strong>en</strong>der. Consider a cube rotating in space. At any giv<strong>en</strong> time, you'll never see more than three sides<br />

of that cube since the sides not in view would be facing the other direction on the other side of the cube. Since those<br />

sides are not going to be se<strong>en</strong>, the r<strong>en</strong>derer shouldn't draw them. Without culling, Flash Player or AIR r<strong>en</strong>ders both<br />

the front and back sides.<br />

Last updated 6/6/2012<br />

369

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

Saved successfully!

Ooh no, something went wrong!