package { import PaperBase; import org.papervision3d.materials.*; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.parsers.Collada; import caurina.transitions.Tweener; import flash.events.MouseEvent; import flash.display.*; public class Flight extends PaperBase { public var tank:DisplayObject3D; public var top:DisplayObject3D; public var bottom:DisplayObject3D; public var zoom:Boolean = false; // private var trans:String = "easeOutBounce"; private var trans:String = "easeInOutQuad"; public function Flight() { var rect:Shape = new Shape(); rect.graphics.beginFill(0x666666, 1); rect.graphics.drawRect(0, 0, 150, 150); //addChild(rect); stage.addEventListener(MouseEvent.MOUSE_DOWN, function(){zoom = true}); stage.addEventListener(MouseEvent.MOUSE_UP, function(){zoom = false}); //this.parent.parent["btReset"].visible = false; btReset.visible = false; btFly.visible = false; btReset.addEventListener(MouseEvent.CLICK, reset); btFly.addEventListener(MouseEvent.CLICK, fly); //addEventListener(MouseEvent.MOUSE_DOWN, zoom); init(); } override protected function init3d():void { //tank = new DisplayObject3D(); // top = new Collada("tank-top.dae"); tank = new Collada("helicopter.dae"); // var tanktop = tank.addChild(top); // tank.addChild(top); default_scene.addChild(tank); tank.rotationX -= 90; tank.rotationY -= 30; //tank.rotationZ += 30; tank.x = -200; tank.y = 50; trace(tank.rotationX); trace(tank.rotationY); trace(tank.rotationZ); trace(tank.x); trace(tank.y); trace(tank.z); btReset.visible = true; btFly.visible = true; // fly(); //tank = new Collada("tank-top.dae"); //tank = new Collada("3dm-M1_Abrams/M1_Abrams.dae"); //top.moveDown(100); /* top.z = -28; tank.moveDown(100); tank.scale = 8; tank.rotationZ += 15; */ /* car.moveDown(100); car.scale = 8; car.rotationX -= 90; car.x = -275; car.y = 400; car.z = 400; */ /* //default_scene.addChild(car); //tank.z += 200; tank.x = -275; tank.y = 200; tank.z = 400; */ //Tweener.addTween(tank, { x:1000, z:1000, time:2, onComplete: randomize, transition : trans } ); } private function reset(evt=null){ tank.rotationX = -90; tank.rotationY = -30; tank.rotationZ = 0; tank.x = -200; tank.y = 50; tank.z = 0; } private function fly(evt=null){ var x = tank.x; var y = tank.y; var z = tank.z; var rX = tank.rotationX; var rY = tank.rotationY; var rZ = tank.rotationZ; x -= 20; y += 50; rZ += 5; Tweener.addTween(tank, { x:x, y:y, z:z, rotationX:rX, rotationY:rY, rotationZ:rZ, time:1, delay:0, transition : trans } ); x += 70; y += 100; rZ -= 20; Tweener.addTween(tank, { x:x, y:y, z:z, rotationX:rX, rotationY:rY, rotationZ:rZ, time:1.5, delay:1, transition : trans } ); x += 1000; y += 40; rY += 180; rZ = 40; Tweener.addTween(tank, { x:x, y:y, z:z, rotationX:rX, rotationY:rY, rotationZ:rZ, time:2, delay:2.5, transition : trans } ); z -= 400; x -= 1000; rY += 140; rZ -= 40; Tweener.addTween(tank, { x:x, y:y, z:z, rotationX:rX, rotationY:rY, rotationZ:rZ, time:2, delay:4.5, transition : trans } ); z += 2800; y += 400; rY -= 25; //rZ -= 40; Tweener.addTween(tank, { x:x, y:y, z:z, rotationX:rX, rotationY:rY, rotationZ:rZ, time:2, delay:6.5, transition : trans } ); } override protected function processFrame():void { //top.rotationZ -= 5; //rotate(null); //default_camera.lookAt(tank); } public function rotate(e){ var rotationY = (stage.width / 2) + mouseX; var rotationX = (stage.height / 2) - mouseY; var z = ((stage.height / 2) - mouseY ) *10; var x = ((stage.height / 2) - mouseX ) * 10; if(zoom){ //trace("z "+z); Tweener.addTween(tank, { z:z, x:x, time:2, delay:0, transition : trans} ); } else{ //Tweener.addTween(tank, { rotationX:rotationX, rotationY:rotationY, time:2, delay:0, transition : trans } ); Tweener.addTween(tank, { rotationY:rotationY, time:2, delay:0, transition : trans } ); } } public function zoomout(e){ var z = (stage.height / 2) - mouseY; Tweener.addTween(tank, { z:z, time:2, delay:0, transition : trans } ); } public function randomize():void { var xp:Number = (Math.random() * 2000) - 1000; var yp:Number = (Math.random() * 2000) - 1000; var yrX:Number = (Math.random() * 360) - 180; var yrY:Number = (Math.random() * 360) - 180; trace(xp+" : "+yp); Tweener.addTween(tank, { x:xp, z:yp, time:2, delay:2, rotationX:yrX, rotationY:yrY, onComplete: randomize, transition : trans } ); } public function get flipAmount():Number { return tank.rotationY; } public function set flipAmount(a:Number):void { tank.rotationY = a; } } }