#include "GEIcosahedron.h"

#include "GEVertex.h"

//
// FUNCIÓN: GEIcosahedron::GEIcosahedron(float r)
//
// PROPÓSITO: Crea la figura
//
GEIcosahedron::GEIcosahedron(float r)
{
	int numFaces = 20; // Number of faces
	int numVertices = 60; // Number of vertices
	vertices.resize(numVertices);
	indices.resize(numFaces * 3);

	float phi = (float)((1 + sqrt(5.0)) / 2.0);

	GEVertex A0 = { { 0.0f, r * phi, r } };
	GEVertex A1 = { { 0, r * phi, -r } };
	GEVertex A2 = { { 0, -r * phi, -r } };
	GEVertex A3 = { { 0, -r * phi, r } };
	GEVertex B0 = { { r * phi, r, 0 } };
	GEVertex B1 = { { r * phi, -r, 0 } };
	GEVertex B2 = { { -r * phi, -r, 0 } };
	GEVertex B3 = { { -r * phi, r, 0 } };
	GEVertex C0 = { { r, 0, r * phi } };
	GEVertex C1 = { { r, 0, -r * phi } };
	GEVertex C2 = { { -r, 0, -r * phi } };
	GEVertex C3 = { { -r, 0, r * phi } };

	// face 1
	vertices[0] = A0;
	vertices[1] = A1;
	vertices[2] = B3;

	// face 2
	vertices[3] = A0;
	vertices[4] = B3;
	vertices[5] = C3;

	// face 3
	vertices[6] = A0;
	vertices[7] = C3;
	vertices[8] = C0;

	// face 4
	vertices[9] = A0;
	vertices[10] = C0;
	vertices[11] = B0;

	// face 5
	vertices[12] = A0;
	vertices[13] = B0;
	vertices[14] = A1;

	// face 6
	vertices[15] = B1;
	vertices[16] = C1;
	vertices[17] = B0;

	// face 7
	vertices[18] = B1;
	vertices[19] = B0;
	vertices[20] = C0;

	// face 8
	vertices[21] = B1;
	vertices[22] = C0;
	vertices[23] = A3;

	// face 9
	vertices[24] = B1;
	vertices[25] = A3;
	vertices[26] = A2;

	// face 10
	vertices[27] = B1;
	vertices[28] = A2;
	vertices[29] = C1;

	// face 11
	vertices[30] = B0;
	vertices[31] = C1;
	vertices[32] = A1;

	// face 12
	vertices[33] = C0;
	vertices[34] = C3;
	vertices[35] = A3;

	// face 13
	vertices[36] = A1;
	vertices[37] = C1;
	vertices[38] = C2;

	// face 14
	vertices[39] = A1;
	vertices[40] = C2;
	vertices[41] = B3;

	// face 15
	vertices[42] = C3;
	vertices[43] = B3;
	vertices[44] = B2;

	// face 16
	vertices[45] = C3;
	vertices[46] = B2;
	vertices[47] = A3;

	// face 17
	vertices[48] = B3;
	vertices[49] = C2;
	vertices[50] = B2;

	// face 18
	vertices[51] = C2;
	vertices[52] = C1;
	vertices[53] = A2;

	// face 19
	vertices[54] = C2;
	vertices[55] = A2;
	vertices[56] = B2;

	// face 20
	vertices[57] = A2;
	vertices[58] = A3;
	vertices[59] = B2;

	for (int i = 0; i < numVertices; i++) indices[i] = i;
}
