papervision3d学习笔记:简单的摄影机

<textarea cols="50" rows="15" name="code" class="java">package { import flash.display.DisplayObject; import flash.display.Sprite; import flash.events.*; import flash.ui.Keyboard; import org.papervision3d.cameras.Camera3D; import org.papervision3d.scenes.Scene3D; import org.papervision3d.materials.*; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.view.Viewport3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.objects.primitives.*; import org.papervision3d.materials.utils.MaterialsList; public class Example3 extends Sprite { private var objet:DisplayObject3D = new DisplayObject3D(); private var viewport:Viewport3D=new Viewport3D(550,400);//视窗 private var renderer:BasicRenderEngine= new BasicRenderEngine();//创建渲染器 private var camera:Camera3D= new Camera3D();//创建摄影机 private var cude:Cube = new Cube(new MaterialsList({all:new BitmapFileMaterial('map.jpg')}),200,200,200);//创建一个立方体,并且进行贴图 //private var cude:Sphere = new Sphere(new BitmapFileMaterial('map.jpg'),200, 24, 24); private var sence:Scene3D = new Scene3D();//创建一个三维场景 public function Example3() { init3D();//初始化3d } private function init3D():void { addChild(viewport);//添加视窗到显示列表 camera.z =-500; sence.addChild(cude);//场景添加立方体 addEventListener(Event.ENTER_FRAME, Run); stage.addEventListener(KeyboardEvent.KEY_DOWN, onkeyDown); } private function Run(event:Event):void { cude.rotationX += 1;//以x轴自转 cude.rotationY += 1;//以y轴自转 renderer.renderScene(sence, camera, viewport);//渲染模型 } private function onkeyDown(event:KeyboardEvent):void { if (event.keyCode==Keyboard.UP) { camera.zoom+=1;//放大 } if (event.keyCode==Keyboard.DOWN) { camera.zoom-=1//缩放 } } } }</textarea>

 

通过这个简单的代码,我们使用键盘进行简单控制,实现摄影机移动。达到一种放大缩小的状况。

 

private var camera:Camera3D= new Camera3D();//创建摄影机

 

下面是通过键盘进行交互,实现摄像机进行交互。

 

<textarea cols="50" rows="15" name="code" class="java">private function onkeyDown(event:KeyboardEvent):void { if (event.keyCode==Keyboard.UP) { camera.zoom+=1;//放大 } if (event.keyCode==Keyboard.DOWN) { camera.zoom-=1//缩放 } }</textarea>

 

 

你可能感兴趣的:(papervision3d学习笔记:简单的摄影机)