/// <summary> /// Constructor /// </summary> public SkinnedGame() { // XNA startup graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Some basic setup for the display window this.IsMouseVisible = true; this.Window.AllowUserResizing = true; this.graphics.PreferredBackBufferWidth = 1024; this.graphics.PreferredBackBufferHeight = 768; // Create a simple mouse-based camera camera = new Camera(graphics); camera.Eye = new Vector3(190, 247, 387); camera.Center = new Vector3(-20, 86, 159); }
/// <summary> /// Draw the model /// </summary> /// <param name="graphics">The graphics device to draw on</param> /// <param name="camera">A camera to determine the view</param> /// <param name="world">A world matrix to place the model</param> public void Draw(GraphicsDevice graphics, Camera camera, Matrix world) { if (model == null) return; // // Compute all of the bone absolute transforms // Matrix[] boneTransforms = new Matrix[bones.Count]; for (int i = 0; i < bones.Count; i++) { Bone bone = bones[i]; bone.ComputeAbsoluteTransform(); boneTransforms[i] = bone.AbsoluteTransform; } // // Determine the skin transforms from the skeleton // Matrix[] skeleton = new Matrix[modelExtra.Skeleton.Count]; for (int s = 0; s < modelExtra.Skeleton.Count; s++) { Bone bone = bones[modelExtra.Skeleton[s]]; skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform; } // Draw the model. foreach (ModelMesh modelMesh in model.Meshes) { foreach (Effect effect in modelMesh.Effects) { if (effect is BasicEffect) { BasicEffect beffect = effect as BasicEffect; beffect.World = boneTransforms[modelMesh.ParentBone.Index] * world; beffect.View = camera.View; beffect.Projection = camera.Projection; beffect.EnableDefaultLighting(); beffect.PreferPerPixelLighting = true; } if (effect is SkinnedEffect) { SkinnedEffect seffect = effect as SkinnedEffect; seffect.World = boneTransforms[modelMesh.ParentBone.Index] * world; seffect.View = camera.View; seffect.Projection = camera.Projection; seffect.EnableDefaultLighting(); seffect.PreferPerPixelLighting = true; seffect.SetBoneTransforms(skeleton); } } modelMesh.Draw(); } }