away3D操纵三维物体之旋转的球体实例
/*在fb下新建as项目运行此实例*/
HelloWorld.as
package{import flash.events.Event;import flash.display.Sprite;import flash.utils.getTimer;import away3d.core.base.*; //核心库import away3d.core.math.*; //数学对象import away3d.containers.*; //容器库import away3d.primitives.*; //几何体库public class HelloWorld extends Sprite{private var view:View3D; //声明一个3D视口private var sphere:Object3D; //声明一个球体对象public function HelloWorld(){view = new View3D({x:250, y:250}); //实例化视口(属性X\Y为视口的坐标值)this.addChild(view); //将视口添加到场景//实例化球体对象(属性依次为:材质(球体颜色#线框颜色)、半径、横向分段、纵向分段、Y\X\Z的坐标值)sphere = new Sphere({material:"#0000FF", radius:200, segmentsW:20, segmentsH:30, y:50, x:20, z:30});view.scene.addChild(sphere); //将球体添加到场景view.camera.position = new Number3D(1000, 1000, 1500); //设置摄像机的镜头位置(X\Y\Z)view.camera.lookAt(sphere.position);this.addEventListener(Event.ENTER_FRAME, onMyEnterFrame);}private function onMyEnterFrame(event:Event):void{sphere.rotationY = getTimer() / 100; //让球体沿着Y轴旋转,其值就是此球体的转速view.render(); //渲染视窗}}}