// Drawable star --------------------------------------------------------------- #include "drawable_star.h" #include #include using namespace std; // Static class members -------------------------------------------------------- int Star::DisplayListId = -1; // Constructor ----------------------------------------------------------------- Star::Star(const double pX, const double pY, const double pZ) : Drawable(pX, pY, pZ) { if (DisplayListId < 0) { DisplayListId = glGenLists(1); glNewList(DisplayListId, GL_COMPILE); { render(); } glEndList(); } } // Draw ------------------------------------------------------------------------ void Star::draw() { glPushMatrix(); glColor3fv(color); glTranslatef(x, y, z); glCallList(DisplayListId); glPopMatrix(); } // Render ---------------------------------------------------------------------- void Star::render() { glBegin(GL_TRIANGLE_FAN); { double ox = 0.0, oy = 0.0, radius = 10.0; int triangles = 32; glVertex2f(ox, oy); for (int i = 0; i <= triangles; i++) { double angle = i * 2.0 * M_PI / triangles; if (i % 2) radius *= 4; else radius /= 4; glVertex2f(ox + radius * cos(angle), oy + radius * sin(angle)); } } glEnd(); } // vim: set sts=4 sw=4 ts=8 ft=cpp: --------------------------------------------