/** * ... * @author ever5u */ public class fuxi extends Sprite { private var scene:Scene3D; private var camera:Camera3D; public function fuxi() { //創(chuàng)建一個(gè)攝像機(jī) camera = new Camera3D(300, 300); camera.z = -300; //創(chuàng)建一個(gè) Group var root:Group = createScene(); //創(chuàng)建場景 scene = new Scene3D( "scene", this, camera, root ); //創(chuàng)建實(shí)時(shí)偵聽 addEventListener( Event.ENTER_FRAME, enterFrameHandler ); } var box = new Box("box", 100, 100, 100); public function createScene() { var g:Group = new Group(); //設(shè)置立方體的顏色、線條色和環(huán)境光 material.lightingEnable = true; var materialAttr:MaterialAttributes = new MaterialAttributes( new LineAttributes( 0.5, 0x000000, 0.4 ), new LightAttributes( true, 0.2) ); var material:Material = new ColorMaterial( 0xCC3300, 1, materialAttr ); var app:Appearance = new Appearance( material );
box.appearance = app;
g.addChild( box ); return g; } public function enterFrameHandler(_evt:Event) { box.rotateX = mouseX; box.rotateY = mouseY; scene.render(); } }