- 最后登录
- 2013-9-29
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 6371
- 纳金币
- 6372
- 精华
- 0
|
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 objetisplayObject3D = 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//缩放
}
}
}
}
通过这个简单的代码,我们使用键盘进行简单控制,实现摄影机移动。达到一种放大缩小的状况。
private var camera:Camera3D= new Camera3D();//创建摄影机
下面是通过键盘进行交互,实现摄像机进行交互。
private function onkeyDown(event:KeyboardEvent):void
{
if (event.keyCode==Keyboard.UP)
{
camera.zoom+=1;//放大
}
if (event.keyCode==Keyboard.DOWN)
{
camera.zoom-=1//缩放
}
}
private function onkeyDown(event:KeyboardEvent):void
{
if (event.keyCode==Keyboard.UP)
{
camera.zoom+=1;//放大
}
if (event.keyCode==Keyboard.DOWN)
{
camera.zoom-=1//缩放
}
}
|
|