package { import alternativa.engine3d.controllers.CameraController; import alternativa.engine3d.core.Camera3D; import alternativa.engine3d.core.Object3D; import alternativa.engine3d.core.Scene3D; import alternativa.engine3d.display.View; import alternativa.engine3d.materials.Material; import alternativa.engine3d.materials.MovieClipMaterial; import alternativa.engine3d.materials.TextureMaterial; import alternativa.engine3d.materials.WireMaterial; import alternativa.engine3d.primitives.Box; import alternativa.engine3d.primitives.Cone; import alternativa.engine3d.primitives.Plane; import alternativa.engine3d.primitives.Sphere; import alternativa.utils.FPS; import flash.display.MovieClip; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; [SWF(backgroundColor="#000000", frameRate="100")] public class HelloAlternativa3D extends MovieClip{ private var scene:Scene3D; private var view:View; private var camera:Camera3D; private var cameraController:CameraController; private var box:Box; private var plane:Plane; private var cone:Cone; public function HelloAlternativa3D() { addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event): void { removeEventListener(Event.ADDED_TO_STAGE, init); stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; // Creating scene——建立场景 scene = new Scene3D(); scene.root = new Object3D(); box = new Box(100, 100, 100, 3, 3, 3); box.cloneMaterialToAllSurfaces(new WireMaterial(1, 0xFF80C0)); scene.root.addChild(box); plane = new Plane(800,800, 2, 2); var hello:MovieClip = new pic(); var shui1:shui = new shui(); shui1.width = 800; shui1.height = 600; plane.cloneMaterialToAllSurfaces(new MovieClipMaterial(hello,800,800)); scene.root.addChild(plane); cone = new Cone(800, 100, 0, 1, 12); cone.cloneMaterialToAllSurfaces(new WireMaterial(1, 0xFF8000)); this.addChild(shui1); scene.root.addChild(cone); // Adding camera and view——添加摄像机和视窗 camera = new Camera3D(); camera.x = 100; camera.y = -150; camera.z = 100; scene.root.addChild(camera); view = new View(); addChild(view); view.camera = camera; // Connecting camera controller——与“摄像机控制器”建立连接 cameraController = new CameraController(stage); cameraController.camera = camera; cameraController.setDefaultBindings(); cameraController.checkCollisions = true; cameraController.collisionRadius = 20; cameraController.lookAt(box.coords); cameraController.controlsEnabled = true; // FPS display launch——FPS 运转显示 FPS.init(stage); stage.addEventListener(Event.RESIZE, onResize); stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); onResize(null); } private function onResize(e:Event):void { view.width = stage.stageWidth; view.height = stage.stageHeight; } private function onEnterFrame(e:Event):void { // User input processing——控制器的输入过程 cameraController.processInput(); // Scene calculating——场景计算 scene.calculate(); } } }