Drought.Entity.MovableEntity.render C# (CSharp) Method

render() public method

public render ( GraphicsDevice graphics, Camera camera, Sun sun ) : void
graphics GraphicsDevice
camera Drought.World.Camera
sun Drought.World.Sun
return void
        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();
            }
        }