2010-03-08 58 views
0

我想在移動相機時讓對象保持在相同的位置。Papervision3D:在移動相機時使對象仍然顯示

我正在使用此腳本http://pv3d.org/2008/11/19/dragging-mouse-for-camera-orbit/使用鼠標拖動使物體運行。但我在場景中有一個我想保持不動的對象。我如何做到這一點?

謝謝, 喬希

+0

你還是什麼意思?您希望對象在視圖更改時保留在視野中的相同位置? – CookieOfFortune 2010-03-08 16:14:16

+0

@CookieOfFortune - 是的沒錯。 – Josh 2010-03-08 16:33:04

回答

2

好的,我通過在Papervision的Camera3D源瀏覽。這裏是軌道實現:

  /** 
      * Orbits the camera around the specified target. If no target is specified the 
      * camera's #target property is used. If this camera's #target property equals null 
      * the camera orbits the origin (0, 0, 0). 
      * 
      * @param  pitch Rotation around X=axis (looking up or down). 
      * @param  yaw    Rotation around Y-axis (looking left or right). 
      * @param  useDegrees  Whether to use degrees for pitch and yaw (defaults to 'true'). 
      * @param  target An optional target to orbit around. 
      */ 
      public override function orbit(pitch:Number, yaw:Number, useDegrees:Boolean=true, target:DisplayObject3D=null):void 
      { 
        target = target || _target; 
        target = target || DisplayObject3D.ZERO; 

        if(useDegrees) 
        { 
          pitch *= (Math.PI/180); 
          yaw *= (Math.PI/180); 
        } 

        // Number3D.sub 
        var dx     :Number = target.world.n14 - this.x; 
        var dy     :Number = target.world.n24 - this.y; 
        var dz     :Number = target.world.n34 - this.z; 

        // Number3D.modulo 
        var distance :Number = Math.sqrt(dx*dx+dy*dy+dz*dz); 

        // Rotations 
        var rx :Number = Math.cos(yaw) * Math.sin(pitch); 
        var rz :Number = Math.sin(yaw) * Math.sin(pitch); 
        var ry :Number = Math.cos(pitch); 

        // Move to specified location 
        this.x = target.world.n14 + (rx * distance); 
        this.y = target.world.n24 + (ry * distance); 
        this.z = target.world.n34 + (rz * distance); 

        this.lookAt(target); 
      } 

您可以實現此作爲要保持靜止對象的輔助功能。我相信這個函數中涉及的唯一相機特定的代碼是lookAt()函數。

然後,您可以在mouseMove處理程序中的camera.orbit()之前添加它,並且它應該與您的相機保持靜止。