How to Create circular path animation
We will useĀ Lathe class , this class allows you to define extrusion on a circular path defining starting angle, ending angle, radius, rotation axis …
Download the classes lathe.zip
AS code:
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.ui.*;
import flash.geom.Point;
import sandy.core.Scene3D;
import sandy.core.scenegraph.Camera3D;
import sandy.core.scenegraph.Group;
import sandy.core.scenegraph.Shape3D;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.primitive.Box;
import sandy.primitive.Line3D;
import sandy.extrusion.Extrusion;
import sandy.extrusion.data.*;
import sandy.core.data.*;
public class Example046 extends Sprite {
private var scene:Scene3D;
private var camera:Camera3D;
private var c:Box;
private var ext:Extrusion;
public function Example046() {
camera = new Camera3D(stage.stageWidth, stage.stageHeight);
scene = new Scene3D("myScene", this, camera , new Group("root"));
var arrayElm:Array = new Array();
arrayElm[0] = new Point(0,-10); arrayElm[1] = new Point(0,10); arrayElm[2] = new Point(30,10); arrayElm[3] = new Point(30,0);
arrayElm[4] = new Point(20,0); arrayElm[5] = new Point(20,5); arrayElm[6] = new Point(10,5); arrayElm[7] = new Point(10,-10);
arrayElm[8] = new Point(0,-10);
var sectionElm:Polygon2D = new Polygon2D(arrayElm);
var lathe1:Lathe = new Lathe (new Vector, new Vector (1, 1, 1), new Vector (1, 0, 0), 0, 4, 0.05);
// create extrusion
ext = new Extrusion ("ext0", sectionElm, lathe1.toSections ());
ext.appearance = new Appearance (new ColorMaterial (0x990000, 1,
new MaterialAttributes (new LightAttributes( true, 0.1))));
ext.appearance.frontMaterial.lightingEnable = true;
ext.pan = -40;
ext.rotateX = -80;
ext.pan = -40;
ext.x = 20;
ext.z = -100;
scene.root.addChild(ext);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMovedHandler);
addEventListener(Event.ENTER_FRAME, render);
}
private function render(event:Event):void {
scene.render();
//ext.rotateX += 4;
}
private function mouseMovedHandler(event:MouseEvent):void {
//ext.pan=(event.stageX-550/2)/5;
//ext.tilt=(event.stageY-400/2)/20;
}
}
}
We start by defining a simple polygon2D that we want to extrude in a circular way:
var arrayElm:Array = new Array();
arrayElm[0] = new Point(0,-10); arrayElm[1] = new Point(0,10);
arrayElm[2] = new Point(30,10); arrayElm[3] = new Point(30,0);
arrayElm[4] = new Point(20,0); arrayElm[5] = new Point(20,5);
arrayElm[6] = new Point(10,5); arrayElm[7] = new Point(10,-10);
arrayElm[8] = new Point(0,-10);
var sectionElm:Polygon2D = new Polygon2D(arrayElm);
How to use the Lathe class
var lathe1:Lathe = new Lathe (new Vector, new Vector (1, 1, 1), new Vector (1, 0, 0), 0, 4, 0.05); Since there is not much to do, probably it's better to list here the parameters of the Lath class:* Generates circular, spiral or helix arc. @param center Arc center. @param axis Axis of revolution. @param reference A vector that specifies direction to count angle from. Must be non-collinear to axis. @param angle0 Start angle. @param angle1 End angle. @param step Angle step. @param radius0 Start radius. @param radius1 End radius. @param height0 Start height. @param height1 End height. @param scale0 Start scale. @param scale1 End scale. public function Lathe (center:Vector, axis:Vector, reference:Vector, angle0:Number = 0, angle1:Number = Math.PI, step:Number = 0.3, radius0:Number = 100, radius1:Number = 100, height0:Number = 0, height1:Number = 0, scale0:Number = 1, scale1:Number = 1)Now see your project :