Generating Icospheres
Without any subdivisions the Icosahedron has 12 vertices and 20 faces, in general though (not 100% sure about the vertices formular):
The 12 vertices of an icosahedron with edge length 2 can be described as:
where is the golden ratio:
To generate an icosahedron with radius 1, every coordinate will be normalized:
where:
void generate_ico_sphere() {
const f32 X = .525731112119133606f;
const f32 Z = .850650808352039932f;
const V3 vertices[12] {
{-X, 0, Z}, { X, 0, Z}, {-X, 0, -Z}, { X, 0, -Z},
{ 0, Z, X}, { 0, Z, -X}, { 0, -Z, X}, { 0, -Z, -X},
{ Z, X, 0}, {-Z, X, 0}, { Z, -X, 0}, {-Z, -X, 0},
};
const u32 indices[60] {
0, 1, 4,
0, 4, 9,
9, 4, 5,
4, 8, 5,
4, 1, 8,
8, 1, 10,
8, 10, 3,
5, 8, 3,
5, 3, 2,
2, 3, 7,
7, 3, 10,
7, 10, 6,
7, 6, 11,
11, 6, 0,
0, 6, 1,
6, 10, 1,
9, 11, 0,
9, 2, 11,
9, 5, 2,
7, 11, 2,
};
}