#include #include #include #include #include #include "sphere.h" const int SPHERE_DISPLAY_LIST = 2; double sphere_list_radius = 0.0; void sphere::draw(double x, double y, double r, double rot_x, double rot_y) { glPushMatrix(); glTranslated(x, y, r); // Rotate the balls the specified the amount glRotated(rot_x, 0.0, 1.0, 0.0); glRotated(rot_y, 1.0, 0.0, 0.0); // Do we have this sphere cached? if ((r == sphere_list_radius) && (glIsList(SPHERE_DISPLAY_LIST) == GL_TRUE)) { // It was cached, call the list glCallList(SPHERE_DISPLAY_LIST); } else { // Figure out the number of sphere divisons we need TDEGlobal::config()->setGroup("Graphics"); int sphere_divisions = TDEGlobal::config()->readNumEntry("Sphere Divisions", 8); // sphere_divisions < 3 causes OpenGL to draw nothing at all, // so clamp to value to 3. if (sphere_divisions < 3) sphere_divisions = 3; // Make the quadratic object GLUquadricObj *quad = gluNewQuadric(); // We need normals for lighting to work gluQuadricNormals(quad, GLU_SMOOTH); // We also need texture points gluQuadricTexture(quad, GL_TRUE); // Create the display list glNewList(SPHERE_DISPLAY_LIST, GL_COMPILE_AND_EXECUTE); // Draw the sphere gluSphere(quad, r, sphere_divisions, sphere_divisions); // End the display list glEndList(); // Update the cached radius sphere_list_radius = r; // Delete quadatric object gluDeleteQuadric(quad); } glPopMatrix(); }