public void Draw() { Matrix world = Matrix.CreateRotationY(Globals.players[id].yr + (float)Math.PI) * Matrix.CreateTranslation(position); Matrix[] bones = clipPlayer.GetSkinTransforms(); for (int i = 0; i < mod.Meshes.Count; i++) { foreach (SkinnedEffect effect in mod.Meshes[i].Effects) { effect.SetBoneTransforms(bones); effect.World = world; effect.View = Globals.player.camera.view; effect.Projection = Globals.player.camera.projection; effect.EnableDefaultLighting(); effect.SpecularColor = new Vector3(0f); effect.SpecularPower = 16; } if (i != 0) { mod.Meshes[i].Draw(); } } mod.Meshes[0].Draw(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> protected override void Draw(GameTime gameTime) { GraphicsDevice device = graphics.GraphicsDevice; device.Clear(Color.CornflowerBlue); Matrix[] bones = clipPlayer.GetSkinTransforms(); // Compute camera matrices. Matrix view = Matrix.CreateTranslation(0, -25, -8) * Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) * Matrix.CreateLookAt(new Vector3(0, -5, cameraDistance), new Vector3(0, 0, 20), Vector3.Up); Matrix projection = Matrix.CreatePerspectiveFieldOfView(0.949982712f, device.Viewport.AspectRatio, 1, 10000); //// Render the skinned mesh. //foreach (ModelMesh mesh in currentModel.Meshes) //{ // foreach (SkinnedEffect effect in mesh.Effects) // { // effect.SetBoneTransforms(bones); // effect.View = view; // effect.Projection = projection; // effect.EnableDefaultLighting(); // effect.SpecularColor = new Vector3(0.25f); // effect.SpecularPower = 16; // } // mesh.Draw(); //} Matrix worldMatrix = Matrix.Identity;//clipPlayer.getWorldTransform(0); foreach (ModelMesh mesh in currentModel.Meshes) { foreach (Effect effect in mesh.Effects) { effect.CurrentTechnique = effect.Techniques["SkinnedShip"]; effect.Parameters["world_Mx"].SetValue(worldMatrix); effect.Parameters["wvp_Mx"].SetValue(worldMatrix * view * projection); //Matrix worldInverseTranspose = Matrix.Transpose(Matrix.Invert(worldTransform)); //effect.Parameters["wit_Mx"].SetValue(worldInverseTranspose); Matrix viewInverse = Matrix.Invert(view); effect.Parameters["viewInv_Mx"].SetValue(viewInverse); effect.Parameters["Bones"].SetValue(bones); } mesh.Draw(); } base.Draw(gameTime); }