旋转矢量

时间:2012-10-09 09:18:57

标签: c# vector xna camera rotation

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

我的目标是将我当前指向目标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?

1 个答案:

答案 0 :(得分:0)

你的代码看起来很稳固。 _flyViewingSpeed或者rotationSpeed会改变吗?

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

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

希望这会有所帮助。

相关问题