Experiment 2 - When PerspectiveProjection is assigned to a 3D Object

The code for the applet below is basically the same as the code for the applet on the first page, except for changes in fieldOfView for pp1, pp2, and the root object explained below, and new buttons that test different things.

Changes in the Code

The file in the pp.zip corresponding to thes experiment is pp_show2.fla. For clearer effects, we vary in this applet values of the fieldOfView property of pp1, pp2, and this.transform.perspectiveProjection.

var pp1:PerspectiveProjection=new PerspectiveProjection();

pp1.fieldOfView=130;

pp1.projectionCenter=new Point(0,0);

var pp2:PerspectiveProjection=new PerspectiveProjection();

pp2.fieldOfView=100;

pp2.projectionCenter=new Point(0,0);

container1.transform.perspectiveProjection=pp1;

container2.transform.perspectiveProjection=pp2;

this.transform.perspectiveProjection.fieldOfView=50;

We have two buttons: btn3D which changes container1 into a 3D object and btn2D which makes container2 back into a 2D object.

btn3D.addEventListener(MouseEvent.CLICK,btn3DClick);

 

function btn3DClick(e:MouseEvent):void {

container1.z=0;

//After the z coordinate is assigned, container1 becomes a 3D object.

}

 

btn2D.addEventListener(MouseEvent.CLICK,btn2DClick);

 

function btn2DClick(e:MouseEvent):void {

container1.transform.matrix3D=null;

//container1 is now a 2D object as its matrix3D is null.

container1.x=100;

container1.y=120;

}

When container1 to which pp1 is assigned changes into a 3D object, the coordinates (0,0) of pp1.projectionCenter are interpreted as coordinates relative to the MainTimeline. Thus, the vanishing point moves to the upper left corner of the stage. fieldOfView remains unaffected at 130.

Download

  • Download all the source files corresponding to this tutorial: pp.zip

On the next page we leave containers but assign PerspectiveProjection to holder1 and holder2. Some interesting effects occur.

Back to Flash CS4 Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.