//public List<Vector3> Trees; /*public Color[] GetImageData(Color[] colorData, int Value) * { * Color[] color = new Color[1]; * color[0] = colorData[Value]; * return color; * }*/ /* public void GetTrees(List<Vector3> trees, Vector2 MapPointer) * { * Trees = new List<Vector3>(); * foreach(Vector3 tree in trees) * { * if(tree.X < size + (int)MapPointer.Y-2 && * tree.X > (int)MapPointer.Y) * { * if(tree.Z < (size + (int)MapPointer.X) && * tree.Z > (int)MapPointer.X) * { * float f = ((tree.Z - MapPointer.X) + (tree.X - MapPointer.Y) * size) - 1; * float h = Vertices[(int)f].Position.Y; * Trees.Add(new Vector3(tree.Z-MapPointer.X, h, -(tree.X-MapPointer.Y))); * * } * } * } * * * }*/ public void GetVertices(VertexPositionColorNormal[] map, Vector2 MapPointer) { Vertices = new VertexPositionColorNormal[size * size]; WaterVertices = new VertexPositionColorNormal[size * size]; WireFrameVertices = new VertexPositionColorNormal[size * size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { Vertices[x + y * size].Position = new Vector3(x, 0, -y); Vertices[x + y * size].Position.Y = map[(x + (int)MapPointer.X) + (y + (int)MapPointer.Y) * 128].Position.Y; WaterVertices[x + y * size].Position = new Vector3(x, 0.001f, -y); WireFrameVertices[x + y * size].Position = Vertices[x + y * size].Position; WireFrameVertices[x + y * size].Position.Y += 0.01f; WireFrameVertices[x + y * size].Color = Color.Black; Vertices[x + y * size].Color = Color.ForestGreen; WaterSand(x + y * size); SetNormal(x + y * size); } } }
private void SetUpVertices() { Vertices = new VertexPositionColorNormal[TerrainWidth * TerrainHeight]; int numberOfTextures = 3; int divider = 2; for (int y = 0; y < TerrainHeight; y++) { for (int x = 0; x < TerrainWidth; x++) { //change the divider to heighData[x, y] to reduce hill sizes Vertices[x + y * TerrainWidth].Position = new Vector3(x, (HeightData[x, y]) / divider, -y); WaterSand(x + y * TerrainWidth); if (x != 0 && x != TerrainWidth - 1 && y != TerrainHeight - 1) { /********************FIRST TRIANGLE*************************************************/ if (HeightData[x, y] == 0 && HeightData[x, y + 1] == 0 && HeightData[x + 1, y] == 0) { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 1))); } else if (HeightData[x, y] == 0 || HeightData[x, y + 1] == 0 || HeightData[x + 1, y] == 0) { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(3f / numberOfTextures, 1))); } else { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(0f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(0f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 1))); } /*************************SECOND TRIANGLE**********************************************/ if ((HeightData[x, y + 1] == 0 && HeightData[x + 1, y + 1] == 0 && HeightData[x + 1, y] == 0)) { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 0))); } else if ((HeightData[x, y + 1] == 0 || HeightData[x + 1, y + 1] == 0 || HeightData[x + 1, y] == 0)) { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(3f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(3f / numberOfTextures, 0))); } else { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(0f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y + 1] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x + 1, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 0))); } /**************************************************************************************/ } else { textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x, HeightData[x, y] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(1f / numberOfTextures, 0))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x, y] / divider, -y - 1), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 1))); textureList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, HeightData[x, y] / divider, -y), new Vector3(0, 1, 0), new Vector2(2f / numberOfTextures, 0))); } } } }