the red book uses a 2dimensional array.. when i change to a 1dimensional the data is all messed up..
weird..
GLuint * IcoPoly;
GLfloat * IcoVert;
GLfloat * IcoNorm;
GLuint tindices[] = { 0,4,1, 0,9,4, 9,5,4, 4,5,8, 4,8,1,
8,10,1, 8,3,10, 5,3,8, 5,2,3, 2,7,3,
7,10,3, 7,6,10, 7,11,6, 11,0,6, 0,1,6,
6,1,10, 9,0,11, 9,11,2, 9,2,5, 7,2,11 };
..
void InitIcosaHedron() {
#define X .525731112119133606
#define Z .850650808352039932
IcoPoly = new GLuint[20*3];
IcoVert = new GLfloat[12*3];
IcoNorm = new GLfloat[12*3];
IcoNorm[ 0] = (GLfloat) -X; IcoNorm[ 1] = (GLfloat) 0.0; IcoNorm[ 2] = (GLfloat) Z;
IcoNorm[ 3] = (GLfloat) X; IcoNorm[ 4] = (GLfloat) 0.0; IcoNorm[ 5] = (GLfloat) Z;
IcoNorm[ 6] = (GLfloat) -X; IcoNorm[ 7] = (GLfloat) 0.0; IcoNorm[ 8] = (GLfloat) -Z;
IcoNorm[ 9] = (GLfloat) X; IcoNorm[10] = (GLfloat) 0.0; IcoNorm[11] = (GLfloat) -Z;
IcoNorm[12] = (GLfloat) 0.0; IcoNorm[13] = (GLfloat) Z; IcoNorm[14] = (GLfloat) X;
IcoNorm[15] = (GLfloat) 0.0; IcoNorm[16] = (GLfloat) Z; IcoNorm[17] = (GLfloat) -X;
IcoNorm[18] = (GLfloat) 0.0; IcoNorm[19] = (GLfloat) -Z; IcoNorm[20] = (GLfloat) X;
IcoNorm[21] = (GLfloat) 0.0; IcoNorm[22] = (GLfloat) -Z; IcoNorm[23] = (GLfloat) -X;
IcoNorm[24] = (GLfloat) Z; IcoNorm[25] = (GLfloat) X; IcoNorm[26] = (GLfloat) 0.0;
IcoNorm[27] = (GLfloat) -Z; IcoNorm[28] = (GLfloat) X; IcoNorm[29] = (GLfloat) 0.0;
IcoNorm[30] = (GLfloat) Z; IcoNorm[31] = (GLfloat) -X; IcoNorm[32] = (GLfloat) 0.0;
IcoNorm[33] = (GLfloat) -Z; IcoNorm[34] = (GLfloat) -X; IcoNorm[35] = (GLfloat) 0.0;
int i;
for (i = 0; i < 12; i++) {
IcoVert[i*3+0] = IcoNorm[i*3+0];
IcoVert[i*3+1] = IcoNorm[i*3+1];
IcoVert[i*3+2] = IcoNorm[i*3+2];
}
float scale = 20.0f;
for (i = 0; i < 12; i++) {
IcoVert[i*3+0] *= scale;
IcoVert[i*3+1] *= scale;
IcoVert[i*3+2] *= scale;
}
}
void DrawIcosaHedron(int smooth) {
int i;
GLfloat v1[3];
glBegin(GL_TRIANGLES);
for (i = 0; i < 20; i++) {
v1[0] = ( IcoNorm[tindices[i*3+0]+0] + IcoNorm[tindices[i*3+1]+0] + IcoNorm[tindices[i*3+2]+0] ) / 3.0f;
v1[1] = ( IcoNorm[tindices[i*3+0]+1] + IcoNorm[tindices[i*3+1]+1] + IcoNorm[tindices[i*3+2]+1] ) / 3.0f;
v1[2] = ( IcoNorm[tindices[i*3+0]+2] + IcoNorm[tindices[i*3+1]+2] + IcoNorm[tindices[i*3+2]+2] ) / 3.0f;
ReduceToUnit(v1);
glNormal3f(v1[0], v1[1], v1[2]);
if(smooth)
glNormal3f( IcoNorm[tindices[i*3+0]+0], IcoNorm[tindices[i*3+0]+1], IcoNorm[tindices[i*3+0]+2] );
glVertex3f( IcoVert[tindices[i*3+0]+0], IcoVert[tindices[i*3+0]+1], IcoVert[tindices[i*3+0]+2] );
if(smooth)
glNormal3f( IcoNorm[tindices[i*3+1]+0], IcoNorm[tindices[i*3+1]+1], IcoNorm[tindices[i*3+1]+2] );
glVertex3f( IcoVert[tindices[i*3+1]+0], IcoVert[tindices[i*3+1]+1], IcoVert[tindices[i*3+1]+2] );
if(smooth)
glNormal3f( IcoNorm[tindices[i*3+2]+0], IcoNorm[tindices[i*3+2]+1], IcoNorm[tindices[i*3+2]+2] );
glVertex3f( IcoVert[tindices[i*3+2]+0], IcoVert[tindices[i*3+2]+1], IcoVert[tindices[i*3+2]+2] );
}
glEnd();
}
The vertices looks like they are placed right but the rest is garbage..