public virtual void render(GraphicsDevice graphics, Camera camera, Sun sun) { if (!isDead()) pathTool.render(camera.getViewMatrix(), camera.getProjectionMatrix()); if (selected) ringTool.render(camera.getViewMatrix(), camera.getProjectionMatrix()); graphics.RenderState.DepthBufferEnable = true; graphics.RenderState.AlphaBlendEnable = false; graphics.RenderState.AlphaTestEnable = false; Matrix[] transforms = new Matrix[model.Model.Bones.Count]; model.Model.CopyAbsoluteBoneTransformsTo(transforms); Matrix worldMatrix = Matrix.CreateScale(model.Scale) * orientation * Matrix.CreateTranslation(position); //"sink" the units a bit if they're dead, just to conceptually remove them from play if (isDead()) worldMatrix *= Matrix.CreateTranslation(new Vector3(0, 0, -0.5f)); int i = 0; foreach (ModelMesh mesh in model.Model.Meshes) { foreach (Effect currentEffect in mesh.Effects) { currentEffect.CurrentTechnique = model.Effect.Techniques["Textured"]; currentEffect.Parameters["xWorldViewProjection"].SetValue(transforms[mesh.ParentBone.Index] * worldMatrix * camera.getViewMatrix() * camera.getProjectionMatrix()); currentEffect.Parameters["xWorld"].SetValue(worldMatrix); currentEffect.Parameters["xTexture"].SetValue(model.Textures[i++]); currentEffect.Parameters["xEnableLighting"].SetValue(true); currentEffect.Parameters["xEnableNormals"].SetValue(true); currentEffect.Parameters["xLightPosition"].SetValue(sun.getPosition()); currentEffect.Parameters["xLightPower"].SetValue(sun.getPower()); currentEffect.Parameters["xGreyScale"].SetValue(isDead()); } mesh.Draw(); } }
public void render(Sun sun) { Matrix worldMatrix = Matrix.Identity; effect.CurrentTechnique = effect.Techniques["MultiTextured"]; effect.Parameters["xWaterTexture"].SetValue(waterTexture); effect.Parameters["xSandTexture"].SetValue(sandTexture); effect.Parameters["xStoneTexture"].SetValue(stoneTexture); effect.Parameters["xErrorTexture"].SetValue(errorTexture); effect.Parameters["xWorld"].SetValue(worldMatrix); effect.Parameters["xWorldViewProjection"].SetValue(worldMatrix * camera.getViewMatrix() * camera.getProjectionMatrix()); effect.Parameters["xEnableLighting"].SetValue(true); effect.Parameters["xLightPosition"].SetValue(sun.getPosition()); effect.Parameters["xLightPower"].SetValue(sun.getPower()); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.Vertices[0].SetSource(vb, 0, VertexMultiTextured.SizeInBytes); device.Indices = ib; device.VertexDeclaration = new VertexDeclaration(device, VertexMultiTextured.VertexElements); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, height * width, 0, (width - 1) * (height - 1) * 2); //device.DrawUserIndexedPrimitives<VertexMultiTextured>(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, (width - 1) * (height - 1) * 2); pass.End(); } effect.End(); }