Alternativa3D学习笔记之HelloWorld
来源:互联网 发布:linux top怎么退出 编辑:程序博客网 时间:2024/04/30 09:26
A3D的基本元素有3D舞台Stage3D,3D摄像机Camera3D,摄像机的视图View,3D显示对象Object3D和材质Material。另外,程序中所有的显示对象必须加到一个根容器rootContainer上,其本质上是一个Object3D。要想让场景响应鼠标和键盘事件,以控制摄像机,我们可以声明一个简单控制器SimpleObjectContainer,当然这个控制器并不好用,我们可以在以后自己创建一个控制器。
A3D基本框架:
1、设置舞台的缩放模式、帧率、对齐方式等,不是必须,但只有设置了舞台的缩放模式舞台才能正确响应大小改变事件。
2、初始化根容器。
3、初始化摄像机和摄像机视图,把视图加到显示列表,把摄像机加到根容器。
4、为摄像机初创建一个控制器,不是必须。
5、初始化舞台。
6、context3D预设定。
7、初始化Context3D事件,加载资源,注册帧事件。
8、在帧事件里渲染3D舞台,如果要响应鼠标或键盘事件,刷新控制器。
下面是A3D的HelloWorld程序:
public class HelloBasic extends Sprite{//舞台private var stage3D:Stage3D;//摄像机private var camera3D:Camera3D;//显示对象根结点private var rootContainer:Object3D;//摄像机控制器private var controller:SimpleObjectController;//3D显示对象private var box:Object3D;public function HelloBasic(){//(1)舞台属性this.stage.frameRate=60;this.stage.scaleMode=StageScaleMode.NO_BORDER;this.stage.align=StageAlign.TOP_LEFT;//(2)初始化根显示对象this.rootContainer=new Object3D();//(3)初始化摄像机this.camera3D=new Camera3D(1,10000);this.camera3D.x=-150;this.camera3D.y=100;this.camera3D.z=-50;this.camera3D.view=new View(this.stage.stageWidth,this.stage.stageHeight,false,0x000000,0.1,4);//摄像机视图必须加到显示列表this.addChild(this.camera3D.view);//将摄像机添加到根结点this.rootContainer.addChild(this.camera3D);//(4)初始化摄像机控制器this.controller=new SimpleObjectController(stage,camera3D,100,1,0.1);controller.lookAtXYZ(0,0,0);//初始化一个方盒var box:Box=new Box();box.setMaterialToAllSurfaces(new FillMaterial(0x804080));rootContainer.addChild(box);//(5)初始化3D舞台this.stage3D=this.stage.stage3Ds[0];//(6)context3D预设定this.stage3D.addEventListener(Event.CONTEXT3D_CREATE,initContext3D);this.stage3D.requestContext3D();}//(7)初始化Context3D事件private function initContext3D(event:Event):void {//加载资源for each(var resource:Resource in rootContainer.getResources(true)){resource.upload(stage3D.context3D);}//添加帧事件this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);}private function enterFrameHandler(event:Event):void {camera3D.render(stage3D);//为了监听鼠标和键盘事件,实时更新控制器controller.update();}}
0 0
- Alternativa3D学习笔记之HelloWorld
- ActiveMQ学习笔记之HelloWorld
- Spring学习笔记之HelloWorld
- Python学习笔记之HelloWorld
- VC++学习笔记之HelloWorld
- Servlet学习笔记之---HelloWorld
- ActiveMQ学习笔记之HelloWorld
- 《Spring In Action》学习笔记之HelloWorld
- Android学习笔记之二-----HelloWorld
- OpenMPI学习笔记(二)之helloWorld
- 学习笔记:Servlet基础之HelloWorld
- 学习笔记之Spring入门HelloWorld
- JAVA学习笔记之(一)HelloWorld
- 3、netty 之HelloWorld(netty学习笔记)
- mybatis学习笔记(零)mybatis学习之HelloWorld
- C#学习笔记:HelloWorld
- 《QML HelloWorld》学习笔记
- SpringBoot学习笔记--HelloWorld
- yum和apt-get的区别
- 无人机光电系统图像处理模块AVT22
- Day3: Meeting friend in Beijing
- 安装AndroidStudio
- Java中Vector、List、Set集合、Iterator迭代器的使用
- Alternativa3D学习笔记之HelloWorld
- Android 高版本API方法在低版本系统上的兼容性处理
- cornerstone创建分支与合并代码方法整理
- mac系统如何显示和隐藏文件 和 删除SVN隐藏文件
- Sql Server 具有可更新订阅的事务发布-业务升级
- 机器学习之 特征选择
- Jquery
- NumPy简明教程(二、数组1)
- jni的两种方式