You are on page 1of 2

Vector3 cameraPosition; Vector3 cameraView; Vector3 cameraLoo ; float cameraRotY; float cameraRotX; BasicEffect effect; SpriteFont font; VertexPositionColor[]

gridVertices; int gridVertexCount; private void SetupGrid(int width, int height, int lineCount, float yHeight, Colo r color) { gridVertexCount = lineCount * 2; gridVertices = new VertexPositionColor[lineCount * 4]; int xDiff = width / (lineCount - 1); int zDiff = height / (lineCount-1); int xStart = -width/2; int xEnd = width/2; int zStart = -height/2; int zEnd = height/2; for (int x = 0; x < lineCount; x++) { gridVertices[x * 2] = new VertexPositionColor( new Vector3(xStart + (x * xDiff), zStart, yHeight), color); gridVertices[x * 2 + 1] = new VertexPositionColor( new Vector3(xStart + (x * xDiff), zEnd, yHeight), color); } int halfLine = lineCount / 2; for (int z = 0; z < lineCount; z++) { gridVertices[halfLine + z * 2] = new VertexPositionColor( new Vector3(xStart, zStart + (z * xDiff), yHeight), color); gridVertices[halfLine + z * 2 + 1] = new VertexPositionColor( new Vector3(xEnd, zStart + (z * xDiff), yHeight), color); } } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. effect = new BasicEffect(GraphicsDevice); effect.VertexColorEnabled = true; effect.LightingEnabled = true; spriteBatch = new SpriteBatch(GraphicsDevice); mon ey = Content.Load<Model>("mon ey"); font = Content.Load<SpriteFont>("font"); SetupGrid(20, 20, 5, 0.5f, Color.Red); int x = 5;

// TODO: use this.Content to load your game content here } GraphicsDevice.Clear(Color.Gray); float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; effect.View = Matrix.CreateLoo At(cameraPosition, cameraView, Vector 3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.T oRadians(45.0f), aspectRatio, 1.0f, 10000.0f); effect.CurrentTechnique.Passes[0].Apply(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineList, gridVertices, 0, 5);