Skip to content

Instantly share code, notes, and snippets.

@trentbrooks
Created October 28, 2013 23:26
Show Gist options
  • Save trentbrooks/7206615 to your computer and use it in GitHub Desktop.
Save trentbrooks/7206615 to your computer and use it in GitHub Desktop.
Icosahedron
ofMesh ico = createIcosahedron(120);
ofMesh testApp::createIcosahedron(float size) {
ofMesh mesh;
GLdouble vertexB[][3]= {
{0, -0.525731, 0.850651}, // vertices[0]
{0.850651, 0, 0.525731}, // vertices[1]
{0.850651, 0, -0.525731}, // vertices[2]
{-0.850651, 0, -0.525731}, // vertices[3]
{-0.850651, 0, 0.525731}, // vertices[4]
{-0.525731, 0.850651, 0}, // vertices[5]
{0.525731, 0.850651, 0}, // vertices[6]
{0.525731, -0.850651, 0}, // vertices[7]
{-0.525731, -0.850651, 0}, // vertices[8]
{0, -0.525731, -0.850651}, // vertices[9]
{0, 0.525731, -0.850651}, // vertices[10]
{0, 0.525731, 0.850651} // vertices[11]
};
GLdouble colorsB[][4] = {
{1.0, 0.0, 0.0, 1.0},
{1.0, 0.5, 0.0, 1.0},
{1.0, 1.0, 0.0, 1.0},
{0.5, 1.0, 0.0, 1.0},
{0.0, 1.0, 0.0, 1.0},
{0.0, 1.0, 0.5, 1.0},
{0.0, 1.0, 1.0, 1.0},
{0.0, 0.5, 1.0, 1.0},
{0.0, 0.0, 1.0, 1.0},
{0.5, 0.0, 1.0, 1.0},
{1.0, 0.0, 1.0, 1.0},
{1.0, 0.0, 0.5, 1.0}
};
// indicates the order
// 20 triangle faces & 3 points = 60
// sucks we have to use this
// what are the defautls
static const GLubyte icosahedronFaces[] = {
1, 2, 6,
1, 7, 2,
3, 4, 5,
4, 3, 8,
6, 5, 11,
5, 6, 10,
9, 10, 2,
10, 9, 3,
7, 8, 9,
8, 7, 0,
11, 0, 1,
0, 11, 4,
6, 2, 10,
1, 6, 11,
3, 5, 10,
5, 4, 11,
2, 7, 9,
7, 1, 0,
3, 9, 8,
4, 8, 0,
};
GLdouble normalB[][3] = {
{0.000000, -0.417775, 0.675974},
{0.675973, 0.000000, 0.417775},
{0.675973, -0.000000, -0.417775},
{-0.675973, 0.000000, -0.417775},
{-0.675973, -0.000000, 0.417775},
{-0.417775, 0.675974, 0.000000},
{0.417775, 0.675973, -0.000000},
{0.417775, -0.675974, 0.000000},
{-0.417775, -0.675974, 0.000000},
{0.000000, -0.417775, -0.675973},
{0.000000, 0.417775, -0.675974},
{0.000000, 0.417775, 0.675973}
}; //36
for(int i = 0 ; i < 12; i++) {
// vertex
ofVec3f v;
v.x = vertexB[i][0] * size;
v.y = vertexB[i][1] * size;
v.z = vertexB[i][2] * size;
mesh.addVertex(v);
// normal- meeded for lighting
ofVec3f n;
n.x = normalB[i][0];// * 100;
n.y = normalB[i][1];// * 100;
n.z = normalB[i][2];// * 100;
mesh.addNormal(n);
// color
ofFloatColor c;
c.set( colorsB[i][0], colorsB[i][1], colorsB[i][2], 1.0f);
mesh.addColor( c );
}
for(int i = 0 ; i < 60; i++) {
mesh.addIndex(icosahedronFaces[i]);
}
return mesh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment