我是XNA的新手,正在创建一个简单的游戏。很抱歉这可能非常简单,但我找不到任何帮助。游戏中有一艘我用Blender制作的飞船,我想通过旋转飞船的X、Y和Z轴来控制它。以下是我的代码:
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轴(通过更改rotationY的值),那么船将沿其Y轴旋转。 但是,如果我旋转X或Z轴,则船会根据世界的X和Z轴旋转,而不是自己的轴心。 我如何使船沿着自己的轴心旋转? 我需要以不同方式处理矩阵吗? 谢谢