void GenDodecaHedron(GLuint &DodecaDListID, const unsigned int &radius)
{
const float PI = 3.1415926535897932384626433832795f;
const float rads = float(PI / 180.0f);
const GLfloat dist = cos(36.0f * rads) * radius; // distance from the center to the bisection of an outer leg
const GLfloat dihedral_angle = 116.565051177f; // cos^-1(-sqrt(5)/5) ~= 116.565051177
// wtf is a dihedral angle? its the angle between any two adjacent faces of a polyhedra.
// more info: http://whistleralley.com/polyhedra/platonic.htm and http://whistleralley.com/polyhedra/dodecahedron.htm
const GLfloat midradius = 1.30901699438f * radius; // ((sqrt(5)+3)/4) ~= 1.30901699438
// the midradius (center-edge) is the radius from the center of the dodecahedron to the center of a face
// more info on platonic solids: http://davidf.faricy.net/polyhedra/Platonic_Solids.html
GLuint PentDListID = glGenLists(1);
GLuint HalfDodecaDListID = glGenLists(1);
if(glIsList(DodecaDListID) == GL_FALSE)
{
DodecaDListID = glGenLists(1);
}
glNewList(PentDListID, GL_COMPILE);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f, 0.0f, 0.0f);
for(unsigned int x = 0; x < 6; ++x)
{
glVertex3f( radius * sin(float(x * 72) * rads),
radius * cos(float(x * 72) * rads),
0.0f);
}
glEnd();
glEndList();
glNewList(HalfDodecaDListID, GL_COMPILE);
glPushMatrix();
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0f, 0.0f, dist);
glRotatef(dihedral_angle-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, dist, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glPushMatrix();
glRotatef(72.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, dist);
glRotatef(dihedral_angle-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, dist, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glPushMatrix();
glRotatef(-72.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, dist);
glRotatef(dihedral_angle-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, dist, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glPushMatrix();
glRotatef(144.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, dist);
glRotatef(dihedral_angle-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, dist, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glPushMatrix();
glRotatef(-144.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, dist);
glRotatef(dihedral_angle-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, dist, 0.0f);
glCallList(PentDListID);
glPopMatrix();
glEndList();
glNewList(DodecaDListID, GL_COMPILE);
glCallList(HalfDodecaDListID);
glScalef(1.0f, -1.0f, 1.0f);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
glTranslatef( 0.0f,
(midradius * radius) * -2.0f,
0.0f);
glCallList(HalfDodecaDListID);
glEndList();
}
|