1、修改PaperBase基类,存贮新的相机、场景和视图区,然后重新渲染产生新的效果。因为,首先需要定义三个新的类成员属性:
public var
current_scene:Scene3D;//为实现3D键盘交互准备
public var
current_camera:CameraObject3D;//为实现3D键盘交互准备
public var
current_viewport:Viewport3D;//为实现3D键盘交互准备 |
然后修改initPapervision函数,把原来默认的场景、相机、视图区更改为这三个类属性:
current_camera = default_camera;
current_scene = default_scene;
current_viewport = viewport; |
用新的类成员变量重新渲染:
renderer.renderScene(current_scene,
current_camera, current_viewport); |
2、新建3D键盘交互类:MainKeyboardInteraction
在这类中我将使用Plane(平面类)加载外部图片贴图来实现3D键盘交互,并且设定使用键盘上的w、a、s、d这4个按键控制Plane的平移,旋转交互效果,代码如下:
package
{
import
PaperBase;
import
flash.events.KeyboardEvent;
import
org.papervision3d.cameras.FreeCamera3D;
import
org.papervision3d.objects.primitives.Plane;
import
org.papervision3d.materials.BitmapFileMaterial;
public class
MainKeyboardInteraction extends PaperBase {
public var wdown:Boolean = false;
public var adown:Boolean = false;
public var sdown:Boolean = false;
public var ddown:Boolean = false;
public var camera:FreeCamera3D;
public function MainKeyboardInteraction() {
init();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
public function onKeyDown( event:KeyboardEvent ):void {
switch(event.keyCode) {//w:87
a:65 s:83 d:68
case 87:
wdown = true;
break;
case 65:
adown = true;
break;
case 83:
sdown = true;
|