http://www.jwz.org/xscreensaver/xscreensaver-5.07.tar.gz
[xscreensaver] / hacks / glx / hypertorus.c
index 9c9132b32a5131ef7010804947e8da87a887e1f3..17f948f144a0d8a3cef3b56122b1402428cbad8b 100644 (file)
@@ -4,7 +4,7 @@
 static const char sccsid[] = "@(#)hypertorus.c  1.2 05/09/28 xlockmore";
 #endif
 
-/* Copyright (c) 2003-2005 Carsten Steger <carsten@mirsanmir.org>. */
+/* Copyright (c) 2003-2007 Carsten Steger <carsten@mirsanmir.org>. */
 
 /*
  * Permission to use, copy, modify, and distribute this software and its
@@ -23,6 +23,7 @@ static const char sccsid[] = "@(#)hypertorus.c  1.2 05/09/28 xlockmore";
  * C. Steger - 03/05/18: Initial version
  * C. Steger - 05/09/28: Added the spirals appearance mode
  *                       and trackball support
+ * C. Steger - 07/01/23: Improved 4d trackball support
  */
 
 /*
@@ -105,7 +106,7 @@ static const char sccsid[] = "@(#)hypertorus.c  1.2 05/09/28 xlockmore";
 #define DTHETA                     2.1
 #define DTHETA_STR                "2.1"
 
-#define DEF_DISPLAY_MODE           DISP_SURFACE_STR   
+#define DEF_DISPLAY_MODE           DISP_TRANSPARENT_STR
 #define DEF_APPEARANCE             APPEARANCE_BANDS_STR
 #define DEF_COLORS                 COLORS_COLORWHEEL_STR
 #define DEF_3D_PROJECTION          DISP_3D_PERSPECTIVE_STR
@@ -403,8 +404,8 @@ static void rotateall(float al, float be, float de, float ze, float et,
   rotatewx(m,al);
   rotatewy(m,be);
   rotatewz(m,de);
-  rotatexy(m,ze);
   rotatexz(m,et);
+  rotatexy(m,ze);
   rotateyz(m,th);
 }
 
@@ -448,11 +449,11 @@ static void quats_to_rotmat(float p[4], float q[4], float m[4][4])
   r12 = 2.0*(q[1]*q[2]+q[0]*q[3]);
   r22 = 1.0-2.0*(q[1]*q[1]+q[0]*q[0]);
 
-  ze = atan2(-r12,r22)*180.0/M_PI;
-  et = atan2(r02,sqrt(r00*r00+r01*r01))*180.0/M_PI;
-  th = atan2(-r01,r00)*180.0/M_PI;
+  et = atan2(-r12,r22)*180.0/M_PI;
+  th = atan2(r02,sqrt(r00*r00+r01*r01))*180.0/M_PI;
+  ze = atan2(-r01,r00)*180.0/M_PI;
 
-  rotateall(al,be,de,ze,et,th,m);
+  rotateall(al,be,de,ze,et,-th,m);
 }
 
 
@@ -520,9 +521,10 @@ static void color(double angle)
    will only work correctly if numu and numv are set to 64 or any higher
    power of 2.  Similarly, the banded appearance will only work correctly
    if numu and numv are divisible by 4. */
-static void hypertorus(ModeInfo *mi, double umin, double umax, double vmin,
+static int hypertorus(ModeInfo *mi, double umin, double umax, double vmin,
                        double vmax, int numu, int numv)
 {
+  int polys = 0;
   static const GLfloat mat_diff_red[]         = { 1.0, 0.0, 0.0, 1.0 };
   static const GLfloat mat_diff_green[]       = { 0.0, 1.0, 0.0, 1.0 };
   static const GLfloat mat_diff_trans_red[]   = { 1.0, 0.0, 0.0, 0.7 };
@@ -650,10 +652,13 @@ static void hypertorus(ModeInfo *mi, double umin, double umax, double vmin,
         n[2] /= t;
         glNormal3fv(n);
         glVertex3fv(p);
+        polys++;
       }
     }
     glEnd();
   }
+  polys /= 2;
+  return polys;
 }
 
 
@@ -792,7 +797,7 @@ static void display_hypertorus(ModeInfo *mi)
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
 
-  hypertorus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI,64,64);
+  mi->polygon_count = hypertorus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI,64,64);
 }