package { import away3d.cameras.HoverCamera3D; import away3d.cameras.TargetCamera3D; import away3d.containers.View3D; import away3d.core.base.Object3D; import away3d.events.MouseEvent3D; import away3d.primitives.Cone; import away3d.primitives.Cube; import away3d.primitives.Sphere; import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; [SWF(width="500", height="400", frameRate="50", backgroundColor="#FFFFFF")] public class Basic08_sphere extends Sprite { private var cam:HoverCamera3D; private var lastKey:uint; private var keyIsDown:Boolean = false; private var View:View3D; private var cover:Cover; private var sphere:Sphere; /** * The following 2 lines are how graphics are embedded using Flex. * If you are using the Flash IDE, simply remove the next two * lines of code, import the image to your library and set it to * export with the class name "texture". **/ [Embed(source="resources/panoramaSpherical.jpg")] private var texture:Class; public function Basic08_sphere() { // create a "hovering" camera cam = new HoverCamera3D(); cam.z = -1000; // make sure the camera is positioned away from the default 0,0,0 coordinate cam.panangle = 0; cam.tiltangle = 0; cam.targetpanangle = 0; cam.targettiltangle = 0; cam.mintiltangle = -90; cam.zoom = 4; // create a viewport View = new View3D({camera:cam,x:250,y:200}); addChild(View); // add a huge surrounding sphere so we really can see what we're doing var largeSphere:Sphere = new Sphere({radius:1500,material:texture,segmentsW:14,segmentsH:28}); //largeSphere.invertFaces(); // This one is buggy at the moment, so use scaleX = -1 instead. largeSphere.scaleX = -1; View.scene.addChild(largeSphere); // update the view cam.hover(); View.render(); // only run when user is above the SWF cover = new Cover(this,500,400,"Roll over and Click to activate. Use S, W and arrow keys to navigate"); addChild(cover); // listen for key events and run every frame this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown); this.stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp); this.addEventListener(Event.ENTER_FRAME,onEnterFrame); } private function onEnterFrame(e:Event):void { if(!cover.visible) { if(keyIsDown){ // if the key is still pressed, just keep on moving switch(lastKey){ case Keyboard.UP : cam.targettiltangle -= 5; break; case Keyboard.DOWN : cam.targettiltangle += 5; break; case 87 : cam.zoom += 0.3; break; case 83 : if(cam.zoom > 1.4){cam.zoom -= 0.3}; break; case Keyboard.LEFT : cam.targetpanangle -= 5; break; case Keyboard.RIGHT : cam.targetpanangle += 5; break; } } // render the view cam.hover(); View.render(); } } private function onKeyDown(e:KeyboardEvent):void { lastKey = e.keyCode; keyIsDown = true; } private function onKeyUp(e:KeyboardEvent):void { keyIsDown = false; } } }