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},
198 # if 0 /* I am not even going to *try* and make this bullshit compile
199 without warning under gcc -std=c89 -pedantic. -jwz. */
201 # ifdef __GNUC__ /* GCC style */
202 #define _DEBUG(msg, args...) do { \
203 fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__ ,##args); \
205 # else /* C99 standard style */
206 #define _DEBUG(msg, ...) do { \
207 fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__,__VA_ARGS__); \
211 # ifdef __GNUC__ /* GCC style */
212 #define _DEBUG(msg, args...)
213 # else /* C99 standard style */
214 #define _DEBUG(msg, ...)
219 /* This is all the half-edge b-rep code (as well as basic geometry) */
220 typedef struct face face;
221 typedef struct edge edge;
222 typedef struct hedge hedge;
223 typedef struct vertex vertex;
224 typedef GLfloat coord;
225 typedef coord vector[3];
265 static inline void vector_init(vector v, coord x, coord y, coord z)
272 static inline void vector_copy(vector d, vector s)
279 static inline void vector_add(vector v1, vector v2, vector v)
281 vector_init(v, v1[0]+v2[0], v1[1]+v2[1], v1[2]+v2[2]);
284 static inline void vector_add_to(vector v1, vector v2)
291 static inline void vector_sub(vector v1, vector v2, vector v)
293 vector_init(v, v1[0]-v2[0], v1[1]-v2[1], v1[2]-v2[2]);
296 static inline void vector_scale(vector v, coord s)
303 static inline coord dot(vector v1, vector v2)
305 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
308 static inline void cross(vector v1, vector v2, vector v)
311 v1[1]*v2[2] - v2[1]*v1[2],
312 v1[2]*v2[0] - v2[2]*v1[0],
313 v1[0]*v2[1] - v2[0]*v1[1]);
316 static inline coord magnitude2(vector v)
318 return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
321 static inline coord magnitude(vector v)
323 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
326 static inline void normalize(vector v)
328 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
335 static inline void normalize_to(vector v, coord m)
337 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])/m;
344 static inline void midpoint(vector v1, vector v2, vector v)
347 v1[0] + 0.5 * (v2[0] - v1[0]),
348 v1[1] + 0.5 * (v2[1] - v1[1]),
349 v1[2] + 0.5 * (v2[2] - v1[2]));
352 static inline hedge *partner(hedge *h) {
355 if(h == h->e->left) {
358 else if(h == h->e->right) {
362 /* _DEBUG("Inconsistent edge detected. Presumably, this is a bug. Exiting.\n", NULL); */
367 vertex *vertex_new(solid *s, vector v)
369 vertex *vtx = (vertex*)malloc(sizeof(vertex));
374 vtx->next = s->vertices;
376 vector_copy(vtx->v, v);
377 vector_init(vtx->f, 0, 0, 0);
378 vector_init(vtx->vel, 0, 0, 0);
382 /* insert a new halfedge after hafter. this is low-level,
383 * i.e. it is a helper for the split_* functions, which
384 * maintain the consistency of the solid.
386 hedge *hedge_new(hedge *hafter, vertex *vtx)
388 hedge *h = (hedge*)malloc(sizeof(hedge));
391 /* _DEBUG("Out of memory in hedge_new()\n",NULL); */
398 h->next = hafter->next;
404 edge *edge_new(solid *s)
406 edge *e = (edge*)malloc(sizeof(edge));
408 /* _DEBUG("Out of memory in edge_new()\n",NULL);*/
414 e->left = e->right = NULL;
418 face *face_new(solid *s, hedge *h)
420 face *f = (face*)malloc(sizeof(face));
422 /* _DEBUG("Out of memory in face_new()",NULL);*/
432 /* split vertex vtx, creating a new edge after v on f
433 * that goes to a new vertex at v, adjoining whatever
434 * face is on the other side of the halfedge attached to
437 * there are at least 2 faces.
438 * partner(h)->next->vtx == vtx
440 * the new halfedge will be inserted AFTER the indicated
441 * halfedge. This means that f->start is guaranteed not to
443 * the vertex returned will have h==<the new halfedge>.
446 vertex *vertex_split(hedge *h, vector v)
448 hedge *h2, *hn1, *hn2;
457 vtxn = vertex_new(f1->s, v);
458 hn1 = hedge_new(h, vtxn);
460 hn2 = hedge_new(h2, vtxn);
463 if(h2->e->left == h2)
468 en = edge_new(f1->s);
476 face *face_split(face *f, hedge *h1, hedge *h2)
478 hedge *hn1, *hn2, *tmp;
482 if(h1->f != f || h2->f != f) {
483 /* _DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n",NULL);*/
487 /* _DEBUG("Trying to split a face at a single vertex\n",NULL);*/
490 /* close the loops */
496 /* insert halfedges & create edge */
497 hn1 = hedge_new(h2->prev, h1->vtx);
498 hn2 = hedge_new(h1->prev, h2->vtx);
505 /* make the new face, first find out which hedge is contained
506 * in the original face, then start the new face at the other */
508 while(tmp != h1 && tmp != h2)
510 tmp = (tmp == h1) ? h2 : h1 ;
511 fn = face_new(f->s, tmp);
515 } while(tmp != fn->start);
516 fn->color = f->color;
520 solid *solid_new(vector where)
522 solid *s = (solid*)malloc(sizeof(solid));
532 h1 = (hedge*)malloc(sizeof(hedge));
533 h2 = (hedge*)malloc(sizeof(hedge));
534 h1->next = h1->prev = h1;
535 h2->next = h2->prev = h2;
537 vtx = vertex_new(s, where);
548 f1 = face_new(s, h1);
549 f2 = face_new(s, h2);
556 /* This is all the code directly related to constructing the jigglypuff */
557 void face_tessel2(face *f)
559 hedge *h1=f->start->prev, *h2=f->start->next;
563 while(h2 != h1 && h2->next != h1) {
564 f = face_split(f, h1, h2);
566 h2 = f->start->next->next;
570 /* This will only work with solids composed entirely of
571 * triangular faces. It first add a vertex to the middle
572 * of each edge, then walks the faces, connecting the
574 * I'm abusing the fact that new faces and edges are always
575 * added at the head of the list. If that ever changes,
578 void solid_tesselate(solid *s)
585 midpoint(e->left->vtx->v, e->right->vtx->v, v);
586 vertex_split(e->left, v);
595 void solid_spherify(solid * s, coord size)
597 vertex *vtx = s->vertices;
600 normalize_to(vtx->v, size);
605 solid *tetrahedron(jigglystruct *js)
614 vector_init(v, 1, 1, 1);
616 vector_init(v, -1, -1, 1);
618 vtx = vertex_split(h, v);
619 vector_init(v, -1, 1, -1);
620 vtx = vertex_split(vtx->h, v);
622 f = face_split(s->faces, h, h->prev);
623 vector_init(v, 1, -1, -1);
624 vertex_split(f->start, v);
625 f = s->faces->next->next;
627 face_split(f, h, h->next->next);
629 if(js->color_style == COLOR_STYLE_FLOWERBOX) {
632 f->color = flowerbox_colors[i];
640 solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
641 solid *s = tetrahedron(js);
644 for(i=0; i<iter; i++) {
650 static void clownbarf_colorize(solid *s) {
653 f->color = clownbarf_colors[random() % CLOWNBARF_NCOLORS];
658 /* Here be the rendering code */
660 static inline void vertex_calcnormal(vertex *vtx, jigglystruct *js)
662 hedge *start = vtx->h, *h=start;
664 vector_init(vtx->n, 0, 0, 0);
667 vector_sub(h->prev->vtx->v, vtx->v, u);
668 vector_sub(h->next->vtx->v, vtx->v, v);
670 vector_add_to(vtx->n, norm);
671 h = partner(h)->next;
676 vector_scale(vtx->n, js->spooky);
679 static inline void vertex_render(vertex *vtx, jigglystruct *js)
685 /* This can be optimized somewhat due to the fact that all
686 * the faces are triangles. I haven't actually tested to
687 * see what the cost is of calling glBegin/glEnd for each
690 static inline void face_render(face *f, jigglystruct *js)
692 hedge *h1, *h2, *hend;
698 if(js->color_style == COLOR_STYLE_FLOWERBOX ||
699 js->color_style == COLOR_STYLE_CLOWNBARF)
700 glColor4fv(f->color);
701 glBegin(GL_TRIANGLES);
702 while(h1 != hend && h2 !=hend) {
703 vertex_render(h1->vtx, js);
704 vertex_render(h2->vtx, js);
705 vertex_render(hend->vtx, js);
712 void jigglypuff_render(jigglystruct *js)
714 face *f = js->shape->faces;
715 vertex *vtx = js->shape->vertices;
718 vertex_calcnormal(vtx, js);
727 /* This is the jiggling code */
729 /* stable distance when subdivs == 4 */
730 #define STABLE_DISTANCE 0.088388347648
732 void update_shape(jigglystruct *js)
734 vertex *vtx = js->shape->vertices;
735 edge *e = js->shape->edges;
738 vector_init(zero, 0, 0, 0);
740 /* sum all the vertex-vertex forces */
744 vector_sub(e->left->vtx->v, e->right->vtx->v, f);
745 mag = js->stable_distance - magnitude(f);
746 vector_scale(f, mag);
747 vector_add_to(e->left->vtx->f, f);
748 vector_sub(zero, f, f);
749 vector_add_to(e->right->vtx->f, f);
753 /* scale back the v-v force and add the spherical force
754 * then add the result to the vertex velocity, damping
755 * if necessary. Finally, move the vertex */
759 vector_scale(vtx->f, js->hold_strength);
760 vector_copy(to_sphere, vtx->v);
761 mag = 1 - magnitude(to_sphere);
762 vector_scale(to_sphere, mag * js->spherify_strength);
763 vector_add_to(vtx->f, to_sphere);
764 vector_add_to(vtx->vel, vtx->f);
765 vector_init(vtx->f, 0, 0, 0);
766 mag = magnitude2(vtx->vel);
767 if(mag > js->damping_velocity)
768 vector_scale(vtx->vel, js->damping_factor);
769 vector_add_to(vtx->v, vtx->vel);
774 /* These are the various initialization routines */
776 void init_texture(ModeInfo *mi)
778 XImage *img = xpm_to_ximage(mi->dpy, mi->xgwa.visual,
779 mi->xgwa.colormap, jigglymap_xpm);
781 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
782 img->width, img->height, 0, GL_RGBA,
783 GL_UNSIGNED_BYTE, img->data);
788 void setup_opengl(ModeInfo *mi, jigglystruct *js)
790 const GLfloat lpos0[4] = {-12, 8, 12, 0};
791 const GLfloat lpos1[4] = {7, -5, 0, 0};
792 const GLfloat lcol0[4] = {0.7f, 0.7f, 0.65f, 1};
793 const GLfloat lcol1[4] = {0.3f, 0.2f, 0.1f, 1};
794 const GLfloat scolor[4]= {0.9f, 0.9f, 0.9f, 0.5f};
796 glDrawBuffer(GL_BACK);
797 glClearColor(0, 0, 0, 0);
798 glShadeModel(GL_SMOOTH);
799 glEnable(GL_DEPTH_TEST);
801 if(js->do_wireframe) {
802 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
807 glEnable(GL_CULL_FACE);
810 if(js->color_style != COLOR_STYLE_CHROME) {
811 glEnable(GL_LIGHTING);
815 glLightfv(GL_LIGHT0, GL_POSITION, lpos0);
816 glLightfv(GL_LIGHT1, GL_POSITION, lpos1);
817 glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol0);
818 glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol1);
820 glEnable(GL_COLOR_MATERIAL);
821 glColor4fv(js->jiggly_color);
823 glMaterialfv(GL_FRONT, GL_SPECULAR, scolor);
824 glMateriali(GL_FRONT, GL_SHININESS, js->shininess);
828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
830 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
831 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
832 glEnable(GL_TEXTURE_GEN_S);
833 glEnable(GL_TEXTURE_GEN_T);
834 glEnable(GL_TEXTURE_2D);
835 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
841 int parse_color(jigglystruct *js)
843 unsigned int r, g, b;
844 if(!strcmp(color, "clownbarf")) {
845 js->color_style = COLOR_STYLE_CLOWNBARF;
848 else if(!strcmp(color, "flowerbox")) {
849 js->color_style = COLOR_STYLE_FLOWERBOX;
852 else if(!strcmp(color, "chrome")) {
853 js->color_style = COLOR_STYLE_CHROME;
856 else if(!strcmp(color, "cycle")) {
857 js->color_style = COLOR_STYLE_CYCLE;
858 js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
859 js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
860 js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
861 js->jiggly_color[3] = 1.0f;
862 js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
863 js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
864 js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
869 if(strlen(color) != 7)
871 if(sscanf(color,"#%02x%02x%02x", &r, &g, &b) != 3) {
874 js->jiggly_color[0] = ((float)r)/255;
875 js->jiggly_color[1] = ((float)g)/255;
876 js->jiggly_color[2] = ((float)b)/255;
877 js->jiggly_color[3] = 1.0f;
882 void randomize_parameters(jigglystruct *js) {
883 do_tetrahedron = random() & 1;
884 js->do_wireframe = !(random() & 3);
885 js->color_style = random() % 5;
886 if(js->color_style == COLOR_STYLE_NORMAL
887 || js->color_style == COLOR_STYLE_CYCLE) {
888 js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
889 js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
890 js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
891 js->jiggly_color[3] = 1.0f;
892 if(js->color_style == COLOR_STYLE_CYCLE) {
893 js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
894 js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
895 js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
898 if((js->color_style != COLOR_STYLE_CHROME) && (random() & 1))
899 js->spooky = (random() % 6) + 4;
902 js->shininess = random() % 200;
903 speed = (random() % 700) + 50;
904 /* It' kind of dull if this is too high when it starts as a sphere */
905 spherism = do_tetrahedron ? (random() % 500) + 20 : (random() % 100) + 10;
906 hold = (random() % 800) + 100;
907 distance = (random() % 500) + 100;
908 damping = (random() % 800) + 50;
911 void calculate_parameters(jigglystruct *js, int subdivs) {
912 /* try to compensate for the inherent instability at
914 float dist_factor = (subdivs == 6) ? 2 : (subdivs == 5) ? 1 : 0.5;
916 js->stable_distance = ((float)distance / 500.0)
917 * (STABLE_DISTANCE / dist_factor);
918 js->hold_strength = (float)hold / 10000.0;
919 js->spherify_strength = (float)spherism / 10000.0;
920 js->damping_velocity = (float)damping / 100000.0;
922 0.001/max(js->hold_strength, js->spherify_strength);
924 js->speed = (float)speed / 1000.0;
927 /* The screenhack related functions begin here */
929 Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
931 jigglystruct *js = &jss[MI_SCREEN(mi)];
933 if(event->xany.type == ButtonPress &&
934 event->xbutton.button & Button1) {
936 gltrackball_start(js->trackball, event->xbutton.x, event->xbutton.y,
937 MI_WIDTH(mi), MI_HEIGHT(mi));
940 else if(event->xany.type == ButtonRelease &&
941 event->xbutton.button & Button1) {
945 else if(event->xany.type == MotionNotify && js->button_down) {
946 gltrackball_track(js->trackball, event->xmotion.x, event->xmotion.y,
947 MI_WIDTH(mi), MI_HEIGHT(mi));
953 void reshape_jigglypuff(ModeInfo *mi, int width, int height)
955 GLfloat aspect = (GLfloat)width / (GLfloat)height;
957 glViewport(0, 0, width, height);
958 glMatrixMode(GL_PROJECTION);
960 glFrustum(-0.5*aspect, 0.5*aspect, -0.5, 0.5, 1, 20);
961 /* glTranslatef(0, 0, -10);*/
964 void draw_jigglypuff(ModeInfo *mi)
966 jigglystruct *js = &jss[MI_SCREEN(mi)];
968 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
970 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
972 glMatrixMode(GL_MODELVIEW);
974 glTranslatef(0,0,-10);
976 glRotatef(js->angle, sin(js->axis), cos(js->axis), -sin(js->axis));
977 glTranslatef(0, 0, 5);
978 if(!(js->button_down)) {
979 if((js->angle += js->speed) >= 360.0f ) {
982 if((js->axis+=0.01f) >= 2*M_PI ) {
986 gltrackball_rotate(js->trackball);
988 if(js->color_style == COLOR_STYLE_CYCLE) {
990 vector_add(js->jiggly_color, js->color_dir, js->jiggly_color);
993 if(js->jiggly_color[i] > 1.0 || js->jiggly_color[i] < 0.3) {
994 js->color_dir[i] = (-js->color_dir[i]);
995 js->jiggly_color[i] += js->color_dir[i];
998 glColor4fv(js->jiggly_color);
1001 jigglypuff_render(js);
1006 glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
1009 void init_jigglypuff(ModeInfo *mi)
1015 jss = (jigglystruct*)
1016 calloc(MI_NUM_SCREENS(mi), sizeof(jigglystruct));
1018 fprintf(stderr, "%s: No..memory...must...abort..\n", progname);
1023 js = &jss[MI_SCREEN(mi)];
1025 js->do_wireframe = MI_IS_WIREFRAME(mi);
1027 js->shininess = shininess;
1029 subdivs = (complexity==1) ? 4 : (complexity==2) ? 5
1030 : (complexity==3) ? 6 : 5;
1032 js->spooky = spooky << (subdivs-3);
1034 if(!parse_color(js)) {
1035 fprintf(stderr, "%s: Bad color specification: '%s'.\n", progname, color);
1040 randomize_parameters(js);
1042 js->shape = tesselated_tetrahedron(1, subdivs, js);
1045 solid_spherify(js->shape, 1);
1047 if(js->color_style == COLOR_STYLE_CLOWNBARF)
1048 clownbarf_colorize(js->shape);
1050 calculate_parameters(js, subdivs);
1052 if((js->glx_context = init_GL(mi)) != NULL) {
1053 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
1054 setup_opengl(mi, js);
1055 reshape_jigglypuff(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1060 js->trackball = gltrackball_init();
1061 /* _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
1062 js->stable_distance, js->hold_strength, js->spherify_strength,
1063 js->damping_velocity, js->damping_factor);
1064 _DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
1065 js->do_wireframe, js->spooky, js->color_style, js->shininess);*/
1068 /* This is the end of the file */