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 # define release_flipflop 0
48 # include "xlockmore.h"
52 #endif /* STANDALONE */
56 #include "gltrackball.h"
59 #define countof(x) (sizeof((x))/sizeof((*x)))
61 static XrmOptionDescRec opts[] = {
62 {"-sticks", ".mode", XrmoptionNoArg, "sticks"},
63 {"-tiles", ".mode", XrmoptionNoArg, "tiles" },
64 {"-mode", ".mode", XrmoptionSepArg, 0 },
65 {"-size", ".size", XrmoptionSepArg, 0 },
66 {"-size-x", ".sizex", XrmoptionSepArg, 0 },
67 {"-size-y", ".sizey", XrmoptionSepArg, 0 },
68 {"-count", ".numsquares", XrmoptionSepArg, 0 },
69 {"-free", ".freesquares", XrmoptionSepArg, 0 },
70 {"-spin", ".spin", XrmoptionSepArg, 0 },
71 {"-texture", ".textured", XrmoptionNoArg, "True" },
72 {"+texture", ".textured", XrmoptionNoArg, "False" },
75 static int wire, clearbits;
76 static int board_x_size, board_y_size, board_avg_size;
77 static int numsquares, freesquares;
78 static float half_thick;
80 static char* flipflopmode_str="tiles";
83 static argtype vars[] = {
84 { &flipflopmode_str, "mode", "Mode", DEF_MODE, t_String},
85 { &board_avg_size, "size", "Integer", DEF_BOARD_SIZE, t_Int},
86 { &board_x_size, "sizex", "Integer", DEF_SIZEX, t_Int},
87 { &board_y_size, "sizey", "Integer", DEF_SIZEY, t_Int},
88 { &numsquares, "numsquares", "Integer", DEF_NUMSQUARES, t_Int},
89 { &freesquares, "freesquares", "Integer", DEF_NUMSQUARES, t_Int},
90 { &spin, "spin", "Float", DEF_SPIN, t_Float},
91 { &textured, "textured", "Bool", DEF_TEXTURED, t_Bool},
94 ENTRYPOINT ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars, NULL};
97 ModStruct flipflop_description =
98 {"flipflop", "init_flipflop", "draw_flipflop", NULL,
99 "draw_flipflop", "init_flipflop", NULL, &flipflop_opts,
100 1000, 1, 2, 1, 4, 1.0, "",
101 "Flipflop", 0, NULL};
103 #endif /* USE_MODULES */
106 /* array specifying which squares are where (to avoid collisions) */
107 /* -1 means empty otherwise integer represents square index 0 - n-1 */
108 /* occupied[x*board_y_size+y] is the tile [x][y] (i.e. that starts at column x and row y)*/
109 int *occupied; /* size: size_x * size_y */
110 /* an array of xpositions of the squares */
111 int *xpos; /* size: numsquares */
112 /* array of y positions of the squares */
113 int *ypos; /* size: numsquares */
114 /* integer representing the direction of movement of a square */
115 int *direction; /* 0 not, 1 x+, 2 y+, 3 x-, 4 y-*/ /* size: numsquares */
116 /* angle of moving square (during a flip) */
117 float *angle; /* size: numsquares */
118 /* array of colors for a square (RGB) */
119 /* eg. color[ 3*3 + 0 ] is the red component of square 3 */
120 /* eg. color[ 4*3 + 1 ] is the green component of square 4 */
121 /* eg. color[ 5*3 + 2 ] is the blue component of square 5 */
122 /* ^-- n is the number of square */
123 float *color; /* size: numsquares * 3 */
124 /* array of texcoords for each square */
125 /* tex[ n*4 + 0 ] is x texture coordinate of square n's left side */
126 /* tex[ n*4 + 1 ] is y texture coordinate of square n's top side */
127 /* tex[ n*4 + 2 ] is x texture coordinate of square n's right side */
128 /* tex[ n*4 + 3 ] is y texture coordinate of square n's bottom side */
129 float *tex; /* size: numsquares * 4 */
133 GLXContext *glx_context;
135 trackball_state *trackball;
140 float theta; /* angle of rotation of the board */
141 float flipspeed; /* amount of flip; 1 is a entire flip */
142 float reldist; /* relative distace of camera from center */
143 float energy; /* likelyhood that a square will attempt to move */
145 /* texture rectangle */
151 /* id of texture in use */
161 static Flipflopcreen *qs = NULL;
163 #include "grab-ximage.h"
165 static void randsheet_create( randsheet *rs );
166 static void randsheet_initialize( randsheet *rs );
167 static void randsheet_free( randsheet *rs );
168 static int randsheet_new_move( randsheet* rs );
169 static void randsheet_move( randsheet *rs, float rot );
170 static int randsheet_draw( randsheet *rs );
171 static void setup_lights(void);
172 static int drawBoard(Flipflopcreen *);
173 static int display(ModeInfo *mi);
174 static int draw_sheet(float *tex);
177 /* configure lighting */
181 /* GLfloat position0[] = { board_avg_size*0.5, board_avg_size*0.1, board_avg_size*0.5, 1.0 }; */
183 /* GLfloat position0[] = { -board_avg_size*0.5, 0.2*board_avg_size, -board_avg_size*0.5, 1.0 }; */
184 GLfloat position0[4];
186 position0[1] = board_avg_size*0.3;
192 glEnable(GL_LIGHTING);
193 glLightfv(GL_LIGHT0, GL_POSITION, position0);
197 static void get_texture(ModeInfo *);
201 flipflop_handle_event (ModeInfo *mi, XEvent *event)
203 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
205 if (gltrackball_event_handler (event, c->trackball,
206 MI_WIDTH (mi), MI_HEIGHT (mi),
209 else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
211 if (!textured || c->got_texture)
214 c->got_texture = False;
225 drawBoard(Flipflopcreen *c)
228 for( i=0; i < (c->energy) ; i++ ) {
229 randsheet_new_move( c->sheet );
231 randsheet_move( c->sheet, c->flipspeed * 3.14159 );
232 return randsheet_draw( c->sheet );
237 display(ModeInfo *mi)
239 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
240 GLfloat amb[] = { 0.8, 0.8, 0.8, 1.0 };
245 glMatrixMode(GL_MODELVIEW);
247 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.2);
248 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.15/board_avg_size );
249 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.15/board_avg_size );
250 glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
253 glRotatef(current_device_rotation(), 0, 0, 1);
255 /** setup perspectif */
256 glTranslatef(0.0, 0.0, -c->reldist*board_avg_size);
257 glRotatef(22.5, 1.0, 0.0, 0.0);
258 gltrackball_rotate (c->trackball);
259 glRotatef(c->theta*100, 0.0, 1.0, 0.0);
260 glTranslatef(-0.5*board_x_size, 0.0, -0.5*board_y_size); /* Center the board */
264 glBindTexture(GL_TEXTURE_2D, c->texid);
266 # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
268 GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
269 int o = (int) current_device_rotation();
270 if (o != 0 && o != 180 && o != -180)
271 glScalef (1/h, 1/h, 1/h);
275 polys = drawBoard(c);
277 if (!c->button_down_p) {
278 c->theta += .01 * spin;
285 reshape_flipflop(ModeInfo *mi, int width, int height)
287 GLfloat h = (GLfloat) height / (GLfloat) width;
288 glViewport(0,0, width, height);
289 glMatrixMode(GL_PROJECTION);
291 gluPerspective(45, 1/h, 1.0, 300.0);
292 glMatrixMode(GL_MODELVIEW);
296 image_loaded_cb (const char *filename, XRectangle *geometry,
297 int image_width, int image_height,
298 int texture_width, int texture_height,
301 Flipflopcreen *c = (Flipflopcreen *)closure;
304 randsheet *rs = c->sheet;
306 c->tex_x = (float)geometry->x / (float)texture_width;
307 c->tex_y = (float)geometry->y / (float)texture_height;
308 c->tex_width = (float)geometry->width / (float)texture_width;
309 c->tex_height = (float)geometry->height / (float)texture_height;
311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
313 (c->mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
315 if(c->anisotropic >= 1)
316 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, c->anisotropic);
318 glEnable(GL_TEXTURE_2D);
320 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
322 for(i = 0; i < board_x_size && index < numsquares; i++)
323 for(j = 0; j < board_y_size && index < numsquares; j++)
325 /* arrange squares to form loaded image */
326 rs->tex[ index*4 + 0 ] = c->tex_x + c->tex_width / board_x_size * (i + 0);
327 rs->tex[ index*4 + 1 ] = c->tex_y + c->tex_height / board_y_size * (j + 1);
328 rs->tex[ index*4 + 2 ] = c->tex_x + c->tex_width / board_x_size * (i + 1);
329 rs->tex[ index*4 + 3 ] = c->tex_y + c->tex_height / board_y_size * (j + 0);
330 rs->color[ index*3 + 0 ] = 1;
331 rs->color[ index*3 + 1 ] = 1;
332 rs->color[ index*3 + 2 ] = 1;
336 c->got_texture = True;
340 get_texture(ModeInfo *modeinfo)
342 Flipflopcreen *c = &qs[MI_SCREEN(modeinfo)];
344 c->got_texture = False;
346 load_texture_async (modeinfo->xgwa.screen, modeinfo->window,
347 *c->glx_context, 0, 0, c->mipmap, c->texid,
351 static void free_flipflop(ModeInfo *mi);
354 init_flipflop(ModeInfo *mi)
359 if (MI_IS_WIREFRAME(mi)) textured = 0;
361 /* Set all constants to their correct values */
362 if (board_avg_size != 0) { /* general size specified by user */
363 board_x_size = board_avg_size;
364 board_y_size = board_avg_size;
366 board_avg_size = (board_x_size + board_y_size) / 2;
368 if ((numsquares == 0) && (freesquares != 0)) {
369 numsquares = board_x_size * board_y_size - freesquares;
371 if (strcmp(flipflopmode_str, "tiles")) {
372 textured = 0; /* textures look dumb in stick mode */
373 half_thick = 1.0 * DEF_STICK_THICK / 100.0;
374 if (numsquares == 0) { /* No value defined by user */
375 numsquares = board_x_size * board_y_size * DEF_STICK_RATIO / 100;
378 half_thick = 1.0 * DEF_TILE_THICK / 100.0;
379 if (numsquares == 0) { /* No value defined by user */
380 numsquares = board_x_size * board_y_size * DEF_TILE_RATIO/ 100;;
383 if (board_avg_size < 2) {
384 fprintf (stderr,"%s: the board must be at least 2x2.\n", progname);
387 if ((board_x_size < 1) || (board_y_size < 1) || (numsquares < 1)) {
388 fprintf (stderr,"%s: the number of elements ('-count') and the dimensions of the board ('-size-x', '-size-y') must be positive integers.\n", progname);
391 if (board_x_size * board_y_size <= numsquares) {
392 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);
395 screen = MI_SCREEN(mi);
396 wire = MI_IS_WIREFRAME(mi);
398 MI_INIT(mi, qs, free_flipflop);
401 c->window = MI_WINDOW(mi);
402 c->trackball = gltrackball_init (False);
408 if((c->glx_context = init_GL(mi)))
409 reshape_flipflop(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
413 /* At this point, all the constants have already been set, */
414 /* so we can create the board */
415 c->sheet = (randsheet*) malloc(sizeof(randsheet));
416 randsheet_create( c->sheet );
418 clearbits = GL_COLOR_BUFFER_BIT;
420 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
421 glEnable(GL_COLOR_MATERIAL);
424 glEnable(GL_DEPTH_TEST);
425 clearbits |= GL_DEPTH_BUFFER_BIT;
426 glEnable(GL_CULL_FACE);
429 randsheet_initialize( c->sheet );
431 /* check for anisotropic filtering */
432 if(strstr((char *)glGetString(GL_EXTENSIONS),
433 "GL_EXT_texture_filter_anisotropic"))
434 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &c->anisotropic);
438 /* allocate a new texture and get it */
439 glGenTextures(1, &c->texid);
445 draw_flipflop(ModeInfo *mi)
447 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
448 Window w = MI_WINDOW(mi);
449 Display *disp = MI_DISPLAY(mi);
451 if(!c->glx_context || (textured && !c->got_texture))
454 glXMakeCurrent(disp, w, *(c->glx_context));
456 mi->polygon_count = display(mi);
463 glXSwapBuffers(disp, w);
469 free_flipflop(ModeInfo *mi)
471 Flipflopcreen *c = &qs[MI_SCREEN(mi)];
473 randsheet_free(c->sheet);
478 /*** ADDED RANDSHEET FUNCTIONS ***/
481 draw_sheet(float *tex)
484 glBegin( wire ? GL_LINE_LOOP : GL_QUADS );
486 glNormal3f( 0, -1, 0 );
487 glTexCoord2f(tex[0], tex[3]);
488 glVertex3f( half_thick, -half_thick, half_thick );
489 glTexCoord2f(tex[2], tex[3]);
490 glVertex3f( 1-half_thick, -half_thick, half_thick );
491 glTexCoord2f(tex[2], tex[1]);
492 glVertex3f( 1-half_thick, -half_thick, 1-half_thick);
493 glTexCoord2f(tex[0], tex[1]);
494 glVertex3f( half_thick, -half_thick, 1-half_thick );
497 if (wire) { glEnd(); glBegin (GL_LINE_LOOP); }
500 glNormal3f( 0, 1, 0 );
501 glTexCoord2f(tex[0], tex[1]);
502 glVertex3f( half_thick, half_thick, 1-half_thick );
503 glTexCoord2f(tex[2], tex[1]);
504 glVertex3f( 1-half_thick, half_thick, 1-half_thick);
505 glTexCoord2f(tex[2], tex[3]);
506 glVertex3f( 1-half_thick, half_thick, half_thick );
507 glTexCoord2f(tex[0], tex[3]);
508 glVertex3f( half_thick, half_thick, half_thick );
511 if (wire) { glEnd(); return polys; }
513 /* 4 edges!!! weee.... */
514 glNormal3f( 0, 0, -1 );
515 glTexCoord2f(tex[0], tex[3]);
516 glVertex3f( half_thick, half_thick, half_thick );
517 glTexCoord2f(tex[2], tex[3]);
518 glVertex3f( 1-half_thick, half_thick, half_thick );
519 glTexCoord2f(tex[2], tex[3]);
520 glVertex3f( 1-half_thick, -half_thick, half_thick );
521 glTexCoord2f(tex[0], tex[3]);
522 glVertex3f( half_thick, -half_thick, half_thick );
524 glNormal3f( 0, 0, 1 );
525 glTexCoord2f(tex[0], tex[1]);
526 glVertex3f( half_thick, half_thick, 1-half_thick );
527 glTexCoord2f(tex[0], tex[1]);
528 glVertex3f( half_thick, -half_thick, 1-half_thick );
529 glTexCoord2f(tex[2], tex[1]);
530 glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
531 glTexCoord2f(tex[2], tex[1]);
532 glVertex3f( 1-half_thick, half_thick, 1-half_thick );
534 glNormal3f( 1, 0, 0 );
535 glTexCoord2f(tex[2], tex[1]);
536 glVertex3f( 1-half_thick, half_thick, 1-half_thick );
537 glTexCoord2f(tex[2], tex[1]);
538 glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
539 glTexCoord2f(tex[2], tex[3]);
540 glVertex3f( 1-half_thick, -half_thick, half_thick );
541 glTexCoord2f(tex[2], tex[3]);
542 glVertex3f( 1-half_thick, half_thick, half_thick );
544 glNormal3f( -1, 0, 0 );
545 glTexCoord2f(tex[0], tex[1]);
546 glVertex3f( half_thick, half_thick, 1-half_thick );
547 glTexCoord2f(tex[0], tex[3]);
548 glVertex3f( half_thick, half_thick, half_thick );
549 glTexCoord2f(tex[0], tex[3]);
550 glVertex3f( half_thick, -half_thick, half_thick );
551 glTexCoord2f(tex[0], tex[1]);
552 glVertex3f( half_thick, -half_thick, 1-half_thick );
559 /* Reserve memory for the randsheet */
561 randsheet_create( randsheet *rs )
563 rs -> occupied = (int*) malloc(board_x_size*board_y_size * sizeof(int));
564 rs -> xpos = (int*) malloc(numsquares * sizeof(int));
565 rs -> ypos = (int*) malloc(numsquares * sizeof(int));
566 rs -> direction = (int*) malloc(numsquares * sizeof(int));
567 rs -> angle = (float*) malloc(numsquares * sizeof(float));
568 rs -> color = (float*) malloc(numsquares*3 * sizeof(float));
569 rs -> tex = (float*) malloc(numsquares*4 * sizeof(float));
572 /* Free reserved memory for the randsheet */
574 randsheet_free( randsheet *rs )
586 randsheet_initialize( randsheet *rs )
590 /* put the moving sheets on the board */
591 for( i = 0; i < board_x_size; i++ )
593 for( j = 0; j < board_y_size; j++ )
595 /* initially fill up a corner with the moving squares */
596 if( index < numsquares )
598 rs->occupied[ i * board_y_size + j ] = index;
599 rs->xpos[ index ] = i;
600 rs->ypos[ index ] = j;
601 /* have the square colors start out as a pattern */
602 rs->color[ index*3 + 0 ] = ((i+j)%3 == 0)||((i+j+1)%3 == 0);
603 rs->color[ index*3 + 1 ] = ((i+j+1)%3 == 0);
604 rs->color[ index*3 + 2 ] = ((i+j+2)%3 == 0);
607 /* leave everything else empty*/
610 rs->occupied[ i * board_y_size + j ] = -1;
614 /* initially everything is at rest */
615 for( i=0; i<numsquares; i++ )
617 rs->direction[ i ] = 0;
622 /* Pick and random square and direction and try to move it. */
623 /* May not actually move anything, just attempt a random move. */
624 /* Returns true if move was sucessful. */
625 /* This could probably be implemented faster in a dequeue */
626 /* to avoid trying to move a square which is already moving */
627 /* but speed is most likely bottlenecked by rendering anyway... */
629 randsheet_new_move( randsheet* rs )
633 /* pick a random square */
634 num = random( ) % numsquares;
637 /* pick a random direction */
638 dir = ( random( )% 4 ) + 1;
640 if( rs->direction[ num ] == 0 )
646 if( ( i + 1 ) < board_x_size )
648 if( rs->occupied[ (i + 1) * board_y_size + j ] == -1 )
650 rs->direction[ num ] = dir;
651 rs->occupied[ (i + 1) * board_y_size + j ] = num;
652 rs->occupied[ i * board_y_size + j ] = -1;
660 if( ( j + 1 ) < board_y_size )
662 if( rs->occupied[ i * board_y_size + (j + 1) ] == -1 )
664 rs->direction[ num ] = dir;
665 rs->occupied[ i * board_y_size + (j + 1) ] = num;
666 rs->occupied[ i * board_y_size + j ] = -1;
676 if( rs->occupied[ (i - 1) * board_y_size + j ] == -1 )
678 rs->direction[ num ] = dir;
679 rs->occupied[ (i - 1) * board_y_size + j ] = num;
680 rs->occupied[ i * board_y_size + j ] = -1;
690 if( rs->occupied[ i * board_y_size + (j - 1) ] == -1 )
692 rs->direction[ num ] = dir;
693 rs->occupied[ i * board_y_size + (j - 1) ] = num;
694 rs->occupied[ i * board_y_size + j ] = -1;
707 /* move a single frame. */
708 /* Pass in the angle in rads the square rotates in a frame. */
710 randsheet_move( randsheet *rs, float rot )
714 for( index = 0 ; index < numsquares; index++ )
716 switch( rs->direction[ index ] )
723 if( textured && rs->angle[ index ] == 0 )
725 tmp = rs->tex[ index * 4 + 0 ];
726 rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
727 rs->tex[ index * 4 + 2 ] = tmp;
729 rs->angle[ index ] += rot;
730 /* check to see if we have finished moving */
731 if( rs->angle[ index ] >= M_PI )
733 rs->xpos[ index ] += 1;
734 rs->direction[ index ] = 0;
735 rs->angle[ index ] = 0;
740 if( textured && rs->angle[ index ] == 0 )
742 tmp = rs->tex[ index * 4 + 1 ];
743 rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
744 rs->tex[ index * 4 + 3 ] = tmp;
746 rs->angle[ index ] += rot;
747 /* check to see if we have finished moving */
748 if( rs->angle[ index ] >= M_PI )
750 rs->ypos[ index ] += 1;
751 rs->direction[ index ] = 0;
752 rs->angle[ index ] = 0;
757 rs->angle[ index ] += rot;
758 /* check to see if we have finished moving */
759 if( rs->angle[ index ] >= M_PI )
761 rs->xpos[ index ] -= 1;
762 rs->direction[ index ] = 0;
763 rs->angle[ index ] = 0;
766 tmp = rs->tex[ index * 4 + 0 ];
767 rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
768 rs->tex[ index * 4 + 2 ] = tmp;
774 rs->angle[ index ] += rot;
775 /* check to see if we have finished moving */
776 if( rs->angle[ index ] >= M_PI )
778 rs->ypos[ index ] -= 1;
779 rs->direction[ index ] = 0;
780 rs->angle[ index ] = 0;
783 tmp = rs->tex[ index * 4 + 1 ];
784 rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
785 rs->tex[ index * 4 + 3 ] = tmp;
796 /* draw all the moving squares */
798 randsheet_draw( randsheet *rs )
803 /* for all moving squares ... */
804 for( index = 0; index < numsquares; index++ )
807 glColor3f( rs->color[ index*3 + 0 ],
808 rs->color[ index*3 + 1 ],
809 rs->color[ index*3 + 2 ] );
810 /* find x and y position */
811 i = rs->xpos[ index ];
812 j = rs->ypos[ index ];
814 switch( rs->direction[ index ] )
820 glTranslatef( i, 0, j );
823 glTranslatef( i+1, 0, j );
824 glRotatef( 180 - rs->angle[ index ]*180/M_PI, 0, 0, 1 );
828 glTranslatef( i, 0, j+1 );
829 glRotatef( 180 - rs->angle[ index ]*180/M_PI, -1, 0, 0 );
833 glTranslatef( i, 0, j );
834 glRotatef( rs->angle[ index ]*180/M_PI, 0, 0, 1 );
837 glTranslatef( i, 0, j );
838 glRotatef( rs->angle[ index ]*180/M_PI, -1, 0, 0 );
843 polys += draw_sheet( rs->tex + index*4 );
850 /**** END RANDSHEET_BAK FUNCTIONS ***/
852 XSCREENSAVER_MODULE ("FlipFlop", flipflop)