package { import alternativa.engine3d.core.Object3D; import alternativa.engine3d.materials.*; import alternativa.engine3d.primitives.*; import alternativa.types.Point3D; import alternativa.utils.FPS; import flash.display.*; import flash.events.*; import flash.utils.*; import jp.clockmaker.alternativa3d.BasicTemplate; [SWF(width = 720, height = 480, frameRate = 60)] /** * @author Yasu (clockmaker.jp) */ public class Tentacle extends BasicTemplate { [Embed(source = 'imgs/alternativa3d_big.png')] private const LOGO_IMAGE:Class; // Const Vars static private const ROT_NUM :uint = 10; static private const CHILDREN_NUM :uint = 16; private var higes:Array = []; /** * 初期化されたときに実行されるイベントです。 * 初期化時に実行したい処理をオーバーライドして記述します。 */ override protected function atInit():void { stage.quality = StageQuality.LOW; graphics.beginFill(0x001122); graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); // create 3d objects for (var i:int = 0; i < ROT_NUM; i++) { var hige:Object3D = new Object3D(); scene.root.addChild(hige); hige.rotationY = i * 360 / ROT_NUM * Math.PI / 180; var distance:Number = 100; for (var j:int = 0; j < CHILDREN_NUM; j++) { var box:Sphere = Sphere(hige.addChild(new Sphere(50, 3, 2))); box.cloneMaterialToAllSurfaces(new WireMaterial(1, 0xFF0000 + 0x001000 * j)); box.scaleX = box.scaleY = box.scaleZ = 1 - 1 / CHILDREN_NUM * j; distance += 150 * box.scaleX; box.z = distance; hige.addChild(box); if (higes[j] == null) higes[j] = []; higes[j][i] = box } } // debug FPS.init(this); // logo addChild(new LOGO_IMAGE); // mouse interactive stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); } /** * Event.ENTER_FRAME 時に実行されるレンダリングのイベントです。 * レンダリング前に実行したい処理をオーバーライドして記述します。 */ override protected function atPreRender():void { // Hige Animation for (var j:int = 0; j < higes.length; j++) { for (var i:int = 0; i < higes[j].length; i++) { var rot:Number = getTimer() / 1000 + 100 * i; higes[j][i].x = Math.sin(rot) * 30 * j higes[j][i].y = Math.cos(rot) * 10 * j } } // Mouse Interactive easePitch += (cameraPitch - easePitch) * 0.2 easeYaw += (cameraYaw - easeYaw) * 0.2 camera.x = 1000 * Math.sin(easeYaw * Math.PI / 180); camera.y = 1000 * Math.cos(easeYaw * Math.PI / 180); //camera.rotationY = -cameraPitch camera.z += (1000 * Math.cos(cameraPitch * Math.PI / 180) - camera.z )* .1; cameraContoller.lookAt(new Point3D()); } // ---------------------------------------------- // Mouse Interactive // ---------------------------------------------- private var isOribiting:Boolean; private var cameraPitch:Number = 90; private var cameraYaw:Number = 270; private var previousMouseX:Number; private var previousMouseY:Number; private var easePitch:Number = 90; private var easeYaw:Number = 270; private function onMouseDown(event:MouseEvent):void { isOribiting = true; previousMouseX = event.stageX; previousMouseY = event.stageY; } private function onMouseUp(event:MouseEvent):void { isOribiting = false; } private function onMouseMove(event:MouseEvent):void { var differenceX:Number = event.stageX - previousMouseX; var differenceY:Number = event.stageY - previousMouseY; if(isOribiting) { cameraPitch += differenceY * 0.25; cameraYaw += differenceX * 0.25; cameraPitch %= 360; cameraPitch = cameraPitch > 0 ? cameraPitch : 0.0001; cameraPitch = cameraPitch < 180 ? cameraPitch : 179.9999; previousMouseX = event.stageX; previousMouseY = event.stageY; } } } }