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
39 # define DEFAULTS "*delay: 20000\n" \
41 "*wireframe: False\n" \
42 "*suppressRotationAnimation: True\n" \
44 # define free_jigglypuff 0
45 # define release_jigglypuff 0
46 # include "xlockmore.h"
55 #include "ximage-loader.h"
56 #include "gltrackball.h"
57 #include "images/gen/jigglymap_png.h"
62 #define DEF_COLOR "cycle"
63 #define DEF_SHININESS "100"
64 #define DEF_COMPLEXITY "2"
65 #define DEF_SPEED "500"
66 #define DEF_DISTANCE "100"
67 #define DEF_HOLD "800"
68 #define DEF_SPHERISM "75"
69 #define DEF_DAMPING "500"
70 #define DEF_RANDOM "True"
71 #define DEF_TETRA "False"
72 #define DEF_SPOOKY "0"
75 #define max(a,b) (((a)>(b))?(a):(b))
76 #define min(a,b) (((a)<(b))?(a):(b))
79 /* Why isn't RAND_MAX correct in the first place? */
80 #define REAL_RAND_MAX (2.0*(float)RAND_MAX)
87 static int complexity;
90 static int do_tetrahedron;
95 static int random_parms;
97 typedef struct solid solid;
100 float stable_distance;
102 float spherify_strength;
103 float damping_velocity;
104 float damping_factor;
110 GLfloat jiggly_color[4];
111 GLfloat color_dir[3];
115 trackball_state *trackball;
122 GLXContext *glx_context;
125 static jigglystruct *jss = NULL;
127 static XrmOptionDescRec opts[] = {
128 {"-random", ".Jigglypuff.random", XrmoptionNoArg, "true"},
129 {"+random", ".Jigglypuff.random", XrmoptionNoArg, "false"},
130 {"-tetra", ".Jigglypuff.tetra", XrmoptionNoArg, "true"},
131 {"+tetra", ".Jigglypuff.tetra", XrmoptionNoArg, "false"},
132 {"-spooky", ".Jigglypuff.spooky", XrmoptionSepArg, "0"},
133 {"-color", ".Jigglypuff.color", XrmoptionSepArg, DEF_COLOR},
134 {"-shininess", ".Jigglypuff.shininess", XrmoptionSepArg, DEF_SHININESS},
135 {"-complexity", ".Jigglypuff.complexity", XrmoptionSepArg, DEF_COMPLEXITY},
136 {"-speed", ".Jigglypuff.speed", XrmoptionSepArg, DEF_SPEED},
137 {"-spherism", ".Jigglypuff.spherism", XrmoptionSepArg, DEF_SPHERISM},
138 {"-hold", ".Jigglypuff.hold", XrmoptionSepArg, DEF_HOLD},
139 {"-distance", "Jigglypuff.distance", XrmoptionSepArg, DEF_DISTANCE},
140 {"-damping", "Jigglypuff.damping", XrmoptionSepArg, DEF_DAMPING}
143 static argtype vars[] = {
144 {&random_parms, "random", "Random", DEF_RANDOM, t_Bool},
145 {&do_tetrahedron, "tetra", "Tetra", DEF_TETRA, t_Bool},
146 {&spooky, "spooky", "Spooky", DEF_SPOOKY, t_Int},
147 {&color, "color", "Color", DEF_COLOR, t_String},
148 {&shininess, "shininess", "Shininess", DEF_SHININESS, t_Int},
149 {&complexity, "complexity", "Complexity", DEF_COMPLEXITY, t_Int},
150 {&speed, "speed", "Speed", DEF_SPEED, t_Int},
151 {&spherism, "spherism", "Spherism", DEF_SPHERISM, t_Int},
152 {&hold, "hold", "Hold", DEF_HOLD, t_Int},
153 {&distance, "distance", "Distance", DEF_DISTANCE, t_Int},
154 {&damping, "damping", "Damping", DEF_DAMPING, t_Int}
158 #define countof(x) ((int)(sizeof(x)/sizeof(*(x))))
160 ENTRYPOINT ModeSpecOpt jigglypuff_opts = {countof(opts), opts, countof(vars), vars, NULL};
162 #define COLOR_STYLE_NORMAL 0
163 #define COLOR_STYLE_CYCLE 1
164 #define COLOR_STYLE_CLOWNBARF 2
165 #define COLOR_STYLE_FLOWERBOX 3
166 #define COLOR_STYLE_CHROME 4
168 #define CLOWNBARF_NCOLORS 5
170 static const GLfloat clownbarf_colors[CLOWNBARF_NCOLORS][4] = {
171 {0.7, 0.7, 0.0, 1.0},
172 {0.8, 0.1, 0.1, 1.0},
173 {0.1, 0.1, 0.8, 1.0},
174 {0.9, 0.9, 0.9, 1.0},
178 static const GLfloat flowerbox_colors[4][4] = {
179 {0.7, 0.7, 0.0, 1.0},
180 {0.9, 0.0, 0.0, 1.0},
181 {0.0, 0.9, 0.0, 1.0},
182 {0.0, 0.0, 0.9, 1.0},
185 # if 0 /* I am not even going to *try* and make this bullshit compile
186 without warning under gcc -std=c89 -pedantic. -jwz. */
188 # ifdef __GNUC__ /* GCC style */
189 #define _DEBUG(msg, args...) do { \
190 fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__ ,##args); \
192 # else /* C99 standard style */
193 #define _DEBUG(msg, ...) do { \
194 fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__,__VA_ARGS__); \
198 # ifdef __GNUC__ /* GCC style */
199 #define _DEBUG(msg, args...)
200 # else /* C99 standard style */
201 #define _DEBUG(msg, ...)
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];
223 const GLfloat *color;
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)
291 static inline coord dot(vector v1, vector v2)
293 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
297 static inline void cross(vector v1, vector v2, vector v)
300 v1[1]*v2[2] - v2[1]*v1[2],
301 v1[2]*v2[0] - v2[2]*v1[0],
302 v1[0]*v2[1] - v2[0]*v1[1]);
305 static inline coord magnitude2(vector v)
307 return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
310 static inline coord magnitude(vector v)
312 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
315 static inline void normalize(vector v)
317 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
324 static inline void normalize_to(vector v, coord m)
326 coord mag = 1.0/sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])/m;
333 static inline void midpoint(vector v1, vector v2, vector v)
336 v1[0] + 0.5 * (v2[0] - v1[0]),
337 v1[1] + 0.5 * (v2[1] - v1[1]),
338 v1[2] + 0.5 * (v2[2] - v1[2]));
341 static inline hedge *partner(hedge *h) {
344 if(h == h->e->left) {
347 else if(h == h->e->right) {
351 /* _DEBUG("Inconsistent edge detected. Presumably, this is a bug. Exiting.\n", NULL); */
356 static vertex *vertex_new(solid *s, vector v)
358 vertex *vtx = (vertex*)malloc(sizeof(vertex));
363 vtx->next = s->vertices;
365 vector_copy(vtx->v, v);
366 vector_init(vtx->f, 0, 0, 0);
367 vector_init(vtx->vel, 0, 0, 0);
371 /* insert a new halfedge after hafter. this is low-level,
372 * i.e. it is a helper for the split_* functions, which
373 * maintain the consistency of the solid.
375 static hedge *hedge_new(hedge *hafter, vertex *vtx)
377 hedge *h = (hedge*)malloc(sizeof(hedge));
380 /* _DEBUG("Out of memory in hedge_new()\n",NULL); */
387 h->next = hafter->next;
393 static edge *edge_new(solid *s)
395 edge *e = (edge*)malloc(sizeof(edge));
397 /* _DEBUG("Out of memory in edge_new()\n",NULL);*/
403 e->left = e->right = NULL;
407 static face *face_new(solid *s, hedge *h)
409 face *f = (face*)malloc(sizeof(face));
411 /* _DEBUG("Out of memory in face_new()",NULL);*/
421 /* split vertex vtx, creating a new edge after v on f
422 * that goes to a new vertex at v, adjoining whatever
423 * face is on the other side of the halfedge attached to
426 * there are at least 2 faces.
427 * partner(h)->next->vtx == vtx
429 * the new halfedge will be inserted AFTER the indicated
430 * halfedge. This means that f->start is guaranteed not to
432 * the vertex returned will have h==<the new halfedge>.
435 static vertex *vertex_split(hedge *h, vector v)
437 hedge *h2, *hn1, *hn2;
445 vtxn = vertex_new(f1->s, v);
446 hn1 = hedge_new(h, vtxn);
448 hn2 = hedge_new(h2, vtxn);
451 if(h2->e->left == h2)
456 en = edge_new(f1->s);
464 static face *face_split(face *f, hedge *h1, hedge *h2)
466 hedge *hn1, *hn2, *tmp;
470 if(h1->f != f || h2->f != f) {
471 /* _DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n",NULL);*/
475 /* _DEBUG("Trying to split a face at a single vertex\n",NULL);*/
478 /* close the loops */
484 /* insert halfedges & create edge */
485 hn1 = hedge_new(h2->prev, h1->vtx);
486 hn2 = hedge_new(h1->prev, h2->vtx);
493 /* make the new face, first find out which hedge is contained
494 * in the original face, then start the new face at the other */
496 while(tmp != h1 && tmp != h2)
498 tmp = (tmp == h1) ? h2 : h1 ;
499 fn = face_new(f->s, tmp);
503 } while(tmp != fn->start);
504 fn->color = f->color;
508 static solid *solid_new(vector where)
510 solid *s = (solid*)malloc(sizeof(solid));
520 h1 = (hedge*)malloc(sizeof(hedge));
521 h2 = (hedge*)malloc(sizeof(hedge));
522 h1->next = h1->prev = h1;
523 h2->next = h2->prev = h2;
525 vtx = vertex_new(s, where);
536 f1 = face_new(s, h1);
537 f2 = face_new(s, h2);
544 /* This is all the code directly related to constructing the jigglypuff */
545 static void face_tessel2(face *f)
547 hedge *h1=f->start->prev, *h2=f->start->next;
551 while(h2 != h1 && h2->next != h1) {
552 f = face_split(f, h1, h2);
554 h2 = f->start->next->next;
558 /* This will only work with solids composed entirely of
559 * triangular faces. It first add a vertex to the middle
560 * of each edge, then walks the faces, connecting the
562 * I'm abusing the fact that new faces and edges are always
563 * added at the head of the list. If that ever changes,
566 static void solid_tesselate(solid *s)
573 midpoint(e->left->vtx->v, e->right->vtx->v, v);
574 vertex_split(e->left, v);
583 static void solid_spherify(solid * s, coord size)
585 vertex *vtx = s->vertices;
588 normalize_to(vtx->v, size);
593 static solid *tetrahedron(jigglystruct *js)
602 vector_init(v, 1, 1, 1);
604 vector_init(v, -1, -1, 1);
606 vtx = vertex_split(h, v);
607 vector_init(v, -1, 1, -1);
608 vtx = vertex_split(vtx->h, v);
610 f = face_split(s->faces, h, h->prev);
611 vector_init(v, 1, -1, -1);
612 vertex_split(f->start, v);
613 f = s->faces->next->next;
615 face_split(f, h, h->next->next);
617 if(js->color_style == COLOR_STYLE_FLOWERBOX) {
620 f->color = flowerbox_colors[i];
628 static solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
629 solid *s = tetrahedron(js);
632 for(i=0; i<iter; i++) {
638 static void clownbarf_colorize(solid *s) {
641 f->color = clownbarf_colors[random() % CLOWNBARF_NCOLORS];
646 /* Here be the rendering code */
648 static inline void vertex_calcnormal(vertex *vtx, jigglystruct *js)
650 hedge *start = vtx->h, *h=start;
652 vector_init(vtx->n, 0, 0, 0);
655 vector_sub(h->prev->vtx->v, vtx->v, u);
656 vector_sub(h->next->vtx->v, vtx->v, v);
658 vector_add_to(vtx->n, norm);
659 h = partner(h)->next;
664 vector_scale(vtx->n, js->spooky);
667 static inline void vertex_render(vertex *vtx, jigglystruct *js)
673 /* This can be optimized somewhat due to the fact that all
674 * the faces are triangles. I haven't actually tested to
675 * see what the cost is of calling glBegin/glEnd for each
678 static inline int face_render(face *f, jigglystruct *js)
680 hedge *h1, *h2, *hend;
687 if(js->color_style == COLOR_STYLE_FLOWERBOX ||
688 js->color_style == COLOR_STYLE_CLOWNBARF)
689 glColor4fv(f->color);
690 glBegin(GL_TRIANGLES);
691 while(h1 != hend && h2 !=hend) {
692 vertex_render(h1->vtx, js);
693 vertex_render(h2->vtx, js);
694 vertex_render(hend->vtx, js);
703 static int jigglypuff_render(jigglystruct *js)
706 face *f = js->shape->faces;
707 vertex *vtx = js->shape->vertices;
710 vertex_calcnormal(vtx, js);
714 polys += face_render(f, js);
720 /* This is the jiggling code */
722 /* stable distance when subdivs == 4 */
723 #define STABLE_DISTANCE 0.088388347648
725 static void update_shape(jigglystruct *js)
727 vertex *vtx = js->shape->vertices;
728 edge *e = js->shape->edges;
731 vector_init(zero, 0, 0, 0);
733 /* sum all the vertex-vertex forces */
737 vector_sub(e->left->vtx->v, e->right->vtx->v, f);
738 mag = js->stable_distance - magnitude(f);
739 vector_scale(f, mag);
740 vector_add_to(e->left->vtx->f, f);
741 vector_sub(zero, f, f);
742 vector_add_to(e->right->vtx->f, f);
746 /* scale back the v-v force and add the spherical force
747 * then add the result to the vertex velocity, damping
748 * if necessary. Finally, move the vertex */
752 vector_scale(vtx->f, js->hold_strength);
753 vector_copy(to_sphere, vtx->v);
754 mag = 1 - magnitude(to_sphere);
755 vector_scale(to_sphere, mag * js->spherify_strength);
756 vector_add_to(vtx->f, to_sphere);
757 vector_add_to(vtx->vel, vtx->f);
758 vector_init(vtx->f, 0, 0, 0);
759 mag = magnitude2(vtx->vel);
760 if(mag > js->damping_velocity)
761 vector_scale(vtx->vel, js->damping_factor);
762 vector_add_to(vtx->v, vtx->vel);
767 /* These are the various initialization routines */
769 static void init_texture(ModeInfo *mi)
771 XImage *img = image_data_to_ximage(mi->dpy, mi->xgwa.visual,
772 jigglymap_png, sizeof(jigglymap_png));
774 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
775 img->width, img->height, 0, GL_RGBA,
776 GL_UNSIGNED_BYTE, img->data);
781 static void setup_opengl(ModeInfo *mi, jigglystruct *js)
783 const GLfloat lpos0[4] = {-12, 8, 12, 0};
784 const GLfloat lpos1[4] = {7, -5, 0, 0};
785 const GLfloat lcol0[4] = {0.7f, 0.7f, 0.65f, 1};
786 const GLfloat lcol1[4] = {0.3f, 0.2f, 0.1f, 1};
787 const GLfloat scolor[4]= {0.9f, 0.9f, 0.9f, 0.5f};
789 glDrawBuffer(GL_BACK);
790 glShadeModel(GL_SMOOTH);
791 glEnable(GL_DEPTH_TEST);
793 if(js->do_wireframe) {
794 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
799 glEnable(GL_CULL_FACE);
802 if(js->color_style != COLOR_STYLE_CHROME) {
803 glEnable(GL_LIGHTING);
807 glLightfv(GL_LIGHT0, GL_POSITION, lpos0);
808 glLightfv(GL_LIGHT1, GL_POSITION, lpos1);
809 glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol0);
810 glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol1);
812 glEnable(GL_COLOR_MATERIAL);
813 glColor4fv(js->jiggly_color);
815 glMaterialfv(GL_FRONT, GL_SPECULAR, scolor);
816 glMateriali(GL_FRONT, GL_SHININESS, js->shininess);
820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
822 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
823 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
824 glEnable(GL_TEXTURE_GEN_S);
825 glEnable(GL_TEXTURE_GEN_T);
826 glEnable(GL_TEXTURE_2D);
827 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
833 static int parse_color(jigglystruct *js)
835 unsigned int r, g, b;
836 if(!strcmp(color, "clownbarf")) {
837 js->color_style = COLOR_STYLE_CLOWNBARF;
840 else if(!strcmp(color, "flowerbox")) {
841 js->color_style = COLOR_STYLE_FLOWERBOX;
844 # ifndef HAVE_JWZGLES /* SPHERE_MAP unimplemented */
845 else if(!strcmp(color, "chrome")) {
846 js->color_style = COLOR_STYLE_CHROME;
850 else if(!strcmp(color, "cycle")) {
851 js->color_style = COLOR_STYLE_CYCLE;
852 js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
853 js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
854 js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
855 js->jiggly_color[3] = 1.0f;
856 js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
857 js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
858 js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
863 if(strlen(color) != 7)
865 if(sscanf(color,"#%02x%02x%02x", &r, &g, &b) != 3) {
868 js->jiggly_color[0] = ((float)r)/255;
869 js->jiggly_color[1] = ((float)g)/255;
870 js->jiggly_color[2] = ((float)b)/255;
871 js->jiggly_color[3] = 1.0f;
876 static void randomize_parameters(jigglystruct *js) {
877 do_tetrahedron = random() & 1;
878 # ifndef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
879 js->do_wireframe = !(random() & 3);
881 js->color_style = random() % 5;
882 # ifdef HAVE_JWZGLES /* #### SPHERE_MAP unimplemented */
883 while (js->color_style == COLOR_STYLE_CHROME)
884 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 static 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 ENTRYPOINT Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
931 jigglystruct *js = &jss[MI_SCREEN(mi)];
933 if (gltrackball_event_handler (event, js->trackball,
934 MI_WIDTH (mi), MI_HEIGHT (mi),
941 ENTRYPOINT void reshape_jigglypuff(ModeInfo *mi, int width, int height)
943 double h = (GLfloat) height / (GLfloat) width;
946 if (width > height * 5) { /* tiny window: show middle */
947 height = width * 9/16;
949 h = height / (GLfloat) width;
952 glViewport(0, y, width, height);
953 glMatrixMode(GL_PROJECTION);
955 glFrustum(-0.5*(1/h), 0.5*(1/h), -0.5, 0.5, 1, 20);
958 ENTRYPOINT void draw_jigglypuff(ModeInfo *mi)
960 jigglystruct *js = &jss[MI_SCREEN(mi)];
962 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
964 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
966 glMatrixMode(GL_MODELVIEW);
968 glTranslatef(0,0,-10);
971 # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
973 GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
974 int o = (int) current_device_rotation();
975 if (o != 0 && o != 180 && o != -180)
976 glScalef (1/h, 1/h, 1/h);
980 glRotatef(js->angle, sin(js->axis), cos(js->axis), -sin(js->axis));
981 glTranslatef(0, 0, 5);
982 if(!(js->button_down)) {
983 if((js->angle += js->speed) >= 360.0f ) {
986 if((js->axis+=0.01f) >= 2*M_PI ) {
991 gltrackball_rotate(js->trackball);
993 if(js->color_style == COLOR_STYLE_CYCLE) {
995 vector_add(js->jiggly_color, js->color_dir, js->jiggly_color);
998 if(js->jiggly_color[i] > 1.0 || js->jiggly_color[i] < 0.3) {
999 js->color_dir[i] = (-js->color_dir[i]);
1000 js->jiggly_color[i] += js->color_dir[i];
1003 glColor4fv(js->jiggly_color);
1006 mi->polygon_count = jigglypuff_render(js);
1011 glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
1014 ENTRYPOINT void init_jigglypuff(ModeInfo *mi)
1021 js = &jss[MI_SCREEN(mi)];
1023 js->do_wireframe = MI_IS_WIREFRAME(mi);
1024 # ifdef HAVE_JWZGLES
1025 js->do_wireframe = 0; /* GL_LINE unimplemented */
1028 js->shininess = shininess;
1030 subdivs = (complexity==1) ? 4 : (complexity==2) ? 5
1031 : (complexity==3) ? 6 : 5;
1033 js->spooky = spooky << (subdivs-3);
1035 if(!parse_color(js)) {
1036 fprintf(stderr, "%s: Bad color specification: '%s'.\n", progname, color);
1041 randomize_parameters(js);
1043 js->angle = frand(180);
1044 js->axis = frand(M_PI);
1046 js->shape = tesselated_tetrahedron(1, subdivs, js);
1049 solid_spherify(js->shape, 1);
1051 if(js->color_style == COLOR_STYLE_CLOWNBARF)
1052 clownbarf_colorize(js->shape);
1054 calculate_parameters(js, subdivs);
1056 if((js->glx_context = init_GL(mi)) != NULL) {
1057 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
1058 setup_opengl(mi, js);
1059 reshape_jigglypuff(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1064 js->trackball = gltrackball_init(True);
1065 /* _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
1066 js->stable_distance, js->hold_strength, js->spherify_strength,
1067 js->damping_velocity, js->damping_factor);
1068 _DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
1069 js->do_wireframe, js->spooky, js->color_style, js->shininess);*/
1072 XSCREENSAVER_MODULE ("JigglyPuff", jigglypuff)
1076 /* This is the end of the file */