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;
}