0

単純なベクトル回転を行いたい。

目標は、現在方向 d のターゲット t を指している一人称カメラを、新しい方向 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 に同じ速度で移動させるにはどうすればよいですか?

4

1 に答える 1

0

あなたのコードはかなり堅実に見えます。_flyViewingSpeed または rotationSpeed はまったく変更されますか?

別のアプローチは、まさにあなたがしようとしていることを行う Vector3.Lerp() を使用することです。ただし、現在の方向ではなく、最初の開始方向と目標方向を使用する必要があることに注意してください。そうしないと、さまざまな速度変化が発生します。

また、距離 (通常はポイントに使用されます) を使用する代わりに、方向の距離のようなものである Vector3.Dot() を使用します。また、Distance() よりも高速である必要があります。

お役に立てれば。

于 2012-10-09T13:12:58.110 に答える