public HeightMap clone() { HeightMap heightMap = new HeightMap(width, height); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) heightMap.setHeight(x, y, map[x, y]); return heightMap; }
public NormalMap(HeightMap heightMap) { initialise(heightMap); }
private void initialise(HeightMap heightMap) { width = heightMap.getMapWidth(); height = heightMap.getMapHeight(); normals = new Vector3[width, height, 2]; for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { Vector3 p0 = heightMap.getPositionAt(x, y); Vector3 p1 = heightMap.getPositionAt(x + 1, y); Vector3 p2 = heightMap.getPositionAt(x, y + 1); Vector3 p3 = heightMap.getPositionAt(x + 1, y + 1); Vector3 v0 = p2 - p0; Vector3 v1 = p3 - p2; Vector3 v2 = p3 - p1; Vector3 v3 = p1 - p0; normals[x, y, 0] = Vector3.Cross(v1, v0); normals[x, y, 1] = Vector3.Cross(v3, v2); } }