```
PlanetFace::PlanetFace(const int resolution, const glm::vec3& localUp, const PlanetSettings& settings, MinMaxFloat& elevation)
{
struct Vertex
{
glm::vec3 position = glm::vec3(0.0f);
glm::vec3 normal = glm::vec3(1.0f);
};
std::vector< Vertex> vertices;
std::vector< unsigned int> indices;
const int vertexCount = resolution * resolution;
const int indexCount = (resolution - 1) * (resolution - 1) * 6;
vertices.resize(vertexCount);
indices.resize(indexCount);
const glm::vec3 axisA = glm::vec3(localUp.y, localUp.z, localUp.x);
const glm::vec3 axisB = glm::cross(localUp, axisA);
for (int y = 0, vi = 0, ti = 0; y < resolution; y++)
{
for (int x = 0; x < resolution; x++, vi++)
{
const glm::vec2 factor = glm::vec2(x, y) / (float)(resolution - 1);
glm::vec3 pointOnCube = localUp + (factor.x - 0.5f) * 2.0f * axisA + (factor.y - 0.5f) * 2.0f * axisB;
glm::vec3 pointOnSphere = glm::normalize(pointOnCube);
glm::vec3 pointOnPlanet = settings.CalculatePointOnPlanet(pointOnSphere, elevation);
vertices[vi] = {pointOnPlanet, glm::vec3(1.0f)};
if (x == resolution - 1 || y == resolution - 1) continue;
indices[ti] = vi;
indices[ti + 1] = vi + resolution + 1;
indices[ti + 2] = vi + resolution;
indices[ti + 3] = vi;
indices[ti + 4] = vi + 1;
indices[ti + 5] = vi + resolution + 1;
ti += 6;
}
}
for (int i = 0; i < indexCount; i += 3)
{
//Triangle
Vertex* v1 = &vertices[indices[i]];
Vertex* v2 = &vertices[indices[i + 1]];
Vertex* v3 = &vertices[indices[i + 2]];
glm::vec3 normal = glm::normalize(glm::cross(v2->position - v1->position, v3->position - v1->position));
v1->normal += normal;
v2->normal += normal;
v3->normal += normal;
}
for (int i = 0; i < vertexCount; i++)
vertices[i].normal = glm::normalize(vertices[i].normal);
const int vertexSize = sizeof(float) * 6;
std::vector< LayoutElement> layout =
{
{3, GL_FLOAT, false, vertexSize, 0},
{3, GL_FLOAT, false, vertexSize, sizeof(float) * 3},
};
_mesh = std::make_unique< Mesh>(&vertices[0].position[0], vertexSize, vertexCount, &indices[0], indexCount, layout);
}
```