summaryrefslogtreecommitdiffstats
path: root/kue/sphere.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kue/sphere.cpp')
-rw-r--r--kue/sphere.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/kue/sphere.cpp b/kue/sphere.cpp
new file mode 100644
index 00000000..321b8bad
--- /dev/null
+++ b/kue/sphere.cpp
@@ -0,0 +1,61 @@
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#include <math.h>
+#include <tdeconfig.h>
+#include <tdeglobal.h>
+#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();
+}