1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
public void Load(ContentManager content)
{
// Load the tank model from the ContentManager.
model = content.Load<Model>("dude");
// Look up shortcut references to the bones we are going to animate.
Head = model.Bones["Head"];
// Store the original transform matrix for each animating bone.
HeadTransform = Head.Transform;
// Allocate the transform matrix array.
boneTransforms = new Matrix[model.Bones.Count];
}
public void Draw(Matrix world, Matrix view, Matrix projection)
{
// Set the world matrix as the root transform of the model.
model.Root.Transform = world;
// Calculate matrices based on the current animation position.
Matrix Rotation = Matrix.CreateRotationX(RotationValue);
// Apply matrices to the relevant bones.
Head.Transform = Rotation * HeadTransform;
// Look up combined bone matrices for the entire model.
model.CopyAbsoluteBoneTransformsTo(boneTransforms);
// Draw the model.
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = boneTransforms[mesh.ParentBone.Index];
effect.View = view;
effect.Projection = projection;
effect.EnableDefaultLighting();
}
mesh.Draw();
}
} |