2012-10-09 159 views
0

我想做一个简单的矢量旋转。旋转矢量

目标是领导我的第一人称摄像机,它正在指向目标t方向d到新方向d1的新目标t1。

d和d1之间的过渡应该是一个平滑的运动。

随着

public void FlyLookTo(Vector3 target) { 

     _flyTargetDirection = target - _cameraPosition; 
     _flyTargetDirection.Normalize(); 

     _rotation = new Matrix(); 

     _rotationAxis = Vector3.Cross(Direction, _flyTargetDirection); 

     // This bool tells the Update()-method to trigger the changeDirection() method. 
     _isLooking = true; 
    } 

我开始与它的新参数的方向变化和

// this method gets executed by the Update()-method if the isLooking flag is up. 
private void _changeDirection() { 

     dist = Vector3.Distance(Direction, _flyTargetDirection); 

     // check whether we have reached the desired direction 
     if (dist >= 0.00001f) { 

      _rotationAxis = Vector3.Cross(Direction, _flyTargetDirection); 
      _rotation = Matrix.CreateFromAxisAngle(_rotationAxis, MathHelper.ToRadians(_flyViewingSpeed - Math.ToRadians(rotationSpeed))); 


      // update the cameras direction. 
      Direction = Vector3.TransformNormal(Direction, _rotation); 
     } else { 

      _onDirectionReached(); 
      _isLooking = false; 
     } 
    } 

我执行实际的运动。

我的问题:实际运行工作正常,但移动速度减慢更多的电流方向越接近所期望的方向,如果连续执行数次,这使得它非常不愉快的运动。

如何使相机以相同的速度从方向d移动到方向d1?

+0

看到我的答案在这里:http://gamedev.stackexchange.com/questions/38594/rotate-a-vector和在这里:http://stackoverflow.com/questions/12797811/rotation-axis-to-perform-回转 –

回答

0

你的代码看起来很稳固。 _flyViewingSpeed或rotationSpeed是否完全改变?

另一种方法是使用Vector3.Lerp(),它将完成你想要做的事情。但是请注意,您需要使用初始开始和目标方向 - 而不是当前方向 - 否则您将获得不同的速度变化。

此外,而不是使用距离(通常用于点),我会使用Vector3.Dot()这是有点像距离的方向。它也应该比Distance()更快。

希望这有助于。