纳金网

标题: [pv3d专题]弹性摄影机 [打印本页]

作者: .    时间: 2013-3-21 14:49
标题: [pv3d专题]弹性摄影机
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/




欢迎光临 纳金网 (http://rs.narkii.com/club/) Powered by Discuz! X2.5