package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; import away3d.primitives.GeodesicSphere; import away3d.primitives.Sphere; import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; [SWF(width="500", height="300", frameRate="50", backgroundColor="#FFFFFF")] public class ExGeodesicSphere extends Sprite { private var cam:HoverCamera3D; private var lastKey:uint; private var keyIsDown:Boolean = false; public var view:View3D; private var sphere:Sphere; private var geoSphere:GeodesicSphere; public function ExGeodesicSphere() { // 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 = 5; // create a viewport view = new View3D({camera:cam,x:250,y:150}); addChild(view); // add a huge surrounding sphere so we really can see what we're doing geoSphere = new GeodesicSphere({radius:200,material:"red#black",x:200}); geoSphere.fractures = 5; geoSphere.invertFaces(); view.scene.addChild(geoSphere); // a sphere with 756 faces sphere = new Sphere({radius:200,material:"red#black",x:-200,segmentsW:12,segmentsH:13}); sphere.invertFaces(); view.scene.addChild(sphere); // 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.LEFT : showLeft(); break; case Keyboard.RIGHT : showRight(); break; case Keyboard.SPACE : showBoth(); break; } } geoSphere.rotationX += 1; sphere.rotationX += 1; // render the view cam.hover(); view.render(); } private function showBoth():void { geoSphere.visible = true; sphere.visible = true; } private function showLeft():void { geoSphere.visible = true; sphere.visible = false; } private function showRight():void { geoSphere.visible = false; sphere.visible = true; } private function onKeyDown(e:KeyboardEvent):void { lastKey = e.keyCode; keyIsDown = true; } private function onKeyUp(e:KeyboardEvent):void { keyIsDown = false; } } }