| |
| protected override void Draw(GameTime gameTime) |
| { |
| graphics.GraphicsDevice.Clear(Color.White); |
| |
| drawCameraStats(); |
| |
| GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; |
| GraphicsDevice.RenderState.DepthBufferEnable = true; |
| |
| graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration; |
| effect.Projection = camera.Projection; |
| effect.View = camera.View; |
| |
| foreach (Box box in boxes) |
| { |
| box.Draw(effect); |
| } |
| |
| base.Draw(gameTime); |
| } |
| |
| public static void InitializeBox() |
| { |
| boxSide = Tactics.Game.Content.Load<Texture2D>("Box Side"); |
| boxTop = Tactics.Game.Content.Load<Texture2D>("Box Top"); |
| |
| #region Initialize vertices |
| Vector3 position; |
| Vector2 textureCoordinates; |
| |
| #region topVerticies |
| topVerticies = new VertexPositionNormalTexture[4]; |
| |
| //top left |
| position = new Vector3(-5, 5, 0); |
| textureCoordinates = new Vector2(0, 0); |
| topVerticies[0] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom right |
| position = new Vector3(5, -5, 0); |
| textureCoordinates = new Vector2(1, 1); |
| topVerticies[1] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom left |
| position = new Vector3(-5, -5, 0); |
| textureCoordinates = new Vector2(0, 1); |
| topVerticies[2] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //top right |
| position = new Vector3(5, 5, 0); |
| textureCoordinates = new Vector2(1, 0); |
| topVerticies[3] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| #endregion |
| |
| #region topSideVertices |
| topSideVertices = new VertexPositionNormalTexture[4]; |
| |
| //top left |
| position = new Vector3(-5, 5, 0); |
| textureCoordinates = new Vector2(0, 0); |
| topSideVertices[0] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom right |
| position = new Vector3(5, 5, -1); |
| textureCoordinates = new Vector2(1, 1); |
| topSideVertices[1] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom left |
| position = new Vector3(5, 5, 0); |
| textureCoordinates = new Vector2(0, 1); |
| topSideVertices[2] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //top right |
| position = new Vector3(-5, 5, -1); |
| textureCoordinates = new Vector2(1, 0); |
| topSideVertices[3] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| #endregion |
| |
| #region bottomSideVertices |
| bottomSideVertices = new VertexPositionNormalTexture[4]; |
| |
| //top left |
| position = new Vector3(-5, -5, 0); |
| textureCoordinates = new Vector2(0, 0); |
| bottomSideVertices[0] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom right |
| position = new Vector3(5, -5, -1); |
| textureCoordinates = new Vector2(1, 1); |
| bottomSideVertices[1] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom left |
| position = new Vector3(-5, -5, -1); |
| textureCoordinates = new Vector2(0, 1); |
| bottomSideVertices[2] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //top right |
| position = new Vector3(5, -5, 0); |
| textureCoordinates = new Vector2(1, 0); |
| bottomSideVertices[3] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| #endregion |
| |
| #region leftSideVertices |
| leftSideVertices = new VertexPositionNormalTexture[4]; |
| |
| //top left |
| position = new Vector3(-5, 5, 0); |
| textureCoordinates = new Vector2(0, 0); |
| leftSideVertices[0] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom right |
| position = new Vector3(-5, -5, -1); |
| textureCoordinates = new Vector2(1, 1); |
| leftSideVertices[1] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom left |
| position = new Vector3(-5, 5, -1); |
| textureCoordinates = new Vector2(0, 1); |
| leftSideVertices[2] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //top right |
| position = new Vector3(-5, -5, 0); |
| textureCoordinates = new Vector2(1, 0); |
| leftSideVertices[3] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| #endregion |
| |
| #region rightSideVertices |
| rightSideVertices = new VertexPositionNormalTexture[4]; |
| |
| //top left |
| position = new Vector3(5, -5, 0); |
| textureCoordinates = new Vector2(0, 0); |
| rightSideVertices[0] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom right |
| position = new Vector3(5, 5, -1); |
| textureCoordinates = new Vector2(1, 1); |
| rightSideVertices[1] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //bottom left |
| position = new Vector3(5, -5, -1); |
| textureCoordinates = new Vector2(0, 1); |
| rightSideVertices[2] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| |
| //top right |
| position = new Vector3(5, 5, 0); |
| textureCoordinates = new Vector2(1, 0); |
| rightSideVertices[3] = new VertexPositionNormalTexture(position, Vector3.Forward, |
| textureCoordinates); |
| #endregion |
| #endregion |
| |
| #region Initialize indices |
| //6 vertices make up 2 triangles which make up our rectangle |
| indices = new short[6]; |
| |
| //triangle 1 (bottom portion) |
| indices[0] = 0; // top left |
| indices[1] = 1; // bottom right |
| indices[2] = 2; // bottom left |
| |
| //triangle 2 (top portion) |
| indices[3] = 0; // top left |
| indices[4] = 3; // top right |
| indices[5] = 1; // bottom right |
| #endregion |
| } |
| |
| //Box.Draw() |
| public void Draw(BasicEffect effect) |
| { |
| effect.World = world; |
| effect.TextureEnabled = true; |
| |
| if (RenderTop) |
| { |
| effect.Texture = boxTop; |
| effect.Begin(); |
| effect.CurrentTechnique.Passes[0].Begin(); |
| |
| //top |
| Tactics.Game.GraphicsDevice.DrawUserIndexedPrimitives( |
| PrimitiveType.TriangleList, |
| topVerticies, 0, topVerticies.Length, |
| indices, 0, indices.Length / 3); |
| |
| effect.CurrentTechnique.Passes[0].End(); |
| effect.End(); |
| } |
| |
| effect.Texture = boxSide; |
| effect.Begin(); |
| effect.CurrentTechnique.Passes[0].Begin(); |
| |
| //top Side |
| Tactics.Game.GraphicsDevice.DrawUserIndexedPrimitives( |
| PrimitiveType.TriangleList, |
| topSideVertices, 0, topSideVertices.Length, |
| indices, 0, indices.Length / 3); |
| |
| //bottom Side |
| Tactics.Game.GraphicsDevice.DrawUserIndexedPrimitives( |
| PrimitiveType.TriangleList, |
| bottomSideVertices, 0, bottomSideVertices.Length, |
| indices, 0, indices.Length / 3); |
| |
| //left Side |
| Tactics.Game.GraphicsDevice.DrawUserIndexedPrimitives( |
| PrimitiveType.TriangleList, |
| leftSideVertices, 0, leftSideVertices.Length, |
| indices, 0, indices.Length / 3); |
| |
| //right Side |
| Tactics.Game.GraphicsDevice.DrawUserIndexedPrimitives( |
| PrimitiveType.TriangleList, |
| rightSideVertices, 0, rightSideVertices.Length, |
| indices, 0, indices.Length / 3); |
| |
| effect.CurrentTechnique.Passes[0].End(); |
| effect.End(); |
| } |