private void generateVertrices(SuperVertex[,] vertrices, float translateY, float maxHeightDifference, float maxScramble) { Random rand = new Random(); float last = 0.0f; float ratio = (float)width / (float)depth; int mul = 2; for (int i = 0; i < width; i++) { float h = ((0.5f - (float)rand.NextDouble()) * maxHeightDifference) + last + translateY; float x = (float)i / 2.0f; for (int j = 0; j < depth; j++) { float y = (float)j / 2.0f; vertrices[i, j] = new SuperVertex(); vertrices[i, j].position = new Vector3f(x, h + ((0.5f - (float)rand.NextDouble()) * maxScramble), -y); vertrices[i, j].texCoord = new Vector2f((float)(i * mul) / (float)depth, ((float)(j * mul) / (float)depth)); } last = h - translateY; } for (int i = 0; i < width; i++) { vertrices[i, 0].position.y -= maxHeightDifference; vertrices[i, 1].position.y -= (maxHeightDifference) / 2.0f; } }
private void loadWorld(string loadPath) { Bitmap data = new Bitmap(loadPath); int step = 1; width = data.Width / step; depth = data.Height / step; vertrices = new SuperVertex[width * depth]; for (int z = 0; z < depth; z++) { for (int x = 0; x < width; x++) { vertrices[x + z * width] = new SuperVertex(); vertrices[x + z * width].position = new Vector3f(x, data.GetPixel(x, z).R / 8.0f, z); } } data.Dispose(); }
private void generateNormals(SuperVertex[,] vertrices, bool invertNormal) { Vector3f vecA, vecB, vecC, vecD, normA, normB, normC, normD; for (int z = 1; z < (depth - 1); z++) { for (int x = 1; x < (width - 1); x++) { Vector3f p = vertrices[x , z].position; vecA = vertrices[x-1 , z ].position.diff(p); vecB = vertrices[x ,z-1].position.diff(p); vecC = vertrices[x+1 ,z ].position.diff(p); vecD = vertrices[x ,z+1].position.diff(p); normA = vecA.Cross(vecD); normB = vecD.Cross(vecC); normC = vecC.Cross(vecB); normD = vecB.Cross(vecA); vertrices[x , z].normal = normA.add(normB).add(normC).add(normD); if (invertNormal) vertrices[x , z].normal.invert(); vertrices[x , z].normal.Normalize(); } } }
public LandscapeCluster(SuperVertex[] data, int width, int depth) { }