1 /* flipflop, Copyright (c) 2003 Kevin Ogden <kogden1@hotmail.com>
2 * (c) 2006 Sergio GutiƩrrez "Sergut" <sergut@gmail.com>
3 * (c) 2008 Andrew Galante <a.drew7@gmail.com>
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
14 * 2003 Kevin Odgen First version
15 * 2006 Sergio GutiƩrrez "Sergut" Made several parameters dynamic and selectable
16 * from the command line: size of the board,
17 * rotation speed and number of free squares; also
18 * added the "sticks" mode.
19 * 2008 Andrew Galante Added -textured option: textures the board with
20 * an image which gets scrambled as the tiles move
24 #define DEF_MODE "tiles" /* Default mode (options: "tiles", "sticks") */
25 #define DEF_SIZEX "9" /* Default width of the board */
26 #define DEF_SIZEY "9" /* Default length of the board */
28 #define DEF_BOARD_SIZE "0" /* "0" means "no value selected by user". It is changed */
29 #define DEF_NUMSQUARES "0" /* in function init_flipflop() to its correct value (that */
30 #define DEF_FREESQUARES "0" /* is a function of the size of the board and the mode)*/
32 #define DEF_SPIN "0.1" /* Default angular velocity: PI/10 rads/s */
34 #define DEF_TEXTURED "False" /* Default: do not grab an image for texturing */
36 #define DEF_STICK_THICK 54 /* Thickness for the sticks mode (over 100) */
37 #define DEF_STICK_RATIO 80 /* Ratio of sticks/total squares (over 100) */
38 #define DEF_TILE_THICK 4 /* Thickness for the tiles mode (over 100) */
39 #define DEF_TILE_RATIO 95 /* Ratio of tiles/total squares (over 100) */
42 #define DEFAULTS "*delay: 20000 \n" \
43 "*showFPS: False \n" \
44 "*wireframe: False \n"
46 # define refresh_flipflop 0
47 # include "xlockmore.h"
51 #endif /* STANDALONE */
55 #include "gltrackball.h"
58 #define countof(x) (sizeof((x))/sizeof((*x)))
60 static XrmOptionDescRec opts[] = {
61 {"-sticks", ".mode", XrmoptionNoArg, "sticks"},
62 {"-tiles", ".mode", XrmoptionNoArg, "tiles" },
63 {"-mode", ".mode", XrmoptionSepArg, 0 },
64 {"-size", ".size", XrmoptionSepArg, 0 },
65 {"-size-x", ".sizex", XrmoptionSepArg, 0 },
66 {"-size-y", ".sizey", XrmoptionSepArg, 0 },
67 {"-count", ".numsquares", XrmoptionSepArg, 0 },
68 {"-free", ".freesquares", XrmoptionSepArg, 0 },
69 {"-spin", ".spin", XrmoptionSepArg, 0 },
70 {"-texture", ".textured", XrmoptionNoArg, "True" },
71 {"+texture", ".textured", XrmoptionNoArg, "False" },
74 static int wire, clearbits;
75 static int board_x_size, board_y_size, board_avg_size;
76 static int numsquares, freesquares;
77 static float half_thick;
79 static char* flipflopmode_str="tiles";
82 static argtype vars[] = {
83 { &flipflopmode_str, "mode", "Mode", DEF_MODE, t_String},
84 { &board_avg_size, "size", "Integer", DEF_BOARD_SIZE, t_Int},
85 { &board_x_size, "sizex", "Integer", DEF_SIZEX, t_Int},
86 { &board_y_size, "sizey", "Integer", DEF_SIZEY, t_Int},
87 { &numsquares, "numsquares", "Integer", DEF_NUMSQUARES, t_Int},
88 { &freesquares, "freesquares", "Integer", DEF_NUMSQUARES, t_Int},
89 { &spin, "spin", "Float", DEF_SPIN, t_Float},
90 { &textured, "textured", "Bool", DEF_TEXTURED, t_Bool},
93 ENTRYPOINT ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars, NULL};
96 ModStruct flipflop_description =
97 {"flipflop", "init_flipflop", "draw_flipflop", "release_flipflop",
98 "draw_flipflop", "init_flipflop", NULL, &flipflop_opts,
99 1000, 1, 2, 1, 4, 1.0, "",
100 "Flipflop", 0, NULL};
102 #endif /* USE_MODULES */
105 /* array specifying which squares are where (to avoid collisions) */
106 /* -1 means empty otherwise integer represents square index 0 - n-1 */
107 /* occupied[x*board_y_size+y] is the tile [x][y] (i.e. that starts at column x and row y)*/
108 int *occupied; /* size: size_x * size_y */
109 /* an array of xpositions of the squares */
110 int *xpos; /* size: numsquares */
111 /* array of y positions of the squares */
112 int *ypos; /* size: numsquares */
113 /* integer representing the direction of movement of a square */
114 int *direction; /* 0 not, 1 x+, 2 y+, 3 x-, 4 y-*/ /* size: numsquares */
115 /* angle of moving square (during a flip) */
116 float *angle; /* size: numsquares */
117 /* array of colors for a square (RGB) */
118 /* eg. color[ 3*3 + 0 ] is the red component of square 3 */
119 /* eg. color[ 4*3 + 1 ] is the green component of square 4 */
120 /* eg. color[ 5*3 + 2 ] is the blue component of square 5 */
121 /* ^-- n is the number of square */
122 float *color; /* size: numsquares * 3 */
123 /* array of texcoords for each square */
124 /* tex[ n*4 + 0 ] is x texture coordinate of square n's left side */
125 /* tex[ n*4 + 1 ] is y texture coordinate of square n's top side */
126 /* tex[ n*4 + 2 ] is x texture coordinate of square n's right side */
127 /* tex[ n*4 + 3 ] is y texture coordinate of square n's bottom side */
128 float *tex; /* size: numsquares * 4 */
132 GLXContext *glx_context;
134 trackball_state *trackball;
139 float theta; /* angle of rotation of the board */
140 float flipspeed; /* amount of flip; 1 is a entire flip */
141 float reldist; /* relative distace of camera from center */
142 float energy; /* likelyhood that a square will attempt to move */
144 /* texture rectangle */
150 /* id of texture in use */
160 static Flipflopcreen *qs = NULL;
162 #include "grab-ximage.h"
164 static void randsheet_create( randsheet *rs );
165 static void randsheet_initialize( randsheet *rs );
166 static void randsheet_free( randsheet *rs );
167 static int randsheet_new_move( randsheet* rs );
168 static void randsheet_move( randsheet *rs, float rot );
169 static int randsheet_draw( randsheet *rs );
170 static void setup_lights(void);
171 static int drawBoard(Flipflopcreen *);
172 static int display(ModeInfo *mi);
173 static int draw_sheet(float *tex);
176 /* configure lighting */
180 /* GLfloat position0[] = { board_avg_size*0.5, board_avg_size*0.1, board_avg_size*0.5, 1.0 }; */
182 /* GLfloat position0[] = { -board_avg_size*0.5, 0.2*board_avg_size, -board_avg_size*0.5, 1.0 }; */
183 GLfloat position0[4];
185 position0[1] = board_avg_size*0.3;
191 glEnable(GL_LIGHTING);
192 glLightfv(GL_LIGHT0, GL_POSITION, position0);
196 static void get_texture(ModeInfo *);
200 flipflop_handle_event (ModeInfo *mi, XEvent *event)
202 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
204 if (gltrackball_event_handler (event, c->trackball,
205 MI_WIDTH (mi), MI_HEIGHT (mi),
208 else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
210 if (!textured || c->got_texture)
213 c->got_texture = False;
224 drawBoard(Flipflopcreen *c)
227 for( i=0; i < (c->energy) ; i++ ) {
228 randsheet_new_move( c->sheet );
230 randsheet_move( c->sheet, c->flipspeed * 3.14159 );
231 return randsheet_draw( c->sheet );
236 display(ModeInfo *mi)
238 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
239 GLfloat amb[] = { 0.8, 0.8, 0.8, 1.0 };
244 glMatrixMode(GL_MODELVIEW);
246 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.2);
247 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.15/board_avg_size );
248 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.15/board_avg_size );
249 glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
252 glRotatef(current_device_rotation(), 0, 0, 1);
254 /** setup perspectif */
255 glTranslatef(0.0, 0.0, -c->reldist*board_avg_size);
256 glRotatef(22.5, 1.0, 0.0, 0.0);
257 gltrackball_rotate (c->trackball);
258 glRotatef(c->theta*100, 0.0, 1.0, 0.0);
259 glTranslatef(-0.5*board_x_size, 0.0, -0.5*board_y_size); /* Center the board */
263 glBindTexture(GL_TEXTURE_2D, c->texid);
265 # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
267 GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
268 int o = (int) current_device_rotation();
269 if (o != 0 && o != 180 && o != -180)
270 glScalef (1/h, 1/h, 1/h);
274 polys = drawBoard(c);
276 if (!c->button_down_p) {
277 c->theta += .01 * spin;
284 reshape_flipflop(ModeInfo *mi, int width, int height)
286 GLfloat h = (GLfloat) height / (GLfloat) width;
287 glViewport(0,0, width, height);
288 glMatrixMode(GL_PROJECTION);
290 gluPerspective(45, 1/h, 1.0, 300.0);
291 glMatrixMode(GL_MODELVIEW);
295 image_loaded_cb (const char *filename, XRectangle *geometry,
296 int image_width, int image_height,
297 int texture_width, int texture_height,
300 Flipflopcreen *c = (Flipflopcreen *)closure;
303 randsheet *rs = c->sheet;
305 c->tex_x = (float)geometry->x / (float)texture_width;
306 c->tex_y = (float)geometry->y / (float)texture_height;
307 c->tex_width = (float)geometry->width / (float)texture_width;
308 c->tex_height = (float)geometry->height / (float)texture_height;
310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
312 (c->mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
314 if(c->anisotropic >= 1)
315 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, c->anisotropic);
317 glEnable(GL_TEXTURE_2D);
319 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
321 for(i = 0; i < board_x_size && index < numsquares; i++)
322 for(j = 0; j < board_y_size && index < numsquares; j++)
324 /* arrange squares to form loaded image */
325 rs->tex[ index*4 + 0 ] = c->tex_x + c->tex_width / board_x_size * (i + 0);
326 rs->tex[ index*4 + 1 ] = c->tex_y + c->tex_height / board_y_size * (j + 1);
327 rs->tex[ index*4 + 2 ] = c->tex_x + c->tex_width / board_x_size * (i + 1);
328 rs->tex[ index*4 + 3 ] = c->tex_y + c->tex_height / board_y_size * (j + 0);
329 rs->color[ index*3 + 0 ] = 1;
330 rs->color[ index*3 + 1 ] = 1;
331 rs->color[ index*3 + 2 ] = 1;
335 c->got_texture = True;
339 get_texture(ModeInfo *modeinfo)
341 Flipflopcreen *c = &qs[MI_SCREEN(modeinfo)];
343 c->got_texture = False;
345 load_texture_async (modeinfo->xgwa.screen, modeinfo->window,
346 *c->glx_context, 0, 0, c->mipmap, c->texid,
351 init_flipflop(ModeInfo *mi)
356 if (MI_IS_WIREFRAME(mi)) textured = 0;
358 /* Set all constants to their correct values */
359 if (board_avg_size != 0) { /* general size specified by user */
360 board_x_size = board_avg_size;
361 board_y_size = board_avg_size;
363 board_avg_size = (board_x_size + board_y_size) / 2;
365 if ((numsquares == 0) && (freesquares != 0)) {
366 numsquares = board_x_size * board_y_size - freesquares;
368 if (strcmp(flipflopmode_str, "tiles")) {
369 textured = 0; /* textures look dumb in stick mode */
370 half_thick = 1.0 * DEF_STICK_THICK / 100.0;
371 if (numsquares == 0) { /* No value defined by user */
372 numsquares = board_x_size * board_y_size * DEF_STICK_RATIO / 100;
375 half_thick = 1.0 * DEF_TILE_THICK / 100.0;
376 if (numsquares == 0) { /* No value defined by user */
377 numsquares = board_x_size * board_y_size * DEF_TILE_RATIO/ 100;;
380 if (board_avg_size < 2) {
381 fprintf (stderr,"%s: the board must be at least 2x2.\n", progname);
384 if ((board_x_size < 1) || (board_y_size < 1) || (numsquares < 1)) {
385 fprintf (stderr,"%s: the number of elements ('-count') and the dimensions of the board ('-size-x', '-size-y') must be positive integers.\n", progname);
388 if (board_x_size * board_y_size <= numsquares) {
389 fprintf (stderr,"%s: the number of elements ('-count') that you specified is too big \n for the dimensions of the board ('-size-x', '-size-y'). Nothing will move.\n", progname);
392 screen = MI_SCREEN(mi);
393 wire = MI_IS_WIREFRAME(mi);
396 !(qs = (Flipflopcreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Flipflopcreen))))
400 c->window = MI_WINDOW(mi);
401 c->trackball = gltrackball_init (False);
407 if((c->glx_context = init_GL(mi)))
408 reshape_flipflop(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
412 /* At this point, all the constants have already been set, */
413 /* so we can create the board */
414 c->sheet = (randsheet*) malloc(sizeof(randsheet));
415 randsheet_create( c->sheet );
417 clearbits = GL_COLOR_BUFFER_BIT;
419 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
420 glEnable(GL_COLOR_MATERIAL);
423 glEnable(GL_DEPTH_TEST);
424 clearbits |= GL_DEPTH_BUFFER_BIT;
425 glEnable(GL_CULL_FACE);
428 randsheet_initialize( c->sheet );
430 /* check for anisotropic filtering */
431 if(strstr((char *)glGetString(GL_EXTENSIONS),
432 "GL_EXT_texture_filter_anisotropic"))
433 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &c->anisotropic);
437 /* allocate a new texture and get it */
438 glGenTextures(1, &c->texid);
444 draw_flipflop(ModeInfo *mi)
446 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
447 Window w = MI_WINDOW(mi);
448 Display *disp = MI_DISPLAY(mi);
450 if(!c->glx_context || (textured && !c->got_texture))
453 glXMakeCurrent(disp, w, *(c->glx_context));
455 mi->polygon_count = display(mi);
462 glXSwapBuffers(disp, w);
468 release_flipflop(ModeInfo *mi)
473 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
475 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
479 randsheet_free(c->sheet);
491 /*** ADDED RANDSHEET FUNCTIONS ***/
494 draw_sheet(float *tex)
497 glBegin( wire ? GL_LINE_LOOP : GL_QUADS );
499 glNormal3f( 0, -1, 0 );
500 glTexCoord2f(tex[0], tex[3]);
501 glVertex3f( half_thick, -half_thick, half_thick );
502 glTexCoord2f(tex[2], tex[3]);
503 glVertex3f( 1-half_thick, -half_thick, half_thick );
504 glTexCoord2f(tex[2], tex[1]);
505 glVertex3f( 1-half_thick, -half_thick, 1-half_thick);
506 glTexCoord2f(tex[0], tex[1]);
507 glVertex3f( half_thick, -half_thick, 1-half_thick );
510 if (wire) { glEnd(); glBegin (GL_LINE_LOOP); }
513 glNormal3f( 0, 1, 0 );
514 glTexCoord2f(tex[0], tex[1]);
515 glVertex3f( half_thick, half_thick, 1-half_thick );
516 glTexCoord2f(tex[2], tex[1]);
517 glVertex3f( 1-half_thick, half_thick, 1-half_thick);
518 glTexCoord2f(tex[2], tex[3]);
519 glVertex3f( 1-half_thick, half_thick, half_thick );
520 glTexCoord2f(tex[0], tex[3]);
521 glVertex3f( half_thick, half_thick, half_thick );
524 if (wire) { glEnd(); return polys; }
526 /* 4 edges!!! weee.... */
527 glNormal3f( 0, 0, -1 );
528 glTexCoord2f(tex[0], tex[3]);
529 glVertex3f( half_thick, half_thick, half_thick );
530 glTexCoord2f(tex[2], tex[3]);
531 glVertex3f( 1-half_thick, half_thick, half_thick );
532 glTexCoord2f(tex[2], tex[3]);
533 glVertex3f( 1-half_thick, -half_thick, half_thick );
534 glTexCoord2f(tex[0], tex[3]);
535 glVertex3f( half_thick, -half_thick, half_thick );
537 glNormal3f( 0, 0, 1 );
538 glTexCoord2f(tex[0], tex[1]);
539 glVertex3f( half_thick, half_thick, 1-half_thick );
540 glTexCoord2f(tex[0], tex[1]);
541 glVertex3f( half_thick, -half_thick, 1-half_thick );
542 glTexCoord2f(tex[2], tex[1]);
543 glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
544 glTexCoord2f(tex[2], tex[1]);
545 glVertex3f( 1-half_thick, half_thick, 1-half_thick );
547 glNormal3f( 1, 0, 0 );
548 glTexCoord2f(tex[2], tex[1]);
549 glVertex3f( 1-half_thick, half_thick, 1-half_thick );
550 glTexCoord2f(tex[2], tex[1]);
551 glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
552 glTexCoord2f(tex[2], tex[3]);
553 glVertex3f( 1-half_thick, -half_thick, half_thick );
554 glTexCoord2f(tex[2], tex[3]);
555 glVertex3f( 1-half_thick, half_thick, half_thick );
557 glNormal3f( -1, 0, 0 );
558 glTexCoord2f(tex[0], tex[1]);
559 glVertex3f( half_thick, half_thick, 1-half_thick );
560 glTexCoord2f(tex[0], tex[3]);
561 glVertex3f( half_thick, half_thick, half_thick );
562 glTexCoord2f(tex[0], tex[3]);
563 glVertex3f( half_thick, -half_thick, half_thick );
564 glTexCoord2f(tex[0], tex[1]);
565 glVertex3f( half_thick, -half_thick, 1-half_thick );
572 /* Reserve memory for the randsheet */
574 randsheet_create( randsheet *rs )
576 rs -> occupied = (int*) malloc(board_x_size*board_y_size * sizeof(int));
577 rs -> xpos = (int*) malloc(numsquares * sizeof(int));
578 rs -> ypos = (int*) malloc(numsquares * sizeof(int));
579 rs -> direction = (int*) malloc(numsquares * sizeof(int));
580 rs -> angle = (float*) malloc(numsquares * sizeof(float));
581 rs -> color = (float*) malloc(numsquares*3 * sizeof(float));
582 rs -> tex = (float*) malloc(numsquares*4 * sizeof(float));
585 /* Free reserved memory for the randsheet */
587 randsheet_free( randsheet *rs )
599 randsheet_initialize( randsheet *rs )
603 /* put the moving sheets on the board */
604 for( i = 0; i < board_x_size; i++ )
606 for( j = 0; j < board_y_size; j++ )
608 /* initially fill up a corner with the moving squares */
609 if( index < numsquares )
611 rs->occupied[ i * board_y_size + j ] = index;
612 rs->xpos[ index ] = i;
613 rs->ypos[ index ] = j;
614 /* have the square colors start out as a pattern */
615 rs->color[ index*3 + 0 ] = ((i+j)%3 == 0)||((i+j+1)%3 == 0);
616 rs->color[ index*3 + 1 ] = ((i+j+1)%3 == 0);
617 rs->color[ index*3 + 2 ] = ((i+j+2)%3 == 0);
620 /* leave everything else empty*/
623 rs->occupied[ i * board_y_size + j ] = -1;
627 /* initially everything is at rest */
628 for( i=0; i<numsquares; i++ )
630 rs->direction[ i ] = 0;
635 /* Pick and random square and direction and try to move it. */
636 /* May not actually move anything, just attempt a random move. */
637 /* Returns true if move was sucessful. */
638 /* This could probably be implemented faster in a dequeue */
639 /* to avoid trying to move a square which is already moving */
640 /* but speed is most likely bottlenecked by rendering anyway... */
642 randsheet_new_move( randsheet* rs )
646 /* pick a random square */
647 num = random( ) % numsquares;
650 /* pick a random direction */
651 dir = ( random( )% 4 ) + 1;
653 if( rs->direction[ num ] == 0 )
659 if( ( i + 1 ) < board_x_size )
661 if( rs->occupied[ (i + 1) * board_y_size + j ] == -1 )
663 rs->direction[ num ] = dir;
664 rs->occupied[ (i + 1) * board_y_size + j ] = num;
665 rs->occupied[ i * board_y_size + j ] = -1;
673 if( ( j + 1 ) < board_y_size )
675 if( rs->occupied[ i * board_y_size + (j + 1) ] == -1 )
677 rs->direction[ num ] = dir;
678 rs->occupied[ i * board_y_size + (j + 1) ] = num;
679 rs->occupied[ i * board_y_size + j ] = -1;
689 if( rs->occupied[ (i - 1) * board_y_size + j ] == -1 )
691 rs->direction[ num ] = dir;
692 rs->occupied[ (i - 1) * board_y_size + j ] = num;
693 rs->occupied[ i * board_y_size + j ] = -1;
703 if( rs->occupied[ i * board_y_size + (j - 1) ] == -1 )
705 rs->direction[ num ] = dir;
706 rs->occupied[ i * board_y_size + (j - 1) ] = num;
707 rs->occupied[ i * board_y_size + j ] = -1;
720 /* move a single frame. */
721 /* Pass in the angle in rads the square rotates in a frame. */
723 randsheet_move( randsheet *rs, float rot )
727 for( index = 0 ; index < numsquares; index++ )
729 switch( rs->direction[ index ] )
736 if( textured && rs->angle[ index ] == 0 )
738 tmp = rs->tex[ index * 4 + 0 ];
739 rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
740 rs->tex[ index * 4 + 2 ] = tmp;
742 rs->angle[ index ] += rot;
743 /* check to see if we have finished moving */
744 if( rs->angle[ index ] >= M_PI )
746 rs->xpos[ index ] += 1;
747 rs->direction[ index ] = 0;
748 rs->angle[ index ] = 0;
753 if( textured && rs->angle[ index ] == 0 )
755 tmp = rs->tex[ index * 4 + 1 ];
756 rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
757 rs->tex[ index * 4 + 3 ] = tmp;
759 rs->angle[ index ] += rot;
760 /* check to see if we have finished moving */
761 if( rs->angle[ index ] >= M_PI )
763 rs->ypos[ index ] += 1;
764 rs->direction[ index ] = 0;
765 rs->angle[ index ] = 0;
770 rs->angle[ index ] += rot;
771 /* check to see if we have finished moving */
772 if( rs->angle[ index ] >= M_PI )
774 rs->xpos[ index ] -= 1;
775 rs->direction[ index ] = 0;
776 rs->angle[ index ] = 0;
779 tmp = rs->tex[ index * 4 + 0 ];
780 rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
781 rs->tex[ index * 4 + 2 ] = tmp;
787 rs->angle[ index ] += rot;
788 /* check to see if we have finished moving */
789 if( rs->angle[ index ] >= M_PI )
791 rs->ypos[ index ] -= 1;
792 rs->direction[ index ] = 0;
793 rs->angle[ index ] = 0;
796 tmp = rs->tex[ index * 4 + 1 ];
797 rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
798 rs->tex[ index * 4 + 3 ] = tmp;
809 /* draw all the moving squares */
811 randsheet_draw( randsheet *rs )
816 /* for all moving squares ... */
817 for( index = 0; index < numsquares; index++ )
820 glColor3f( rs->color[ index*3 + 0 ],
821 rs->color[ index*3 + 1 ],
822 rs->color[ index*3 + 2 ] );
823 /* find x and y position */
824 i = rs->xpos[ index ];
825 j = rs->ypos[ index ];
827 switch( rs->direction[ index ] )
833 glTranslatef( i, 0, j );
836 glTranslatef( i+1, 0, j );
837 glRotatef( 180 - rs->angle[ index ]*180/M_PI, 0, 0, 1 );
841 glTranslatef( i, 0, j+1 );
842 glRotatef( 180 - rs->angle[ index ]*180/M_PI, -1, 0, 0 );
846 glTranslatef( i, 0, j );
847 glRotatef( rs->angle[ index ]*180/M_PI, 0, 0, 1 );
850 glTranslatef( i, 0, j );
851 glRotatef( rs->angle[ index ]*180/M_PI, -1, 0, 0 );
856 polys += draw_sheet( rs->tex + index*4 );
863 /**** END RANDSHEET_BAK FUNCTIONS ***/
865 XSCREENSAVER_MODULE ("FlipFlop", flipflop)