查看: 2213|回复: 0
打印 上一主题 下一主题

[pv3d专题]弹性摄影机

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-3-21 14:49:19 |只看该作者 |倒序浏览
package  
{
import flash.display.Stage;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
import org.papervision3d.cameras.SpringCamera3D;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.special.CompositeMaterial;
import org.papervision3d.objects.primitives.PaperPlane;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;

/**
  * ...
  * @author 张首尚
  */
public class vb3 extends BasicView
{
  private var ppaperPlane;
  private var left:Boolean;
  private var right:Boolean;
  private var forWard:Boolean;
  private var backWard:Boolean;
  private var qWard:Boolean;
  private var eWard:Boolean;
  
  private var camer:SpringCamera3D;
  public function vb3(_stage:Stage)
  {
   super(640, 480,***e,false,CameraType.SPRING);
   init(_stage);
  }
  
  private function init(_stage:Stage):void
  {
   camer = SpringCamera3D(this.camera);
   camer.useCulling = ***e;
   camer.mass = 20;
   camer.damping = 4;
   camer.stiffness = 1;
   camer.positionOffset = new Number3D(0, -150, -150);
   camer.lookOffset = new Number3D(0,0,100);
   
   var cm:CompositeMaterial = new CompositeMaterial();
   cm.addMaterial(new ColorMaterial(0xFF33FF));
   cm.addMaterial(new WireframeMaterial(0xEEEEEE));
   cm.doubleSided = ***e;
   pp = new PaperPlane(cm);
   scene.addChild(pp);
   pp.y = 250;
   pp.z = -10;
   _stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey_Down);
   _stage.addEventListener(KeyboardEvent.KEY_UP, onKey_Up);
   
   /*camer.target = pp;*/
   this.startRendering();
  }
  
  private function onKey_Down(evt:KeyboardEvent):void
  {
   switch(evt.keyCode)
   {
    case "W".charCodeAt():
    case Keyboard.UP:
     forWard = ***e;
     break;
    case "S".charCodeAt():
    case Keyboard.DOWN:
     backWard = ***e;
     break;
    case "A".charCodeAt():
    case Keyboard.LEFT:
     left = ***e;
     break;
    case "D".charCodeAt():
    case Keyboard.RIGHT:
     right = ***e;
     break;
    case "Q".charCodeAt():
     qWard = ***e;
     break;
    case "E".charCodeAt():
     eWard = ***e;
     break;
   }
  }
  
  private function onKey_Up(evt:KeyboardEvent):void
  {
   switch(evt.keyCode)
   {
    case "W".charCodeAt():
    case Keyboard.UP:
     forWard = false;
     break;
    case "S".charCodeAt():
    case Keyboard.DOWN:
     backWard = false;
     break;
    case "A".charCodeAt():
    case Keyboard.LEFT:
     left = false;
     break;
    case "D".charCodeAt():
    case Keyboard.RIGHT:
     right = false;
     break;
    case "Q".charCodeAt():
     qWard = false;
     break;
    case "E".charCodeAt():
     eWard = false;
     break;
   }
  }
  
  private function moveObject():void
  {
   if (this.forWard) {
    pp.moveForward(30);
   }else if (this.backWard) {
    pp.moveBackward(30);
   }
   
   if (this.left) {
    pp.localRotationY -= 2;
   }else if (this.right) {
    pp.localRotationY += 2;
   }
   
   if (qWard) {
    pp.localRotationX -= 2;
   }else if(eWard) {
    pp.localRotationX += 2;
   }
  }
  override protected function onRenderTick(e:Event=null):void
  {
   super.onRenderTick();
   moveObject();
   camer.lookAt(pp);
  }
  
}
}
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-10 15:49 , Processed in 0.105292 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部