topical media & game development
animation-ch16-SpinningE.ax
animation-ch16-SpinningE.ax
[swf]
[flash]
flex
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class @ax-animation-ch16-SpinningE extends Sprite
{
private var points:Array;
private var numPoints:uint = 12;
private var fl:Number = 250;
private var vpX:Number = stage.stageWidth / 2;
private var vpY:Number = stage.stageHeight / 2;
public function @ax-animation-ch16-SpinningE()
{
init();
}
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
points = new Array();
points[0] = new animation_ch16_Point3D(-150, -250, 100);
points[1] = new animation_ch16_Point3D( 150, -250, 100);
points[2] = new animation_ch16_Point3D( 150, -150, 100);
points[3] = new animation_ch16_Point3D( -50, -150, 100);
points[4] = new animation_ch16_Point3D( -50, -50, 100);
points[5] = new animation_ch16_Point3D( 50, -50, 100);
points[6] = new animation_ch16_Point3D( 50, 50, 100);
points[7] = new animation_ch16_Point3D( -50, 50, 100);
points[8] = new animation_ch16_Point3D( -50, 150, 100);
points[9] = new animation_ch16_Point3D( 150, 150, 100);
points[10] = new animation_ch16_Point3D( 150, 250, 100);
points[11] = new animation_ch16_Point3D(-150, 250, 100);
for(var i:uint = 0; i < numPoints; i++)
{
points[i].setVanishingPoint(vpX, vpY);
points[i].setCenter(0, 0, 200);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
var angleX:Number = (mouseY - vpY) * .001;
var angleY:Number = (mouseX - vpX) * .001;
for(var i:uint = 0; i < numPoints; i++)
{
var point:animation_ch16_Point3D = points[i];
point.rotateX(angleX);
point.rotateY(angleY);
}
graphics.clear();
graphics.lineStyle(0);
graphics.moveTo(points[0].screenX, points[0].screenY);
for(i = 1; i < numPoints; i++)
{
graphics.lineTo(points[i].screenX, points[i].screenY);
}
graphics.lineTo(points[0].screenX, points[0].screenY);
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.