1 /* xscreensaver, Copyright (c) 2002, 2004 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * Algorithm by Paul Bourke <pbourke@swin.edu.au>
12 * http://astronomy.swin.edu.au/~pbourke/geometry/sphericalh/
13 * Screensaver veneer and parameter selection by jwz.
17 * These closed objects are commonly called spherical harmonics,
18 * although they are only remotely related to the mathematical
19 * definition found in the solution to certain wave functions, most
20 * notable the eigenfunctions of angular momentum operators.
22 * The formula is quite simple: the form used here is based upon
23 * spherical (polar) coordinates (radius, theta, phi).
25 * r = sin(m0 phi) ^ m1 +
27 * sin(m4 theta) ^ m5 +
30 * Where phi ranges from 0 to pi (lines of latitude), and theta ranges
31 * from 0 to 2 pi (lines of longitude), and r is the radius. The
32 * parameters m0, m1, m2, m3, m4, m5, m6, and m7 are all integers
33 * greater than or equal to 0.
35 * As the degree increases, the objects become increasingly "pointed"
36 * and a large number of polygons are required to represent the surface
41 * The eight parameters live in the `cc->m' array.
42 * Each time we permute the image, we alter *one* of those eight parameters.
43 * Each time we alter a parameter, we move it in the same direction (either
44 * toward larger or smaller values) in the range [0, 3].
46 * By altering only one parameter at a time, and only by small amounts,
47 * we tend to produce successive objects that are pretty similar to each
48 * other, so you can see a progression.
50 * It'd be nice if they were even closer together, so that it looked more
51 * like a morph, but, well, that's not how it works.
53 * There tends to be a dark stripe in the colormaps. I don't know why.
54 * Perhaps utils/colors.c is at fault?
56 * Note that this equation sometimes generates faces that are inside out:
57 * -parameters 01210111
58 * To make this work, we need to render back-faces with two-sided lighting:
59 * figuring out how to correct the winding and normals on those inside out
60 * surfaces would be too hard.
63 #include <X11/Intrinsic.h>
65 extern XtAppContext app;
67 #define PROGCLASS "Spheremonics"
68 #define HACK_INIT init_spheremonics
69 #define HACK_DRAW draw_spheremonics
70 #define HACK_RESHAPE reshape_spheremonics
71 #define HACK_HANDLE_EVENT spheremonics_handle_event
72 #define EVENT_MASK PointerMotionMask
73 #define ccs_opts xlockmore_opts
75 #define DEF_DURATION "100"
76 #define DEF_SPIN "XYZ"
77 #define DEF_WANDER "False"
78 #define DEF_RESOLUTION "64"
79 #define DEF_BBOX "False"
80 #define DEF_GRID "True"
81 #define DEF_SMOOTH "True"
82 #define DEF_PARMS "(default)"
84 #define DEFAULTS "*delay: 30000 \n" \
85 "*resolution: " DEF_RESOLUTION "\n" \
86 "*showFPS: False \n" \
87 "*wireframe: False \n" \
88 "*duration: " DEF_DURATION "\n" \
89 "*spin: " DEF_SPIN "\n" \
90 "*wander: " DEF_WANDER "\n" \
91 "*bbox: " DEF_BBOX "\n" \
92 "*grid: " DEF_GRID "\n" \
93 "*smooth: " DEF_SMOOTH "\n" \
94 "*parameters: " DEF_PARMS "\n" \
97 #define countof(x) (sizeof((x))/sizeof((*x)))
99 #include "xlockmore.h"
102 #include "gltrackball.h"
105 #ifdef USE_GL /* whole file */
114 GLXContext *glx_context;
116 trackball_state *trackball;
119 GLuint dlist, dlist2;
133 int polys1, polys2; /* polygon counts */
138 } spheremonics_configuration;
140 static spheremonics_configuration *ccs = NULL;
142 static char *do_spin;
143 static Bool do_wander;
147 static char *static_parms;
151 static XrmOptionDescRec opts[] = {
152 { "-spin", ".spin", XrmoptionSepArg, 0 },
153 { "+spin", ".spin", XrmoptionNoArg, "" },
154 { "-wander", ".wander", XrmoptionNoArg, "True" },
155 { "+wander", ".wander", XrmoptionNoArg, "False" },
156 { "-resolution", ".resolution", XrmoptionSepArg, 0 },
157 { "-duration", ".duration", XrmoptionSepArg, 0 },
158 { "-bbox", ".bbox", XrmoptionNoArg, "True" },
159 { "+bbox", ".bbox", XrmoptionNoArg, "False" },
160 { "-grid", ".grid", XrmoptionNoArg, "True" },
161 { "+grid", ".grid", XrmoptionNoArg, "False" },
162 {"-smooth", ".smooth", XrmoptionNoArg, "True" },
163 {"+smooth", ".smooth", XrmoptionNoArg, "False" },
164 { "-parameters", ".parameters", XrmoptionSepArg, 0 },
167 static argtype vars[] = {
168 {&do_spin, "spin", "Spin", DEF_SPIN, t_String},
169 {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
170 {&res, "resolution", "Resolution", DEF_RESOLUTION, t_Int},
171 {&duration, "duration", "Duration", DEF_DURATION, t_Int},
172 {&do_bbox, "bbox", "BBox", DEF_BBOX, t_Bool},
173 {&do_grid, "grid", "Grid", DEF_GRID, t_Bool},
174 {&smooth_p, "smooth", "Smooth", DEF_SMOOTH, t_Bool},
175 {&static_parms, "parameters", "Parameters", DEF_PARMS, t_String},
178 ModeSpecOpt ccs_opts = {countof(opts), opts, countof(vars), vars, NULL};
181 /* Window management, etc
184 reshape_spheremonics (ModeInfo *mi, int width, int height)
186 GLfloat h = (GLfloat) height / (GLfloat) width;
188 glViewport (0, 0, (GLint) width, (GLint) height);
190 glMatrixMode(GL_PROJECTION);
192 gluPerspective (30.0, 1/h, 1.0, 100.0);
194 glMatrixMode(GL_MODELVIEW);
196 gluLookAt( 0.0, 0.0, 30.0,
200 glClear(GL_COLOR_BUFFER_BIT);
205 gl_init (ModeInfo *mi)
207 /* spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; */
208 int wire = MI_IS_WIREFRAME(mi);
210 static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0};
212 glEnable(GL_NORMALIZE);
216 glLightfv(GL_LIGHT0, GL_POSITION, pos);
217 glEnable(GL_LIGHTING);
219 glEnable(GL_DEPTH_TEST);
221 /* With objects that have proper winding and normals set up on all
222 their faces, one can cull back-faces; however, these equations
223 generate objects that are sometimes "inside out", and determining
224 whether a facet has been inverted like that is really hard.
225 So we render both front and back faces, at a probable performance
226 penalty on non-accelerated systems.
228 When rendering back faces, we also need to do two-sided lighting,
229 or the fact that the normals are flipped gives us too-dark surfaces
230 on the inside-out surfaces.
232 This isn't generally something you'd want, because you end up
233 with half the lighting dynamic range (kind of.) So if you had
234 a sphere with correctly pointing normals, and a single light
235 source, it would be illuminated from two sides. In this case,
236 though, it saves us from a difficult and time consuming
237 inside/outside test. And we don't really care about a precise
240 glDisable(GL_CULL_FACE);
241 glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, TRUE);
247 /* generate the object */
250 sphere_eval (double theta, double phi, int *m)
255 r += pow (sin(m[0] * phi), (double)m[1]);
256 r += pow (cos(m[2] * phi), (double)m[3]);
257 r += pow (sin(m[4] * theta),(double)m[5]);
258 r += pow (cos(m[6] * theta),(double)m[7]);
260 p.x = r * sin(phi) * cos(theta);
262 p.z = r * sin(phi) * sin(theta);
268 /* Normalise a vector */
273 length = sqrt(p->x * p->x + p->y * p->y + p->z * p->z);
285 /*-------------------------------------------------------------------------
286 Calculate the unit normal at p given two other points
287 p1,p2 on the surface. The normal points in the direction
288 of p1 crossproduct p2
291 calc_normal (XYZ p, XYZ p1, XYZ p2)
300 n.x = pa.y * pb.z - pa.z * pb.y;
301 n.y = pa.z * pb.x - pa.x * pb.z;
302 n.z = pa.x * pb.y - pa.y * pb.x;
309 do_color (int i, XColor *colors)
312 c[0] = colors[i].red / 65535.0;
313 c[1] = colors[i].green / 65535.0;
314 c[2] = colors[i].blue / 65535.0;
316 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c);
317 glColor3f (c[0], c[1], c[2]);
322 draw_circle (ModeInfo *mi, Bool teeth_p)
327 GLfloat step = (M_PI / 180);
329 glBegin(GL_LINE_LOOP);
330 for (th = 0; th < M_PI*2; th += step*5)
335 glVertex3f(x*r1, y*r1, 0);
339 if (!teeth_p) return;
342 for (th = 0; th < M_PI*2; th += step)
345 GLfloat r2 = r1 - 0.01;
348 else if (! (tick % 5))
354 glVertex3f(x*r1, y*r1, 0);
355 glVertex3f(x*r2, y*r2, 0);
362 draw_bounding_box (ModeInfo *mi)
364 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
366 static GLfloat c1[4] = { 0.2, 0.2, 0.6, 1.0 };
367 static GLfloat c2[4] = { 1.0, 0.0, 0.0, 1.0 };
368 int wire = MI_IS_WIREFRAME(mi);
370 GLfloat x1 = cc->bbox[0].x;
371 GLfloat y1 = cc->bbox[0].y;
372 GLfloat z1 = cc->bbox[0].z;
373 GLfloat x2 = cc->bbox[1].x;
374 GLfloat y2 = cc->bbox[1].y;
375 GLfloat z2 = cc->bbox[1].z;
382 if (do_bbox && !wire)
384 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c1);
387 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
389 glVertex3f(x1, y1, z1); glVertex3f(x1, y1, z2);
390 glVertex3f(x2, y1, z2); glVertex3f(x2, y1, z1);
392 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
393 glNormal3f(0, -1, 0);
394 glVertex3f(x2, y2, z1); glVertex3f(x2, y2, z2);
395 glVertex3f(x1, y2, z2); glVertex3f(x1, y2, z1);
397 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
399 glVertex3f(x1, y1, z1); glVertex3f(x2, y1, z1);
400 glVertex3f(x2, y2, z1); glVertex3f(x1, y2, z1);
402 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
403 glNormal3f(0, 0, -1);
404 glVertex3f(x1, y2, z2); glVertex3f(x2, y2, z2);
405 glVertex3f(x2, y1, z2); glVertex3f(x1, y1, z2);
407 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
409 glVertex3f(x1, y2, z1); glVertex3f(x1, y2, z2);
410 glVertex3f(x1, y1, z2); glVertex3f(x1, y1, z1);
412 glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
413 glNormal3f(-1, 0, 0);
414 glVertex3f(x2, y1, z1); glVertex3f(x2, y1, z2);
415 glVertex3f(x2, y2, z2); glVertex3f(x2, y2, z1);
419 glPushAttrib (GL_LIGHTING);
420 glDisable (GL_LIGHTING);
422 glColor3f (c2[0], c2[1], c2[2]);
428 glVertex3f(0, -0.66, 0);
429 glVertex3f(0, 0.66, 0);
431 draw_circle (mi, True);
432 glRotatef(90, 1, 0, 0);
433 draw_circle (mi, True);
434 glRotatef(90, 0, 1, 0);
435 draw_circle (mi, True);
441 if (x1 > 0) x1 = 0; if (x2 < 0) x2 = 0;
442 if (y1 > 0) y1 = 0; if (y2 < 0) y2 = 0;
443 if (z1 > 0) z1 = 0; if (z2 < 0) z2 = 0;
444 glVertex3f(x1, 0, 0); glVertex3f(x2, 0, 0);
445 glVertex3f(0 , y1, 0); glVertex3f(0, y2, 0);
446 glVertex3f(0, 0, z1); glVertex3f(0, 0, z2);
455 do_tracer (ModeInfo *mi)
457 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
459 if (cc->tracer == -1 &&
461 !(random() % (duration * 4)))
464 cc->tracer = ((random() & 1) ? 0 : 180);
466 cc->mesher = ((random() % ((duration / 3) + 1)) +
467 (random() % ((duration / 3) + 1)));
472 int d = (90 - cc->tracer);
473 GLfloat th = d * (M_PI / 180);
474 GLfloat x = cos (th);
475 GLfloat y = sin (th);
476 GLfloat s = 1.5 / cc->scale;
480 static GLfloat c[4] = { 0.6, 0.5, 1.0, 1.0 };
482 glPushAttrib (GL_LIGHTING);
483 glDisable (GL_LIGHTING);
486 glRotatef (90, 1, 0, 0);
487 glTranslatef (0, 0, y*s/2);
490 glColor3f (c[0], c[1], c[2]);
491 draw_circle (mi, False);
498 if (cc->tracer == 180 || cc->tracer == 360)
505 unit_spheremonics (ModeInfo *mi,
506 int resolution, Bool wire, int *m, XColor *colors)
508 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
518 cc->bbox[0].x = cc->bbox[0].y = cc->bbox[0].z = 0;
519 cc->bbox[1].x = cc->bbox[1].y = cc->bbox[1].z = 0;
521 du = (M_PI+M_PI) / (double)res; /* Theta */
522 dv = M_PI / (double)res; /* Phi */
527 glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
529 for (i = 0; i < res; i++) {
531 for (j = 0; j < res; j++) {
533 q[0] = sphere_eval (u, v, m);
534 n[0] = calc_normal(q[0],
535 sphere_eval (u+du/10, v, m),
536 sphere_eval (u, v+dv/10, m));
537 glNormal3f(n[0].x,n[0].y,n[0].z);
538 if (!wire) do_color (i, colors);
539 glVertex3f(q[0].x,q[0].y,q[0].z);
541 q[1] = sphere_eval (u+du, v, m);
542 n[1] = calc_normal(q[1],
543 sphere_eval (u+du+du/10, v, m),
544 sphere_eval (u+du, v+dv/10, m));
545 glNormal3f(n[1].x,n[1].y,n[1].z);
546 if (!wire) do_color ((i+1)%res, colors);
547 glVertex3f(q[1].x,q[1].y,q[1].z);
549 q[2] = sphere_eval (u+du, v+dv, m);
550 n[2] = calc_normal(q[2],
551 sphere_eval (u+du+du/10, v+dv, m),
552 sphere_eval (u+du, v+dv+dv/10, m));
553 glNormal3f(n[2].x,n[2].y,n[2].z);
554 if (!wire) do_color ((i+1)%res, colors);
555 glVertex3f(q[2].x,q[2].y,q[2].z);
557 q[3] = sphere_eval (u,v+dv, m);
558 n[3] = calc_normal(q[3],
559 sphere_eval (u+du/10, v+dv, m),
560 sphere_eval (u, v+dv+dv/10, m));
561 glNormal3f(n[3].x,n[3].y,n[3].z);
562 if (!wire) do_color (i, colors);
563 glVertex3f(q[3].x,q[3].y,q[3].z);
567 # define CHECK_BBOX(N) \
568 if (q[(N)].x < cc->bbox[0].x) cc->bbox[0].x = q[(N)].x; \
569 if (q[(N)].y < cc->bbox[0].y) cc->bbox[0].y = q[(N)].y; \
570 if (q[(N)].z < cc->bbox[0].z) cc->bbox[0].z = q[(N)].z; \
571 if (q[(N)].x > cc->bbox[1].x) cc->bbox[1].x = q[(N)].x; \
572 if (q[(N)].y > cc->bbox[1].y) cc->bbox[1].y = q[(N)].y; \
573 if (q[(N)].z > cc->bbox[1].z) cc->bbox[1].z = q[(N)].z
585 GLfloat w = cc->bbox[1].x - cc->bbox[0].x;
586 GLfloat h = cc->bbox[1].y - cc->bbox[0].y;
587 GLfloat d = cc->bbox[1].z - cc->bbox[0].z;
588 GLfloat wh = (w > h ? w : h);
589 GLfloat hd = (h > d ? h : d);
590 GLfloat scale = (wh > hd ? wh : hd);
594 if (wire < 2 && (do_bbox || do_grid))
596 GLfloat s = scale * 1.5;
599 draw_bounding_box (mi);
608 init_colors (ModeInfo *mi)
610 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
612 cc->ncolors = cc->resolution;
613 cc->colors = (XColor *) calloc(cc->ncolors, sizeof(XColor));
614 make_smooth_colormap (0, 0, 0,
615 cc->colors, &cc->ncolors,
618 /* brighter colors, please... */
619 for (i = 0; i < cc->ncolors; i++)
621 cc->colors[i].red = (cc->colors[i].red / 2) + 32767;
622 cc->colors[i].green = (cc->colors[i].green / 2) + 32767;
623 cc->colors[i].blue = (cc->colors[i].blue / 2) + 32767;
628 /* Pick one of the parameters to the function and tweak it up or down.
631 tweak_parameters (ModeInfo *mi)
633 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
635 /* If the -parameters command line option was specified, just use that
640 !!strcasecmp (static_parms, "(default)"))
644 if (8 == sscanf (static_parms, "%d %d %d %d %d %d %d %d %c",
645 &cc->m[0], &cc->m[1], &cc->m[2], &cc->m[3],
646 &cc->m[4], &cc->m[5], &cc->m[6], &cc->m[7],
649 else if (strlen (static_parms) == 8 &&
650 1 == sscanf (static_parms, "%lu %c", &n, &dummy))
652 const char *s = static_parms;
655 cc->m[i++] = (*s++)-'0';
659 "%s: -parameters must be a string of 8 ints (not \"%s\")\n",
660 progname, static_parms);
667 # define SHIFT(N) do { \
669 cc->m[n] += cc->dm[n]; \
671 cc->m[n] = 0, cc->dm[n] = -cc->dm[n]; \
672 else if (cc->m[n] >= cc->m_max) \
673 cc->m[n] = cc->m_max, cc->dm[n] = -cc->dm[n]; \
676 /* else if (cc->m[n] >= cc->m_max/2 && (! (random() % 3))) \
677 cc->m[n] = cc->m_max/2, cc->dm[n] = -cc->dm[n]; \
682 case 0: SHIFT(0); break;
683 case 1: SHIFT(1); break;
684 case 2: SHIFT(2); break;
685 case 3: SHIFT(3); break;
686 case 4: SHIFT(4); break;
687 case 5: SHIFT(5); break;
688 case 6: SHIFT(6); break;
689 case 7: SHIFT(7); break;
690 default: abort(); break;
695 printf ("%s: state: %d %d %d %d %d %d %d %d\n",
697 cc->m[0], cc->m[1], cc->m[2], cc->m[3],
698 cc->m[4], cc->m[5], cc->m[6], cc->m[7]);
705 generate_spheremonics (ModeInfo *mi)
707 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
708 int wire = MI_IS_WIREFRAME(mi);
710 tweak_parameters (mi);
713 static Bool done = False;
714 if (!done || (0 == (random() % 20)))
722 glNewList(cc->dlist, GL_COMPILE);
723 cc->polys1 = unit_spheremonics (mi, cc->resolution, wire,cc->m,cc->colors);
726 glNewList(cc->dlist2, GL_COMPILE);
727 glPushAttrib (GL_LIGHTING);
728 glDisable (GL_LIGHTING);
730 glScalef (1.05, 1.05, 1.05);
731 cc->polys2 = unit_spheremonics (mi, cc->resolution, 2, cc->m, cc->colors);
742 load_font (ModeInfo *mi, char *res, XFontStruct **fontP, GLuint *dlistP)
744 const char *font = get_string_resource (res, "Font");
749 if (!font) font = "-*-times-bold-r-normal-*-140-*";
751 f = XLoadQueryFont(mi->dpy, font);
752 if (!f) f = XLoadQueryFont(mi->dpy, "fixed");
755 first = f->min_char_or_byte2;
756 last = f->max_char_or_byte2;
759 *dlistP = glGenLists ((GLuint) last+1);
760 check_gl_error ("glGenLists");
761 glXUseXFont(id, first, last-first+1, *dlistP + first);
762 check_gl_error ("glXUseXFont");
768 draw_label (ModeInfo *mi, const char *s)
770 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
773 glPushAttrib(GL_TRANSFORM_BIT | GL_ENABLE_BIT);
774 glDisable(GL_LIGHTING);
775 glDisable(GL_DEPTH_TEST);
776 glMatrixMode(GL_PROJECTION);
779 glMatrixMode(GL_MODELVIEW);
782 gluOrtho2D(0, mi->xgwa.width, 0, mi->xgwa.height);
783 glColor3f(1.0, 1.0, 0.0);
788 - (cc->font->ascent + cc->font->descent)));
789 for (i = 0; i < strlen(s); i++)
790 glCallList (cc->font_list + (int)s[i]);
793 glMatrixMode(GL_PROJECTION);
802 init_spheremonics (ModeInfo *mi)
804 spheremonics_configuration *cc;
807 ccs = (spheremonics_configuration *)
808 calloc (MI_NUM_SCREENS(mi), sizeof (spheremonics_configuration));
810 fprintf(stderr, "%s: out of memory\n", progname);
814 cc = &ccs[MI_SCREEN(mi)];
817 cc = &ccs[MI_SCREEN(mi)];
819 if ((cc->glx_context = init_GL(mi)) != NULL) {
821 reshape_spheremonics (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
826 glEnable (GL_LINE_SMOOTH);
827 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
828 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
833 Bool spinx=False, spiny=False, spinz=False;
834 double spin_speed = 1.0;
835 double wander_speed = 0.03;
840 if (*s == 'x' || *s == 'X') spinx = True;
841 else if (*s == 'y' || *s == 'Y') spiny = True;
842 else if (*s == 'z' || *s == 'Z') spinz = True;
846 "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
853 cc->rot = make_rotator (spinx ? spin_speed : 0,
854 spinz ? spin_speed : 0,
855 spiny ? spin_speed : 0,
857 do_wander ? wander_speed : 0,
858 (spinx && spiny && spinz));
859 cc->trackball = gltrackball_init ();
865 cc->resolution = res;
867 load_font (mi, "labelfont", &cc->font, &cc->font_list);
869 cc->dlist = glGenLists(1);
870 cc->dlist2 = glGenLists(1);
872 cc->m_max = 4; /* 9? */
875 for (i = 0; i < countof(cc->dm); i++)
876 cc->dm[i] = 1; /* going up! */
878 /* Generate a few more times so we don't always start off with a sphere */
879 for (i = 0; i < 5; i++)
880 tweak_parameters (mi);
883 generate_spheremonics(mi);
888 spheremonics_handle_event (ModeInfo *mi, XEvent *event)
890 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
892 if (event->xany.type == ButtonPress &&
893 event->xbutton.button & Button1)
895 cc->button_down_p = True;
896 gltrackball_start (cc->trackball,
897 event->xbutton.x, event->xbutton.y,
898 MI_WIDTH (mi), MI_HEIGHT (mi));
901 else if (event->xany.type == ButtonRelease &&
902 event->xbutton.button & Button1)
904 cc->button_down_p = False;
907 else if (event->xany.type == MotionNotify &&
910 gltrackball_track (cc->trackball,
911 event->xmotion.x, event->xmotion.y,
912 MI_WIDTH (mi), MI_HEIGHT (mi));
921 draw_spheremonics (ModeInfo *mi)
923 spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)];
924 Display *dpy = MI_DISPLAY(mi);
925 Window window = MI_WINDOW(mi);
927 if (!cc->glx_context)
930 glShadeModel(GL_SMOOTH);
932 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
936 glScalef(1.1, 1.1, 1.1);
940 get_position (cc->rot, &x, &y, &z, !cc->button_down_p);
941 glTranslatef((x - 0.5) * 8,
945 gltrackball_rotate (cc->trackball);
947 get_rotation (cc->rot, &x, &y, &z, !cc->button_down_p);
948 glRotatef (x * 360, 1.0, 0.0, 0.0);
949 glRotatef (y * 360, 0.0, 1.0, 0.0);
950 glRotatef (z * 360, 0.0, 0.0, 1.0);
955 mi->polygon_count = 0;
957 glScalef (cc->scale, cc->scale, cc->scale);
958 glCallList (cc->dlist);
959 mi->polygon_count += cc->polys1;
961 if (cc->mesher >= 0 /* || mouse_p */)
963 glCallList (cc->dlist2);
964 mi->polygon_count += cc->polys2;
971 if (cc->button_down_p)
975 ((cc->m[0]<10 && cc->m[1]<10 && cc->m[2]<10 && cc->m[3]<10 &&
976 cc->m[4]<10 && cc->m[5]<10 && cc->m[6]<10 && cc->m[7]<10)
978 : "%d %d %d %d %d %d %d %d"),
979 cc->m[0], cc->m[1], cc->m[2], cc->m[3],
980 cc->m[4], cc->m[5], cc->m[6], cc->m[7]);
981 draw_label (mi, buf);
987 if (tick++ >= duration && !cc->button_down_p)
989 generate_spheremonics(mi);
991 cc->mesher = -1; /* turn off the mesh when switching objects */
997 if (mi->fps_p) do_fps (mi);
1000 glXSwapBuffers(dpy, window);