1 /* jigglypuff - a most, most, unfortunate screensaver.
3 * Copyright (c) 2003 Keith Macleod (kmacleod@primus.ca)
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation. No representations are made about the suitability of this
10 * software for any purpose. It is provided "as is" without express or
13 * Draws all varieties of obscene, spastic, puffy balls
14 * orbiting lazily about the screen. More of an accident
17 * Apologies to anyone who thought they were getting a Pokemon
20 * Of course, if you modify it to do something interesting and/or
21 * funny, I'd appreciate receiving a copy.
23 * 04/06/2003 - Oops, figured out what was wrong with the sphere
24 * mapping. I had assumed it was done in model space,
25 * but of course I was totally wrong... Eye space you
28 * 03/31/2003 - Added chrome to the color options. The mapping
29 * is anything but 'correct', but it's a pretty good
30 * effect anyways, as long as the surface is jiggling
31 * enough that you can't tell. Sure, it seems kind of odd
32 * that it's reflecting a sky that's obviously not there,
33 * but who has time to worry about silly details like
34 * that? Not me, ah rekkin'. km
38 #include <X11/Intrinsic.h>
41 # define PROGCLASS "Jigglypuff"
42 # define HACK_INIT init_jigglypuff
43 # define HACK_DRAW draw_jigglypuff
44 # define HACK_RESHAPE reshape_jigglypuff
45 # define HACK_HANDLE_EVENT jigglypuff_handle_event
46 # define EVENT_MASK PointerMotionMask
47 # define jigglypuff_opts xlockmore_opts
49 #define DEF_COLOR "cycle"
50 #define DEF_SHININESS "100"
51 #define DEF_COMPLEXITY "2"
52 #define DEF_SPEED "500"
53 #define DEF_DISTANCE "100"
54 #define DEF_HOLD "800"
55 #define DEF_SPHERISM "75"
56 #define DEF_DAMPING "500"
58 # define DEFAULTS "*delay: 20000\n" \
60 "*wireframe: False\n" \
71 # include "xlockmore.h"
80 #include "xpm-ximage.h"
81 #include "gltrackball.h"
82 #include "../images/jigglymap.xpm"
88 #define max(a,b) (((a)>(b))?(a):(b))
89 #define min(a,b) (((a)<(b))?(a):(b))
92 /* Why isn't RAND_MAX correct in the first place? */
93 #define REAL_RAND_MAX (2.0*(float)RAND_MAX)
100 static int complexity;
103 static int do_tetrahedron;
106 static int shininess;
108 static int random_parms;
110 typedef struct solid solid;
113 float stable_distance;
115 float spherify_strength;
116 float damping_velocity;
117 float damping_factor;
123 GLfloat jiggly_color[4];
124 GLfloat color_dir[3];
128 trackball_state *trackball;
135 GLXContext *glx_context;
138 static jigglystruct *jss = NULL;
140 static XrmOptionDescRec opts[] = {
141 {"-random", ".Jigglypuff.random", XrmoptionNoArg, (caddr_t)"true"},
142 {"+random", ".Jigglypuff.random", XrmoptionNoArg, (caddr_t)"false"},
143 {"-tetra", ".Jigglypuff.tetra", XrmoptionNoArg, (caddr_t)"true"},
144 {"+tetra", ".Jigglypuff.tetra", XrmoptionNoArg, (caddr_t)"false"},
145 {"-spooky", ".Jigglypuff.spooky", XrmoptionSepArg, (caddr_t)"0"},
146 {"-color", ".Jigglypuff.color", XrmoptionSepArg, (caddr_t)DEF_COLOR},
147 {"-shininess", ".Jigglypuff.shininess", XrmoptionSepArg, (caddr_t)DEF_SHININESS},
148 {"-complexity", ".Jigglypuff.complexity", XrmoptionSepArg, (caddr_t)DEF_COMPLEXITY},
149 {"-speed", ".Jigglypuff.speed", XrmoptionSepArg, (caddr_t)DEF_SPEED},
150 {"-spherism", ".Jigglypuff.spherism", XrmoptionSepArg, (caddr_t)DEF_SPHERISM},
151 {"-hold", ".Jigglypuff.hold", XrmoptionSepArg, (caddr_t)DEF_HOLD},
152 {"-distance", "Jigglypuff.distance", XrmoptionSepArg, (caddr_t)DEF_DISTANCE},
153 {"-damping", "Jigglypuff.damping", XrmoptionSepArg, (caddr_t)DEF_DAMPING}
156 static argtype vars[] = {
157 {(caddr_t*)&random_parms, "random", "Random", "False", t_Bool},
158 {(caddr_t*)&do_tetrahedron, "tetra", "Tetra", "False", t_Bool},
159 {(caddr_t*)&spooky, "spooky", "Spooky", "0", t_Int},
160 {(caddr_t*)&color, "color", "Color", DEF_COLOR, t_String},
161 {(caddr_t*)&shininess, "shininess", "Shininess", DEF_SHININESS, t_Int},
162 {(caddr_t*)&complexity, "complexity", "Complexity", DEF_COMPLEXITY, t_Int},
163 {(caddr_t*)&speed, "speed", "Speed", DEF_SPEED, t_Int},
164 {(caddr_t*)&spherism, "spherism", "Spherism", DEF_SPHERISM, t_Int},
165 {(caddr_t*)&hold, "hold", "Hold", DEF_HOLD, t_Int},
166 {(caddr_t*)&distance, "distance", "Distance", DEF_DISTANCE, t_Int},
167 {(caddr_t*)&damping, "damping", "Damping", DEF_DAMPING, t_Int}
171 #define countof(x) ((int)(sizeof(x)/sizeof(*(x))))
173 ModeSpecOpt jigglypuff_opts = {countof(opts), opts, countof(vars), vars, NULL};
175 #define COLOR_STYLE_NORMAL 0
176 #define COLOR_STYLE_CYCLE 1
177 #define COLOR_STYLE_CLOWNBARF 2
178 #define COLOR_STYLE_FLOWERBOX 3
179 #define COLOR_STYLE_CHROME 4
181 #define CLOWNBARF_NCOLORS 5
183 static GLfloat clownbarf_colors[CLOWNBARF_NCOLORS][4] = {
184 {0.7, 0.7, 0.0, 1.0},
185 {0.8, 0.1, 0.1, 1.0},
186 {0.1, 0.1, 0.8, 1.0},
187 {0.9, 0.9, 0.9, 1.0},
191 static GLfloat flowerbox_colors[4][4] = {
192 {0.7, 0.7, 0.0, 1.0},
193 {0.9, 0.0, 0.0, 1.0},
194 {0.0, 0.9, 0.0, 1.0},
195 {0.0, 0.0, 0.9, 1.0},
199 #define _DEBUG(msg, args...) do { \
200 fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__ ,##args); \
203 #define _DEBUG(msg, args...)
206 /* This is all the half-edge b-rep code (as well as basic geometry) */
207 typedef struct face face;
208 typedef struct edge edge;
209 typedef struct hedge hedge;
210 typedef struct vertex vertex;
211 typedef GLfloat coord;
212 typedef coord vector[3];
252 static inline void vector_init(vector v, coord x, coord y, coord z)
259 static inline void vector_copy(vector d, vector s)
266 static inline void vector_add(vector v1, vector v2, vector v)
268 vector_init(v, v1[0]+v2[0], v1[1]+v2[1], v1[2]+v2[2]);
271 static inline void vector_add_to(vector v1, vector v2)
278 static inline void vector_sub(vector v1, vector v2, vector v)
280 vector_init(v, v1[0]-v2[0], v1[1]-v2[1], v1[2]-v2[2]);
283 static inline void vector_scale(vector v, coord s)
290 static inline coord dot(vector v1, vector v2)
292 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
295 static inline void cross(vector v1, vector v2, vector v)
298 v1[1]*v2[2] - v2[1]*v1[2],
299 v1[2]*v2[0] - v2[2]*v1[0],
300 v1[0]*v2[1] - v2[0]*v1[1]);
303 static inline coord magnitude2(vector v)
305 return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
308 static inline coord magnitude(vector v)
310 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
313 static inline void normalize(vector v)
315 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
322 static inline void normalize_to(vector v, coord m)
324 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])/m;
331 static inline void midpoint(vector v1, vector v2, vector v)
334 v1[0] + 0.5 * (v2[0] - v1[0]),
335 v1[1] + 0.5 * (v2[1] - v1[1]),
336 v1[2] + 0.5 * (v2[2] - v1[2]));
339 static inline hedge *partner(hedge *h) {
342 if(h == h->e->left) {
345 else if(h == h->e->right) {
349 _DEBUG("Inconsistent edge detected. Presumably, this is a bug. Exiting.\n");
354 vertex *vertex_new(solid *s, vector v)
356 vertex *vtx = (vertex*)malloc(sizeof(vertex));
361 vtx->next = s->vertices;
363 vector_copy(vtx->v, v);
364 vector_init(vtx->f, 0, 0, 0);
365 vector_init(vtx->vel, 0, 0, 0);
369 /* insert a new halfedge after hafter. this is low-level,
370 * i.e. it is a helper for the split_* functions, which
371 * maintain the consistency of the solid.
373 hedge *hedge_new(hedge *hafter, vertex *vtx)
375 hedge *h = (hedge*)malloc(sizeof(hedge));
378 _DEBUG("Out of memory in hedge_new()\n");
385 h->next = hafter->next;
391 edge *edge_new(solid *s)
393 edge *e = (edge*)malloc(sizeof(edge));
395 _DEBUG("Out of memory in edge_new()\n");
401 e->left = e->right = NULL;
405 face *face_new(solid *s, hedge *h)
407 face *f = (face*)malloc(sizeof(face));
409 _DEBUG("Out of memory in face_new()");
419 /* split vertex vtx, creating a new edge after v on f
420 * that goes to a new vertex at v, adjoining whatever
421 * face is on the other side of the halfedge attached to
424 * there are at least 2 faces.
425 * partner(h)->next->vtx == vtx
427 * the new halfedge will be inserted AFTER the indicated
428 * halfedge. This means that f->start is guaranteed not to
430 * the vertex returned will have h==<the new halfedge>.
433 vertex *vertex_split(hedge *h, vector v)
435 hedge *h2, *hn1, *hn2;
444 vtxn = vertex_new(f1->s, v);
445 hn1 = hedge_new(h, vtxn);
447 hn2 = hedge_new(h2, vtxn);
450 if(h2->e->left == h2)
455 en = edge_new(f1->s);
463 face *face_split(face *f, hedge *h1, hedge *h2)
465 hedge *hn1, *hn2, *tmp;
469 if(h1->f != f || h2->f != f) {
470 _DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n");
474 _DEBUG("Trying to split a face at a single vertex\n");
477 /* close the loops */
483 /* insert halfedges & create edge */
484 hn1 = hedge_new(h2->prev, h1->vtx);
485 hn2 = hedge_new(h1->prev, h2->vtx);
492 /* make the new face, first find out which hedge is contained
493 * in the original face, then start the new face at the other */
495 while(tmp != h1 && tmp != h2)
497 tmp = (tmp == h1) ? h2 : h1 ;
498 fn = face_new(f->s, tmp);
502 } while(tmp != fn->start);
503 fn->color = f->color;
507 solid *solid_new(vector where)
509 solid *s = (solid*)malloc(sizeof(solid));
519 h1 = (hedge*)malloc(sizeof(hedge));
520 h2 = (hedge*)malloc(sizeof(hedge));
521 h1->next = h1->prev = h1;
522 h2->next = h2->prev = h2;
524 vtx = vertex_new(s, where);
535 f1 = face_new(s, h1);
536 f2 = face_new(s, h2);
543 /* This is all the code directly related to constructing the jigglypuff */
544 void face_tessel2(face *f)
546 hedge *h1=f->start->prev, *h2=f->start->next;
550 while(h2 != h1 && h2->next != h1) {
551 f = face_split(f, h1, h2);
553 h2 = f->start->next->next;
557 /* This will only work with solids composed entirely of
558 * triangular faces. It first add a vertex to the middle
559 * of each edge, then walks the faces, connecting the
561 * I'm abusing the fact that new faces and edges are always
562 * added at the head of the list. If that ever changes,
565 void solid_tesselate(solid *s)
572 midpoint(e->left->vtx->v, e->right->vtx->v, v);
573 vertex_split(e->left, v);
582 void solid_spherify(solid * s, coord size)
584 vertex *vtx = s->vertices;
587 normalize_to(vtx->v, size);
592 solid *tetrahedron(jigglystruct *js)
601 vector_init(v, 1, 1, 1);
603 vector_init(v, -1, -1, 1);
605 vtx = vertex_split(h, v);
606 vector_init(v, -1, 1, -1);
607 vtx = vertex_split(vtx->h, v);
609 f = face_split(s->faces, h, h->prev);
610 vector_init(v, 1, -1, -1);
611 vertex_split(f->start, v);
612 f = s->faces->next->next;
614 face_split(f, h, h->next->next);
616 if(js->color_style == COLOR_STYLE_FLOWERBOX) {
619 f->color = flowerbox_colors[i];
627 solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
628 solid *s = tetrahedron(js);
631 for(i=0; i<iter; i++) {
637 static void clownbarf_colorize(solid *s) {
640 f->color = clownbarf_colors[random() % CLOWNBARF_NCOLORS];
645 /* Here be the rendering code */
647 static inline void vertex_calcnormal(vertex *vtx, jigglystruct *js)
649 hedge *start = vtx->h, *h=start;
651 vector_init(vtx->n, 0, 0, 0);
654 vector_sub(h->prev->vtx->v, vtx->v, u);
655 vector_sub(h->next->vtx->v, vtx->v, v);
657 vector_add_to(vtx->n, norm);
658 h = partner(h)->next;
663 vector_scale(vtx->n, js->spooky);
666 static inline void vertex_render(vertex *vtx, jigglystruct *js)
672 /* This can be optimized somewhat due to the fact that all
673 * the faces are triangles. I haven't actually tested to
674 * see what the cost is of calling glBegin/glEnd for each
677 static inline void face_render(face *f, jigglystruct *js)
679 hedge *h1, *h2, *hend;
685 if(js->color_style == COLOR_STYLE_FLOWERBOX ||
686 js->color_style == COLOR_STYLE_CLOWNBARF)
687 glColor4fv(f->color);
688 glBegin(GL_TRIANGLES);
689 while(h1 != hend && h2 !=hend) {
690 vertex_render(h1->vtx, js);
691 vertex_render(h2->vtx, js);
692 vertex_render(hend->vtx, js);
699 void jigglypuff_render(jigglystruct *js)
701 face *f = js->shape->faces;
702 vertex *vtx = js->shape->vertices;
705 vertex_calcnormal(vtx, js);
714 /* This is the jiggling code */
716 /* stable distance when subdivs == 4 */
717 #define STABLE_DISTANCE 0.088388347648
719 void update_shape(jigglystruct *js)
721 vertex *vtx = js->shape->vertices;
722 edge *e = js->shape->edges;
725 vector_init(zero, 0, 0, 0);
727 /* sum all the vertex-vertex forces */
731 vector_sub(e->left->vtx->v, e->right->vtx->v, f);
732 mag = js->stable_distance - magnitude(f);
733 vector_scale(f, mag);
734 vector_add_to(e->left->vtx->f, f);
735 vector_sub(zero, f, f);
736 vector_add_to(e->right->vtx->f, f);
740 /* scale back the v-v force and add the spherical force
741 * then add the result to the vertex velocity, damping
742 * if necessary. Finally, move the vertex */
746 vector_scale(vtx->f, js->hold_strength);
747 vector_copy(to_sphere, vtx->v);
748 mag = 1 - magnitude(to_sphere);
749 vector_scale(to_sphere, mag * js->spherify_strength);
750 vector_add_to(vtx->f, to_sphere);
751 vector_add_to(vtx->vel, vtx->f);
752 vector_init(vtx->f, 0, 0, 0);
753 mag = magnitude2(vtx->vel);
754 if(mag > js->damping_velocity)
755 vector_scale(vtx->vel, js->damping_factor);
756 vector_add_to(vtx->v, vtx->vel);
761 /* These are the various initialization routines */
763 void init_texture(ModeInfo *mi)
765 XImage *img = xpm_to_ximage(mi->dpy, mi->xgwa.visual,
766 mi->xgwa.colormap, jigglymap_xpm);
768 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
769 img->width, img->height, 0, GL_RGBA,
770 GL_UNSIGNED_BYTE, img->data);
775 void setup_opengl(ModeInfo *mi, jigglystruct *js)
777 const GLfloat lpos0[4] = {-12, 8, 12, 0};
778 const GLfloat lpos1[4] = {7, -5, 0, 0};
779 const GLfloat lcol0[4] = {0.7, 0.7, 0.65, 1};
780 const GLfloat lcol1[4] = {0.3, 0.2, 0.1, 1};
781 const GLfloat scolor[4]= {0.9, 0.9, 0.9, 0.5};
783 glDrawBuffer(GL_BACK);
784 glClearColor(0, 0, 0, 0);
785 glShadeModel(GL_SMOOTH);
786 glEnable(GL_DEPTH_TEST);
788 if(js->do_wireframe) {
789 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
794 glEnable(GL_CULL_FACE);
797 if(js->color_style != COLOR_STYLE_CHROME) {
798 glEnable(GL_LIGHTING);
802 glLightfv(GL_LIGHT0, GL_POSITION, lpos0);
803 glLightfv(GL_LIGHT1, GL_POSITION, lpos1);
804 glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol0);
805 glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol1);
807 glEnable(GL_COLOR_MATERIAL);
808 glColor4fv(js->jiggly_color);
810 glMaterialfv(GL_FRONT, GL_SPECULAR, scolor);
811 glMateriali(GL_FRONT, GL_SHININESS, js->shininess);
815 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
817 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
818 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
819 glEnable(GL_TEXTURE_GEN_S);
820 glEnable(GL_TEXTURE_GEN_T);
821 glEnable(GL_TEXTURE_2D);
822 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
828 int parse_color(jigglystruct *js)
831 if(!strcmp(color, "clownbarf")) {
832 js->color_style = COLOR_STYLE_CLOWNBARF;
835 else if(!strcmp(color, "flowerbox")) {
836 js->color_style = COLOR_STYLE_FLOWERBOX;
839 else if(!strcmp(color, "chrome")) {
840 js->color_style = COLOR_STYLE_CHROME;
843 else if(!strcmp(color, "cycle")) {
844 js->color_style = COLOR_STYLE_CYCLE;
845 js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
846 js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
847 js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
848 js->jiggly_color[3] = 1.0f;
849 js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
850 js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
851 js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
856 if(strlen(color) != 7)
858 if(sscanf(color,"#%02x%02x%02x", &r, &g, &b) != 3) {
861 js->jiggly_color[0] = ((float)r)/255;
862 js->jiggly_color[1] = ((float)g)/255;
863 js->jiggly_color[2] = ((float)b)/255;
864 js->jiggly_color[3] = 1.0f;
869 void randomize_parameters(jigglystruct *js) {
870 do_tetrahedron = random() & 1;
871 js->do_wireframe = !(random() & 3);
872 js->color_style = random() % 5;
873 if(js->color_style == COLOR_STYLE_NORMAL
874 || js->color_style == COLOR_STYLE_CYCLE) {
875 js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
876 js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
877 js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
878 js->jiggly_color[3] = 1.0f;
879 if(js->color_style == COLOR_STYLE_CYCLE) {
880 js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
881 js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
882 js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
885 if((js->color_style != COLOR_STYLE_CHROME) && (random() & 1))
886 js->spooky = (random() % 6) + 4;
889 js->shininess = random() % 200;
890 speed = (random() % 700) + 50;
891 /* It' kind of dull if this is too high when it starts as a sphere */
892 spherism = do_tetrahedron ? (random() % 500) + 20 : (random() % 100) + 10;
893 hold = (random() % 800) + 100;
894 distance = (random() % 500) + 100;
895 damping = (random() % 800) + 50;
898 void calculate_parameters(jigglystruct *js, int subdivs) {
899 /* try to compensate for the inherent instability at
901 float dist_factor = (subdivs == 6) ? 2 : (subdivs == 5) ? 1 : 0.5;
903 js->stable_distance = ((float)distance / 500.0)
904 * (STABLE_DISTANCE / dist_factor);
905 js->hold_strength = (float)hold / 10000.0;
906 js->spherify_strength = (float)spherism / 10000.0;
907 js->damping_velocity = (float)damping / 100000.0;
909 0.001/max(js->hold_strength, js->spherify_strength);
911 js->speed = (float)speed / 1000.0;
914 /* The screenhack related functions begin here */
916 Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
918 jigglystruct *js = &jss[MI_SCREEN(mi)];
920 if(event->xany.type == ButtonPress &&
921 event->xbutton.button & Button1) {
923 gltrackball_start(js->trackball, event->xbutton.x, event->xbutton.y,
924 MI_WIDTH(mi), MI_HEIGHT(mi));
927 else if(event->xany.type == ButtonRelease &&
928 event->xbutton.button & Button1) {
932 else if(event->xany.type == MotionNotify && js->button_down) {
933 gltrackball_track(js->trackball, event->xmotion.x, event->xmotion.y,
934 MI_WIDTH(mi), MI_HEIGHT(mi));
940 void reshape_jigglypuff(ModeInfo *mi, int width, int height)
942 GLfloat aspect = (GLfloat)width / (GLfloat)height;
944 glViewport(0, 0, width, height);
945 glMatrixMode(GL_PROJECTION);
947 glFrustum(-0.5*aspect, 0.5*aspect, -0.5, 0.5, 1, 20);
948 /* glTranslatef(0, 0, -10);*/
951 void draw_jigglypuff(ModeInfo *mi)
953 jigglystruct *js = &jss[MI_SCREEN(mi)];
955 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
957 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
959 glMatrixMode(GL_MODELVIEW);
961 glTranslatef(0,0,-10);
963 glRotatef(js->angle, sin(js->axis), cos(js->axis), -sin(js->axis));
964 glTranslatef(0, 0, 5);
965 if(!(js->button_down)) {
966 if((js->angle += js->speed) >= 360.0f ) {
969 if((js->axis+=0.01f) >= 2*M_PI ) {
973 gltrackball_rotate(js->trackball);
975 if(js->color_style == COLOR_STYLE_CYCLE) {
977 vector_add(js->jiggly_color, js->color_dir, js->jiggly_color);
980 if(js->jiggly_color[i] > 1.0 || js->jiggly_color[i] < 0.3) {
981 js->color_dir[i] = (-js->color_dir[i]);
982 js->jiggly_color[i] += js->color_dir[i];
985 glColor4fv(js->jiggly_color);
988 jigglypuff_render(js);
993 glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
996 void init_jigglypuff(ModeInfo *mi)
1002 jss = (jigglystruct*)
1003 calloc(MI_NUM_SCREENS(mi), sizeof(jigglystruct));
1005 fprintf(stderr, "%s: No..memory...must...abort..\n", progname);
1010 js = &jss[MI_SCREEN(mi)];
1012 js->do_wireframe = MI_IS_WIREFRAME(mi);
1014 js->shininess = shininess;
1016 subdivs = (complexity==1) ? 4 : (complexity==2) ? 5
1017 : (complexity==3) ? 6 : 5;
1019 js->spooky = spooky << (subdivs-3);
1021 if(!parse_color(js)) {
1022 fprintf(stderr, "%s: Bad color specification: '%s'.\n", progname, color);
1027 randomize_parameters(js);
1029 js->shape = tesselated_tetrahedron(1, subdivs, js);
1032 solid_spherify(js->shape, 1);
1034 if(js->color_style == COLOR_STYLE_CLOWNBARF)
1035 clownbarf_colorize(js->shape);
1037 calculate_parameters(js, subdivs);
1039 if((js->glx_context = init_GL(mi)) != NULL) {
1040 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
1041 setup_opengl(mi, js);
1042 reshape_jigglypuff(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1047 js->trackball = gltrackball_init();
1048 _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
1049 js->stable_distance, js->hold_strength, js->spherify_strength,
1050 js->damping_velocity, js->damping_factor);
1051 _DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
1052 js->do_wireframe, js->spooky, js->color_style, js->shininess);
1055 /* This is the end of the file */