私はXNAを初めて使い、単純なゲームを作成しています。申し訳ありませんが、これはおそらく本当に簡単ですが、私はそれについて助けを見つけることができません。ゲームにはBlenderで作った船があります。船のX、Y、Z軸を回転させることで船をコントロールしたいと考えています。私が持っているコードは次のとおりです。XNAで3Dモデルを回転
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
RotationMatrix = Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateRotationY (rotationY) * Matrix.CreateRotationX(rotationX) * Matrix.CreateRotationZ(rotationZ);
Matrix shipTransformMatrix = RotationMatrix * Matrix.CreateTranslation(ship.Position);
DrawModel(ship.Model, shipTransformMatrix, ship.Transforms);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
public void DrawModel(Model model, Matrix modelTransform, Matrix[] absoluteBoneTransforms)
{
//Draw the model, a model can have multiple meshes, so loop
foreach (ModelMesh mesh in model.Meshes)
{
//This is where the mesh orientation is set
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform;
effect.Projection = projectionMatrix;
effect.View = viewMatrix;
}
//Draw the mesh, will use the effects set above.
mesh.Draw();
}
}
これは、船の軸に沿ってではなく、船を回転させます。 Y軸を(回転Yの値を変更して)回転させると、船はY軸に沿って回転します。しかし、X軸またはZ軸を回転させると、船は世界のX軸とZ軸に応じて回転します。どのように私はそれを作るために、船は自分の軸で回転するのですか?行列とは何か違うことをする必要がありますか? おかげ
ありがとう。 CreateFromAxisAngleで船の回転軸を定義するにはどうすればよいですか?私は試してみました。行列に回転を保存するにはどうすればよいですか?それは私がやろうとしていることです。 – davidsbro
ちょうど私はそれについてのブログ記事を書いた。 http://stevehazen.wordpress.com/2010/02/15/matrix-basics-how-to-step-away-from-storing-an-orientation-as-3-angles/ –
ありがとうございました。私はあなたがそれを置く直前にあなたが置いたリンクを見つけました。笑。私はそれを読んで問題を解決することができました。ありがとうございました!本当に分かりやすくて本当に役に立ちました – davidsbro