/** * ... * @author ever5u */ public class fuxi extends Sprite { private var scene:Scene3D; private var camera:Camera3D; public function fuxi() { //創(chuàng)建一個攝像機 camera = new Camera3D(300, 300); camera.x = 100; camera.y = 100; camera.z = -300; camera.lookAt(0,0,0); //創(chuàng)建一個 Group var root:Group = createScene(); //創(chuàng)建場景 scene = new Scene3D( "scene", this, camera, root ); //創(chuàng)建實時偵聽 addEventListener( Event.ENTER_FRAME, enterFrameHandler ); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); } var box = new Box("box", 100, 100, 100); var Plane:Plane3D; public function createScene() { var g:Group = new Group();
//在場景畫一個坐標(biāo)定位點 Plane = new Plane3D("Texture", 300, 300); var myXLine:Line3D = new Line3D( "x-coord", new Point3D( -20, 0, 0), new Point3D( 20, 0, 0 )); var myYLine:Line3D = new Line3D( "y-coord", new Point3D(0, -20, 0), new Point3D( 0, 20, 0 )); var myZLine:Line3D = new Line3D( "z-coord", new Point3D(0, 0, -20), new Point3D( 0, 0, 20 ));
g.addChild(myXLine); g.addChild(myYLine); g.addChild(myZLine); g.addChild( box ); return g; } public function enterFrameHandler(_evt:Event) { box.rotateX = mouseX; box.rotateY = mouseY; scene.render(); } public function keyPressed(_evt:KeyboardEvent):void { switch(_evt.keyCode) { case Keyboard.UP: camera.tilt += 2; //camera.y -= 2; break; case Keyboard.DOWN: camera.tilt -= 2; //camera.y += 2; break; case Keyboard.RIGHT: camera.pan -= 2; //camera.x += 2; break; case Keyboard.LEFT: camera.pan += 2; //camera.x -= 2; break; case Keyboard.CONTROL: camera.roll += 2; break; case Keyboard.PAGE_DOWN: camera.z -= 5; break; case Keyboard.PAGE_UP: camera.z += 5; break; } } }