#include "CGIcosahedron.h"
#include <GL/glew.h>
#include <math.h>
#include "CGFigure.h"

//
// FUNCIÓN: CGIcosahedron::CGIcosahedron(GLfloat r)
//
// PROPÓSITO: Dibuja un icosaedro de arista '2r'
// 
CGIcosahedron::CGIcosahedron(GLfloat r)
{
	numFaces = 20; // Number of faces
	numVertices = 60; // Number of vertices
	normals = new GLfloat[numVertices * 3];
	textures = new GLfloat[numVertices * 2];
	vertices = new GLfloat[numVertices * 3];
	indexes = new GLushort[numFaces * 3];

	GLfloat phi = (GLfloat)((1 + sqrt(5.0)) / 2.0);
	GLfloat mod = (GLfloat)sqrt(6 + 9 * phi);
	GLfloat p0M = (GLfloat)phi / mod;
	GLfloat p1M = (GLfloat)(phi + 1) / mod;
	GLfloat p2M = (GLfloat)(2 * phi + 1) / mod;
	GLfloat X0 = 0.0f;
	GLfloat X1 = 1.0f / 11;
	GLfloat X2 = 2.0f / 11;
	GLfloat X3 = 3.0f / 11;
	GLfloat X4 = 4.0f / 11;
	GLfloat X5 = 5.0f / 11;
	GLfloat X6 = 6.0f / 11;
	GLfloat X7 = 7.0f / 11;
	GLfloat X8 = 8.0f / 11;
	GLfloat X9 = 9.0f / 11;
	GLfloat X10 = 10.0f / 11;
	GLfloat X11 = 1.0f;
	GLfloat Y0 = 0.0f;
	GLfloat Y1 = 1.0f / 3;
	GLfloat Y2 = 2.0f / 3;
	GLfloat Y3 = 1.0f;

	GLfloat A0[] = { 0, r * phi, r };
	GLfloat A1[] = { 0, r * phi, -r };
	GLfloat A2[] = { 0, -r * phi, -r };
	GLfloat A3[] = { 0, -r * phi, r };
	GLfloat B0[] = { r * phi, r, 0 };
	GLfloat B1[] = { r * phi, -r, 0 };
	GLfloat B2[] = { -r * phi, -r, 0 };
	GLfloat B3[] = { -r * phi, r, 0 };
	GLfloat C0[] = { r, 0, r * phi };
	GLfloat C1[] = { r, 0, -r * phi };
	GLfloat C2[] = { -r, 0, -r * phi };
	GLfloat C3[] = { -r, 0, r * phi };

	GLfloat N1[] = { -p0M, p2M, 0 };
	GLfloat N2[] = { -p1M, p1M, p1M };
	GLfloat N3[] = { 0, p0M, p2M };
	GLfloat N4[] = { p1M, p1M, p1M };
	GLfloat N5[] = { p0M, p2M, 0 };
	GLfloat N6[] = { p2M, 0, -p0M };
	GLfloat N7[] = { p2M, 0, p0M };
	GLfloat N8[] = { p1M, -p1M, p1M };
	GLfloat N9[] = { p0M, -p2M, 0 };
	GLfloat N10[] = { p1M, -p1M, -p1M };
	GLfloat N11[] = { p1M, p1M, -p1M };
	GLfloat N12[] = { 0, -p0M, p2M };
	GLfloat N13[] = { 0, p0M, -p2M };
	GLfloat N14[] = { -p1M, p1M, -p1M };
	GLfloat N15[] = { -p2M, 0, p0M };
	GLfloat N16[] = { -p1M, -p1M, p1M };
	GLfloat N17[] = { -p2M, 0, -p0M };
	GLfloat N18[] = { 0, -p0M, -p2M };
	GLfloat N19[] = { -p1M, -p1M, -p1M };
	GLfloat N20[] = { -p0M, -p2M, 0 };

	int texturesIndex = 0;
	int normalsIndex = 0;
	int verticesIndex = 0;

	// face 1; vertex[1] = A0; normals[1]=N1; textures[1]={X1,Y3};
	vertices[verticesIndex] = A0[0];
	vertices[verticesIndex + 1] = A0[1];
	vertices[verticesIndex + 2] = A0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N1[0];
	normals[normalsIndex + 1] = N1[1];
	normals[normalsIndex + 2] = N1[2];
	normalsIndex += 3;
	textures[texturesIndex] = X1;
	textures[texturesIndex + 1] = Y3;
	texturesIndex += 2;

	// face 1; vertex[2]=A1; normals[2]=N1; textures[2]={X0,Y2};
	vertices[verticesIndex] = A1[0];
	vertices[verticesIndex + 1] = A1[1];
	vertices[verticesIndex + 2] = A1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N1[0];
	normals[normalsIndex + 1] = N1[1];
	normals[normalsIndex + 2] = N1[2];
	normalsIndex += 3;
	textures[texturesIndex] = X0;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 1; vertex[3]=B3; normals[3]=N1; textures[3]={X2,Y2};
	vertices[verticesIndex] = B3[0];
	vertices[verticesIndex + 1] = B3[1];
	vertices[verticesIndex + 2] = B3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N1[0];
	normals[normalsIndex + 1] = N1[1];
	normals[normalsIndex + 2] = N1[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 2; vertex[1] = A0; normals[1]=N2; textures[1]={X3,Y3};
	vertices[verticesIndex] = A0[0];
	vertices[verticesIndex + 1] = A0[1];
	vertices[verticesIndex + 2] = A0[2]; verticesIndex += 3;
	normals[normalsIndex] = N2[0];
	normals[normalsIndex + 1] = N2[1];
	normals[normalsIndex + 2] = N2[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y3;
	texturesIndex += 2;

	// face 2; vertex[2] = B3; normals[2]=N2; textures[2]={X2,Y2};
	vertices[verticesIndex] = B3[0];
	vertices[verticesIndex + 1] = B3[1];
	vertices[verticesIndex + 2] = B3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N2[0];
	normals[normalsIndex + 1] = N2[1];
	normals[normalsIndex + 2] = N2[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 2; vertex[3] = C3; normals[3]=N2; textures[3]={X4,Y2};
	vertices[verticesIndex] = C3[0];
	vertices[verticesIndex + 1] = C3[1];
	vertices[verticesIndex + 2] = C3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N2[0];
	normals[normalsIndex + 1] = N2[1];
	normals[normalsIndex + 2] = N2[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 3; vertex[1] = A0; normals[1]=N3; textures[1]={X5,Y3};
	vertices[verticesIndex] = A0[0];
	vertices[verticesIndex + 1] = A0[1];
	vertices[verticesIndex + 2] = A0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N3[0];
	normals[normalsIndex + 1] = N3[1];
	normals[normalsIndex + 2] = N3[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y3;
	texturesIndex += 2;

	// face 3; vertex[2] = C3; normals[2]=N3; textures[2]={X4,Y2};
	vertices[verticesIndex] = C3[0];
	vertices[verticesIndex + 1] = C3[1];
	vertices[verticesIndex + 2] = C3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N3[0];
	normals[normalsIndex + 1] = N3[1];
	normals[normalsIndex + 2] = N3[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 3; vertex[3] = C0; normals[3]=N3; textures[3]={X6,Y2};
	vertices[verticesIndex] = C0[0];
	vertices[verticesIndex + 1] = C0[1];
	vertices[verticesIndex + 2] = C0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N3[0];
	normals[normalsIndex + 1] = N3[1];
	normals[normalsIndex + 2] = N3[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 4; vertex[1] = A0; normals[1]=N4; textures[1]={X7,Y3};
	vertices[verticesIndex] = A0[0];
	vertices[verticesIndex + 1] = A0[1];
	vertices[verticesIndex + 2] = A0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N4[0];
	normals[normalsIndex + 1] = N4[1];
	normals[normalsIndex + 2] = N4[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y3;
	texturesIndex += 2;

	// face 4; vertex[2] = C0; normals[2]=N4; textures[2]={X6,Y2};
	vertices[verticesIndex] = C0[0];
	vertices[verticesIndex + 1] = C0[1];
	vertices[verticesIndex + 2] = C0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N4[0];
	normals[normalsIndex + 1] = N4[1];
	normals[normalsIndex + 2] = N4[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 4; vertex[3] = B0; normals[3]=N4; textures[3]={X8,Y2};
	vertices[verticesIndex] = B0[0];
	vertices[verticesIndex + 1] = B0[1];
	vertices[verticesIndex + 2] = B0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N4[0];
	normals[normalsIndex + 1] = N4[1];
	normals[normalsIndex + 2] = N4[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 5; vertex[1] = A0; normals[1]=N5; textures[1]={X9,Y3};
	vertices[verticesIndex] = A0[0];
	vertices[verticesIndex + 1] = A0[1];
	vertices[verticesIndex + 2] = A0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N5[0];
	normals[normalsIndex + 1] = N5[1];
	normals[normalsIndex + 2] = N5[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y3;
	texturesIndex += 2;

	// face 5; vertex[2] = B0; normals[2]=N5; textures[2]={X8,Y2};
	vertices[verticesIndex] = B0[0];
	vertices[verticesIndex + 1] = B0[1];
	vertices[verticesIndex + 2] = B0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N5[0];
	normals[normalsIndex + 1] = N5[1];
	normals[normalsIndex + 2] = N5[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 5; vertex[3] = A1; normals[3]=N5; textures[3]={X10,Y2};
	vertices[verticesIndex] = A1[0];
	vertices[verticesIndex + 1] = A1[1];
	vertices[verticesIndex + 2] = A1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N5[0];
	normals[normalsIndex + 1] = N5[1];
	normals[normalsIndex + 2] = N5[2];
	normalsIndex += 3;
	textures[texturesIndex] = X10;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 6; vertex[1] = B1; normals[1]=N6; textures[1]={X7,Y1};
	vertices[verticesIndex] = B1[0];
	vertices[verticesIndex + 1] = B1[1];
	vertices[verticesIndex + 2] = B1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N6[0];
	normals[normalsIndex + 1] = N6[1];
	normals[normalsIndex + 2] = N6[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 6; vertex[2] = C1; normals[2]=N6; textures[2]={X9,Y1};
	vertices[verticesIndex] = C1[0];
	vertices[verticesIndex + 1] = C1[1];
	vertices[verticesIndex + 2] = C1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N6[0];
	normals[normalsIndex + 1] = N6[1];
	normals[normalsIndex + 2] = N6[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 6; vertex[3] = B0; normals[3]=N6; textures[3]={X8,Y2};
	vertices[verticesIndex] = B0[0];
	vertices[verticesIndex + 1] = B0[1];
	vertices[verticesIndex + 2] = B0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N6[0];
	normals[normalsIndex + 1] = N6[1];
	normals[normalsIndex + 2] = N6[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 7; vertex[1] = B1; normals[1]=N7; textures[1]={X7,Y1};
	vertices[verticesIndex] = B1[0];
	vertices[verticesIndex + 1] = B1[1];
	vertices[verticesIndex + 2] = B1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N7[0];
	normals[normalsIndex + 1] = N7[1];
	normals[normalsIndex + 2] = N7[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 7; vertex[2] = B0; normals[2]=N7; textures[2]={X8,Y2};
	vertices[verticesIndex] = B0[0];
	vertices[verticesIndex + 1] = B0[1];
	vertices[verticesIndex + 2] = B0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N7[0];
	normals[normalsIndex + 1] = N7[1];
	normals[normalsIndex + 2] = N7[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 7; vertex[3] = C0; normals[3]=N7; textures[3]={X6,Y2};
	vertices[verticesIndex] = C0[0];
	vertices[verticesIndex + 1] = C0[1];
	vertices[verticesIndex + 2] = C0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N7[0];
	normals[normalsIndex + 1] = N7[1];
	normals[normalsIndex + 2] = N7[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 8; vertex[1] = B1; normals[1]=N8; textures[1]={X7,Y1};
	vertices[verticesIndex] = B1[0];
	vertices[verticesIndex + 1] = B1[1];
	vertices[verticesIndex + 2] = B1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N8[0];
	normals[normalsIndex + 1] = N8[1];
	normals[normalsIndex + 2] = N8[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 8; vertex[2] = C0; normals[2]=N8; textures[2]={X6,Y2};
	vertices[verticesIndex] = C0[0];
	vertices[verticesIndex + 1] = C0[1];
	vertices[verticesIndex + 2] = C0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N8[0];
	normals[normalsIndex + 1] = N8[1];
	normals[normalsIndex + 2] = N8[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 8; vertex[3] = A3; normals[3]=N8; textures[3]={X5,Y1};
	vertices[verticesIndex] = A3[0];
	vertices[verticesIndex + 1] = A3[1];
	vertices[verticesIndex + 2] = A3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N8[0];
	normals[normalsIndex + 1] = N8[1];
	normals[normalsIndex + 2] = N8[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 9; vertex[1] = B1; normals[1]=N9; textures[1]={X7,Y1};
	vertices[verticesIndex] = B1[0];
	vertices[verticesIndex + 1] = B1[1];
	vertices[verticesIndex + 2] = B1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N9[0];
	normals[normalsIndex + 1] = N9[1];
	normals[normalsIndex + 2] = N9[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 9; vertex[2] = A3; normals[2]=N9; textures[2]={X5,Y1};
	vertices[verticesIndex] = A3[0];
	vertices[verticesIndex + 1] = A3[1];
	vertices[verticesIndex + 2] = A3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N9[0];
	normals[normalsIndex + 1] = N9[1];
	normals[normalsIndex + 2] = N9[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 9; vertex[3] = A2; normals[3]=N9; textures[3]={X6,Y0};
	vertices[verticesIndex] = A2[0];
	vertices[verticesIndex + 1] = A2[1];
	vertices[verticesIndex + 2] = A2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N9[0];
	normals[normalsIndex + 1] = N9[1];
	normals[normalsIndex + 2] = N9[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y0;
	texturesIndex += 2;

	// face 10; vertex[1] = B1; normals[1]=N10; textures[1]={X7,Y1};
	vertices[verticesIndex] = B1[0];
	vertices[verticesIndex + 1] = B1[1];
	vertices[verticesIndex + 2] = B1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N10[0];
	normals[normalsIndex + 1] = N10[1];
	normals[normalsIndex + 2] = N10[2];
	normalsIndex += 3;
	textures[texturesIndex] = X7;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 10; vertex[2] = A2; normals[2]=N10; textures[2]={X8,Y0};
	vertices[verticesIndex] = A2[0];
	vertices[verticesIndex + 1] = A2[1];
	vertices[verticesIndex + 2] = A2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N10[0];
	normals[normalsIndex + 1] = N10[1];
	normals[normalsIndex + 2] = N10[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y0;
	texturesIndex += 2;

	// face 10; vertex[3] = C1; normals[3]=N10; textures[3]={X9,Y1};
	vertices[verticesIndex] = C1[0];
	vertices[verticesIndex + 1] = C1[1];
	vertices[verticesIndex + 2] = C1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N10[0];
	normals[normalsIndex + 1] = N10[1];
	normals[normalsIndex + 2] = N10[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 11; vertex[1] = B0; normals[1]=N11; textures[1]={X8,Y2};
	vertices[verticesIndex] = B0[0];
	vertices[verticesIndex + 1] = B0[1];
	vertices[verticesIndex + 2] = B0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N11[0];
	normals[normalsIndex + 1] = N11[1];
	normals[normalsIndex + 2] = N11[2];
	normalsIndex += 3;
	textures[texturesIndex] = X8;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 11; vertex[2] = C1; normals[2]=N11; textures[2]={X9,Y1};
	vertices[verticesIndex] = C1[0];
	vertices[verticesIndex + 1] = C1[1];
	vertices[verticesIndex + 2] = C1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N11[0];
	normals[normalsIndex + 1] = N11[1];
	normals[normalsIndex + 2] = N11[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 11; vertex[3] = A1; normals[3]=N11; textures[3]={X10,Y2};
	vertices[verticesIndex] = A1[0];
	vertices[verticesIndex + 1] = A1[1];
	vertices[verticesIndex + 2] = A1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N11[0];
	normals[normalsIndex + 1] = N11[1];
	normals[normalsIndex + 2] = N11[2];
	normalsIndex += 3;
	textures[texturesIndex] = X10;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 12; vertex[1] = C0; normals[1]=N12; textures[1]={X6,Y2};
	vertices[verticesIndex] = C0[0];
	vertices[verticesIndex + 1] = C0[1];
	vertices[verticesIndex + 2] = C0[2];
	verticesIndex += 3;
	normals[normalsIndex] = N12[0];
	normals[normalsIndex + 1] = N12[1];
	normals[normalsIndex + 2] = N12[2];
	normalsIndex += 3;
	textures[texturesIndex] = X6;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 12; vertex[2] = C3; normals[2]=N12; textures[2]={X4,Y2};
	vertices[verticesIndex] = C3[0];
	vertices[verticesIndex + 1] = C3[1];
	vertices[verticesIndex + 2] = C3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N12[0];
	normals[normalsIndex + 1] = N12[1];
	normals[normalsIndex + 2] = N12[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 12; vertex[3] = A3; normals[3]=N12; textures[3]={X5,Y1};
	vertices[verticesIndex] = A3[0];
	vertices[verticesIndex + 1] = A3[1];
	vertices[verticesIndex + 2] = A3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N12[0];
	normals[normalsIndex + 1] = N12[1];
	normals[normalsIndex + 2] = N12[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 13; vertex[1] = A1; normals[1]=N13; textures[1]={X10,Y2};
	vertices[verticesIndex] = A1[0];
	vertices[verticesIndex + 1] = A1[1];
	vertices[verticesIndex + 2] = A1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N13[0];
	normals[normalsIndex + 1] = N13[1];
	normals[normalsIndex + 2] = N13[2];
	normalsIndex += 3;
	textures[texturesIndex] = X10;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 13; vertex[2] = C1; normals[2]=N13; textures[2]={X9,Y1};
	vertices[verticesIndex] = C1[0];
	vertices[verticesIndex + 1] = C1[1];
	vertices[verticesIndex + 2] = C1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N13[0];
	normals[normalsIndex + 1] = N13[1];
	normals[normalsIndex + 2] = N13[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 13; vertex[3] = C2; normals[3]=N13; textures[3]={X11,Y1};
	vertices[verticesIndex] = C2[0];
	vertices[verticesIndex + 1] = C2[1];
	vertices[verticesIndex + 2] = C2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N13[0];
	normals[normalsIndex + 1] = N13[1];
	normals[normalsIndex + 2] = N13[2];
	normalsIndex += 3;
	textures[texturesIndex] = X11;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 14; vertex[1] = A1; normals[1]=N14; textures[1]={X0,Y2};
	vertices[verticesIndex] = A1[0];
	vertices[verticesIndex + 1] = A1[1];
	vertices[verticesIndex + 2] = A1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N14[0];
	normals[normalsIndex + 1] = N14[1];
	normals[normalsIndex + 2] = N14[2];
	normalsIndex += 3;
	textures[texturesIndex] = X0;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 14; vertex[2] = C2; normals[2]=N14; textures[2]={X1,Y1};
	vertices[verticesIndex] = C2[0];
	vertices[verticesIndex + 1] = C2[1];
	vertices[verticesIndex + 2] = C2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N14[0];
	normals[normalsIndex + 1] = N14[1];
	normals[normalsIndex + 2] = N14[2];
	normalsIndex += 3;
	textures[texturesIndex] = X1;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 14; vertex[3] = B3; normals[3]=N14; textures[3]={X2,Y2};
	vertices[verticesIndex] = B3[0];
	vertices[verticesIndex + 1] = B3[1];
	vertices[verticesIndex + 2] = B3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N14[0];
	normals[normalsIndex + 1] = N14[1];
	normals[normalsIndex + 2] = N14[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 15; vertex[1] = C3; normals[1]=N15; textures[1]={X4,Y2};
	vertices[verticesIndex] = C3[0];
	vertices[verticesIndex + 1] = C3[1];
	vertices[verticesIndex + 2] = C3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N15[0];
	normals[normalsIndex + 1] = N15[1];
	normals[normalsIndex + 2] = N15[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 15; vertex[2] = B3; normals[2]=N15; textures[2]={X2,Y2};
	vertices[verticesIndex] = B3[0];
	vertices[verticesIndex + 1] = B3[1];
	vertices[verticesIndex + 2] = B3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N15[0];
	normals[normalsIndex + 1] = N15[1];
	normals[normalsIndex + 2] = N15[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 15; vertex[3] = B2; normals[3]=N15; textures[3]={X3,Y1};
	vertices[verticesIndex] = B2[0];
	vertices[verticesIndex + 1] = B2[1];
	vertices[verticesIndex + 2] = B2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N15[0];
	normals[normalsIndex + 1] = N15[1];
	normals[normalsIndex + 2] = N15[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 16; vertex[1] = C3; normals[1]=N16; textures[1]={X4,Y2};
	vertices[verticesIndex] = C3[0];
	vertices[verticesIndex + 1] = C3[1];
	vertices[verticesIndex + 2] = C3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N16[0];
	normals[normalsIndex + 1] = N16[1];
	normals[normalsIndex + 2] = N16[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 16; vertex[2] = B2; normals[2]=N16; textures[2]={X3,Y1};
	vertices[verticesIndex] = B2[0];
	vertices[verticesIndex + 1] = B2[1];
	vertices[verticesIndex + 2] = B2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N16[0];
	normals[normalsIndex + 1] = N16[1];
	normals[normalsIndex + 2] = N16[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 16; vertex[3] = A3; normals[3]=N16; textures[3]={X5,Y1};
	vertices[verticesIndex] = A3[0];
	vertices[verticesIndex + 1] = A3[1];
	vertices[verticesIndex + 2] = A3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N16[0];
	normals[normalsIndex + 1] = N16[1];
	normals[normalsIndex + 2] = N16[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 17; vertex[1] = B3; normals[1]=N17; textures[1]={X2,Y2};
	vertices[verticesIndex] = B3[0];
	vertices[verticesIndex + 1] = B3[1];
	vertices[verticesIndex + 2] = B3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N17[0];
	normals[normalsIndex + 1] = N17[1];
	normals[normalsIndex + 2] = N17[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y2;
	texturesIndex += 2;

	// face 17; vertex[2] = C2; normals[2]=N17; textures[2]={X1,Y1};
	vertices[verticesIndex] = C2[0];
	vertices[verticesIndex + 1] = C2[1];
	vertices[verticesIndex + 2] = C2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N17[0];
	normals[normalsIndex + 1] = N17[1];
	normals[normalsIndex + 2] = N17[2];
	normalsIndex += 3;
	textures[texturesIndex] = X1;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 17; vertex[3] = B2; normals[1]=N17; textures[3]={X3,Y1};
	vertices[verticesIndex] = B2[0];
	vertices[verticesIndex + 1] = B2[1];
	vertices[verticesIndex + 2] = B2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N17[0];
	normals[normalsIndex + 1] = N17[1];
	normals[normalsIndex + 2] = N17[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 18; vertex[1] = C2; normals[1]=N18; textures[1]={X11,Y1};
	vertices[verticesIndex] = C2[0];
	vertices[verticesIndex + 1] = C2[1];
	vertices[verticesIndex + 2] = C2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N18[0];
	normals[normalsIndex + 1] = N18[1];
	normals[normalsIndex + 2] = N18[2];
	normalsIndex += 3;
	textures[texturesIndex] = X11;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 18; vertex[2] = C1; normals[2]=N18; textures[2]={X9,Y1};
	vertices[verticesIndex] = C1[0];
	vertices[verticesIndex + 1] = C1[1];
	vertices[verticesIndex + 2] = C1[2];
	verticesIndex += 3;
	normals[normalsIndex] = N18[0];
	normals[normalsIndex + 1] = N18[1];
	normals[normalsIndex + 2] = N18[2];
	normalsIndex += 3;
	textures[texturesIndex] = X9;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 18; vertex[3] = A2; normals[3]=N18; textures[3]={X10,Y0};
	vertices[verticesIndex] = A2[0];
	vertices[verticesIndex + 1] = A2[1];
	vertices[verticesIndex + 2] = A2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N18[0];
	normals[normalsIndex + 1] = N18[1];
	normals[normalsIndex + 2] = N18[2];
	normalsIndex += 3;
	textures[texturesIndex] = X10;
	textures[texturesIndex + 1] = Y0;
	texturesIndex += 2;

	// face 19; vertex[1] = C2; normals[1]=N19; textures[1]={X1,Y1};
	vertices[verticesIndex] = C2[0];
	vertices[verticesIndex + 1] = C2[1];
	vertices[verticesIndex + 2] = C2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N19[0];
	normals[normalsIndex + 1] = N19[1];
	normals[normalsIndex + 2] = N19[2];
	normalsIndex += 3;
	textures[texturesIndex] = X1;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 19; vertex[2] = A2; normals[2]=N19; textures[2]={X2,Y0};
	vertices[verticesIndex] = A2[0];
	vertices[verticesIndex + 1] = A2[1];
	vertices[verticesIndex + 2] = A2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N19[0];
	normals[normalsIndex + 1] = N19[1];
	normals[normalsIndex + 2] = N19[2];
	normalsIndex += 3;
	textures[texturesIndex] = X2;
	textures[texturesIndex + 1] = Y0;
	texturesIndex += 2;

	// face 19; vertex[3] = B2; normals[3]=N19; textures[3]={X3,Y1};
	vertices[verticesIndex] = B2[0];
	vertices[verticesIndex + 1] = B2[1];
	vertices[verticesIndex + 2] = B2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N19[0];
	normals[normalsIndex + 1] = N19[1];
	normals[normalsIndex + 2] = N19[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 20; vertex[1] = A2; normals[1]=N20; textures[1]={X4,Y0};
	vertices[verticesIndex] = A2[0];
	vertices[verticesIndex + 1] = A2[1];
	vertices[verticesIndex + 2] = A2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N20[0];
	normals[normalsIndex + 1] = N20[1];
	normals[normalsIndex + 2] = N20[2];
	normalsIndex += 3;
	textures[texturesIndex] = X4;
	textures[texturesIndex + 1] = Y0;
	texturesIndex += 2;

	// face 20; vertex[2] = A3; normals[2]=N20; textures[2]={X5,Y1};
	vertices[verticesIndex] = A3[0];
	vertices[verticesIndex + 1] = A3[1];
	vertices[verticesIndex + 2] = A3[2];
	verticesIndex += 3;
	normals[normalsIndex] = N20[0];
	normals[normalsIndex + 1] = N20[1];
	normals[normalsIndex + 2] = N20[2];
	normalsIndex += 3;
	textures[texturesIndex] = X5;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

	// face 20; vertex[3] = B2; normals[3]=N20; textures[3]={X3,Y1};
	vertices[verticesIndex] = B2[0];
	vertices[verticesIndex + 1] = B2[1];
	vertices[verticesIndex + 2] = B2[2];
	verticesIndex += 3;
	normals[normalsIndex] = N20[0];
	normals[normalsIndex + 1] = N20[1];
	normals[normalsIndex + 2] = N20[2];
	normalsIndex += 3;
	textures[texturesIndex] = X3;
	textures[texturesIndex + 1] = Y1;
	texturesIndex += 2;

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

	InitBuffers();
}