1

XNA でフライト シミュレータ プログラム (Star fox 64 に類似) を作成していますが、ローテーションに問題があります。私の考えは、速度のベクトルと位置のベクトルを持つことです。私が許可しているコントロールは、オイラーの角度が問題を引き起こすようにするため、クォータニオンを使用したいと考えています。

私はまだグラフィックスのレンダリングにあまり慣れていませんが、Quaternion.createFromAxisAngle(vector, roll) (ロールは速度ベクトルの周りの回転です) を使用できると思っていましたが、正しく機能していません。基本的に、ピッチまたはヨーを回転させようとしても何も起こりません。ロールすると機能しますが、期待したほどではありません。これは createFromAxisAngle メソッドの正しい使い方ですか? ありがとう。

これが私の船の更新位置コードです:

    public override void UpdatePositions()
    {
        float sinRoll = (float)Math.Sin(roll);
        float cosRoll = (float)Math.Cos(roll);
        float sinPitch = (float)Math.Sin(pitch);
        float cosPitch = (float)Math.Cos(pitch);
        float sinYaw = (float)Math.Sin(yaw);
        float cosYaw = (float)Math.Cos(yaw);

        m_Velocity.X = (sinRoll * sinPitch - sinRoll * sinYaw * cosPitch - sinYaw * cosPitch);
        m_Velocity.Y = sinPitch * cosRoll;
        m_Velocity.Z = (sinRoll * sinPitch + sinRoll * cosYaw * cosPitch + cosYaw * cosPitch);
        if (m_Velocity.X == 0 && m_Velocity.Y == 0 && m_Velocity.Z == 0)
            m_Velocity = new Vector3(0f,0f,1f);
        m_Rotation = new Vector3((float)pitch, (float)yaw, (float)roll);

        m_Velocity.Normalize();
        //m_QRotation = Quaternion.CreateFromYawPitchRoll((float)yaw,(float)pitch,(float)roll); This line works for the most part but doesn't allow you to pitch up correctly while banking.
        m_QRotation = Quaternion.CreateFromAxisAngle(m_Velocity,(float)roll);
        m_Velocity = Vector3.Multiply(m_Velocity, shipSpeed);

        m_Position += m_Velocity;
    }
4

2 に答える 2

2

XNA を使用して 3D で回転させたいですか? 次に、これを読んでください:http://stevehazen.wordpress.com/2010/02/15/matrix-basics-how-to-step-away-from-storing-an-orientation-as-3-angles/

十分にお勧めできません。

于 2011-08-04T11:31:09.223 に答える
2

船の向きをヨー、ピッチ、ロールの変数として保存することに固執していますか? そうでない場合は、方向をクォータニオンまたはマトリックスに保存すると、ここでの課題が大幅に簡素化されます。

フレームの最後に、effect.World を送信します。これは、船のワールド空間の向きと位置を表すマトリックスです。そのマトリックスの forward プロパティは、たまたまここで速度として計算したベクトルと同じです。そのマトリックスを effect.World から保存しないのはなぜですか。次のフレームでは、そのマトリックスをそれ自体の前方ベクトル (ロール用) を中心に単純に回転させ、それ自体 (前方プロパティ * shipSpeed) に基づいてその Translation プロパティを進め、それを次のフレームの効果。これにより、船の実際のヨー角、ピッチ角、ロール角を「知る」ことができなくなります。しかし、ほとんどの場合、3D プログラミングでは、何かの角度を知る必要があると考える場合、おそらく間違った方法で取り組んでいます。

必要に応じて、マトリックスを使用してこの方向に進むためのスニペットを次に示します。

//class scope field
Matrix orientation = Matrix.Identity;


//in the update
Matrix changesThisFrame = Matrix.Identity;

//for yaw
changesThisFrame *= Matrix.CreatFromAxisAngle(orientation.Up, inputtedYawAmount);//consider tempering the inputted amounts by time since last update.

//for pitch
changesThisFrame *= Matrix.CreateFromAxisAngle(orientation.Right, inputtedPitchAmount);

//for roll
changesThisFrame *= Matrix.CreateFromAxisAngle(orientation.Forward, inputtedRollAmount);

orientation *= changesThisFrame;

orientation.Translation += orientation.Forward * shipSpeed;


//then, somewhere in the ship's draw call

effect.World = orientation;
于 2011-08-03T20:12:54.797 に答える