package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; 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 ExPanoramaSpherical extends Sprite { private var cam:HoverCamera3D; private var lastKey:uint; private var keyIsDown:Boolean = false; public var view:View3D; /** * 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 ExPanoramaSpherical() { // 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.hover(true); 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); // 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,update); } public function update(e:Event):void { if(keyIsDown){ // if the key is still pressed, just keep on moving switch(lastKey){ case Keyboard.UP : cam.tiltAngle -= 5; break; case Keyboard.DOWN : cam.tiltAngle += 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.panAngle -= 5; break; case Keyboard.RIGHT : cam.panAngle += 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; } } }