public Terrain(HeightMap heightMap, float heightScale, GraphicsDevice device) { this.width = heightMap.Width; this.height = heightMap.Height; this.vertices = this.loadVertices(heightMap, heightScale); this.setupIndices(); this.calculateNormals(); this.copyToBuffers(device); }
private VertexPositionColorNormal[] loadVertices(HeightMap heightMap, float heightScale) { VertexPositionColorNormal[] vertices = new VertexPositionColorNormal[this.width * this.height]; for (int x = 0; x < this.width; x++) for (int y = 0; y < this.height; y++) { int v = x + y * this.width; float h = heightMap[x, y] * heightScale; vertices[v].Position = new Vector3(x, h, -y); vertices[v].Color = Color.Green; } return vertices; }