2 * Permission to use, copy, modify, and distribute this software and its
3 * documentation for any purpose and without fee is hereby granted,
4 * provided that the above copyright notice appear in all copies and that
5 * both that copyright notice and this permission notice appear in
6 * supporting documentation.
8 * This file is provided AS IS with no warranties of any kind. The author
9 * shall have no liability with respect to the infringement of copyrights,
10 * trade secrets or any patents by this file or any part thereof. In no
11 * event will the author be liable for any lost revenue or profits or
12 * other special, indirect and consequential damages.
14 * Copyright 2004 Blair Tennessy
18 #if !defined( lint ) && !defined( SABER )
19 static const char sccsid[] = "@(#)antmaze.c 5.01 2001/03/01 xlockmore";
24 # define DEFAULTS "*delay: 20000 \n" \
27 # define refresh_antmaze 0
28 # include "xlockmore.h" /* from the xscreensaver distribution */
29 #else /* !STANDALONE */
30 # include "xlock.h" /* from the xlockmore distribution */
32 #endif /* !STANDALONE */
38 #include "gltrackball.h"
40 #define DEF_SOLIDANTMAZE "False"
41 #define DEF_NOANTS "False"
43 static int solidantmaze;
46 static XrmOptionDescRec opts[] =
48 {"-solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "on"},
49 {"+solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "off"},
50 {"-noants", ".antmaze.noants", XrmoptionNoArg, "on"},
51 {"+noants", ".antmaze.noants", XrmoptionNoArg, "off"}
53 static argtype vars[] =
55 {&solidantmaze, "solidantmaze", "Solidantmaze", DEF_SOLIDANTMAZE, t_Bool},
56 {&noants, "noants", "Noants", DEF_NOANTS, t_Bool}
59 static OptionStruct desc[] =
61 {"-/+solidantmaze", "select between a SOLID or a NET Antmaze Strip"},
62 {"-/+noants", "turn on/off walking ants"}
65 ENTRYPOINT ModeSpecOpt antmaze_opts =
66 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
69 ModStruct antmaze_description =
70 {"antmaze", "init_antmaze", "draw_antmaze", "release_antmaze",
71 "draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
72 1000, 1, 1, 1, 4, 1.0, "",
73 "draws some ants", 0, NULL};
77 #define Scale4Window 0.3
78 #define Scale4Iconic 0.4
80 #define sqr(A) ((A)*(A))
86 #define ObjAntmazeStrip 0
90 /*************************************************************************/
102 #define checkImageWidth 64
103 #define checkImageHeight 64
108 GLfloat ant_position;
109 GLXContext *glx_context;
111 trackball_state *trackball;
117 double antdirection[ANTCOUNT];
118 double antposition[ANTCOUNT][3];
121 double antvelocity[ANTCOUNT];
122 double antsize[ANTCOUNT];
123 int bposition[ANTCOUNT][2];
124 int board[BOARDCOUNT][10][10];
127 double antpath[ANTCOUNT][PARTS][2];
128 int antpathlength[ANTCOUNT];
130 GLubyte checkers[checkImageWidth][checkImageHeight][3];
132 GLuint checktexture, brushedtexture;
136 double first_ant_step;
148 static antmazestruct *antmaze = (antmazestruct *) NULL;
151 static const GLfloat MaterialRed[] = {0.6, 0.0, 0.0, 1.0};
152 /*static const GLfloat MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};*/
153 static const GLfloat MaterialGray8[] = {0.8, 0.8, 0.8, 1.0};
154 static const GLfloat MaterialGray35[] = {0.30, 0.30, 0.30, 1.0};
155 static const GLfloat MaterialGray4[] = {0.40, 0.40, 0.40, 1.0};
156 static const GLfloat MaterialOrange[] = {1.0, 0.69, 0.00, 1.0};
157 static const GLfloat MaterialGreen[] = {0.1, 0.4, 0.2, 1.0};
159 /* lighting variables */
160 static const GLfloat front_shininess[] = {60.0};
161 static const GLfloat front_specular[] = {0.8, 0.8, 0.8, 1.0};
162 static const GLfloat ambient[] = {0.1, 0.1, 0.1, 1.0};
163 /*static const GLfloat ambient2[] = {0.0, 0.0, 0.0, 0.0};*/
164 static const GLfloat diffuse[] = {0.8, 0.8, 0.8, 1.0};
165 static const GLfloat position0[] = {1.0, 5.0, 1.0, 1.0};
166 static const GLfloat position1[] = {-1.0, -5.0, 1.0, 1.0};
167 /*static const GLfloat lmodel_ambient[] = {0.8, 0.8, 0.8, 1.0};*/
168 /*static const GLfloat lmodel_twoside[] = {GL_TRUE};*/
169 /*static const GLfloat spotlight_ambient[] = { 0.0, 0.0, 0.0, 1.0 };*/
170 /*static const GLfloat spotlight_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };*/
175 static Bool mySphere(float radius)
177 GLUquadricObj *quadObj;
179 if((quadObj = gluNewQuadric()) == 0)
181 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
182 gluSphere(quadObj, radius, 16, 16);
183 gluDeleteQuadric(quadObj);
189 /* silhouette sphere */
190 static Bool mySphere2(float radius)
192 GLUquadricObj *quadObj;
194 if((quadObj = gluNewQuadric()) == 0)
196 gluQuadricDrawStyle(quadObj, (GLenum) GLU_SILHOUETTE);
197 gluSphere(quadObj, radius, 16, 8);
198 gluDeleteQuadric(quadObj);
204 /* textured sphere */
205 static Bool mySphereTex(float radius)
207 GLUquadricObj *quadObj;
209 if((quadObj = gluNewQuadric()) == 0)
211 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
212 gluQuadricTexture(quadObj, GL_TRUE);
213 gluQuadricNormals(quadObj, GLU_SMOOTH);
214 gluSphere(quadObj, radius, 32, 16);
215 gluDeleteQuadric(quadObj);
221 static Bool myCone(float radius)
223 GLUquadricObj *quadObj;
225 if ((quadObj = gluNewQuadric()) == 0)
227 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
228 gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
229 gluDeleteQuadric(quadObj);
234 static Bool myCone2(float radius) { return True; }
237 static const float *antmaterial[ANTCOUNT] =
238 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange, MaterialGreen};
240 static const float *materials[MATERIALS] =
241 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange};
244 static void makeCheckImage(antmazestruct *mp)
248 for (i = 0; i < checkImageWidth; i++) {
249 for (j = 0; j < checkImageHeight; j++) {
250 if(((((i&0x8)==0)^((j&0x8)))==0)) {
251 int c = 102 + random()%32;
252 mp->checkers[i][j][0] = c;
253 mp->checkers[i][j][1] = c;
254 mp->checkers[i][j][2] = c;
257 int c = 153 + random()%32;
258 mp->checkers[i][j][0] = c;/*153;*/
259 mp->checkers[i][j][1] = c;/*c;*//*0;*/
260 mp->checkers[i][j][2] = c;/*c;*//*0;*/
265 glGenTextures(1, &mp->checktexture);
266 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
268 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
269 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
270 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
271 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
272 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
273 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
274 &mp->checkers[0][0]);
275 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
278 static void makeBrushedImage(antmazestruct *mp)
282 for(i = 0; i < checkImageWidth; ++i)
283 for(j = 0; j < checkImageHeight; ++j) {
285 c = 102+102*fabs(sin(2.0*i / Pi)*sin(2.0*j/Pi)) + random()%51;
287 /* c = (i+j)%8==0 || (i+j+5)%8==0 ? 153 : 102; */
289 mp->checkers[i][j][0] = c;
290 mp->checkers[i][j][1] = c;
291 mp->checkers[i][j][2] = c;
294 /* for (i = 0; i < checkImageWidth; i++) { */
295 /* for (j = 0; j < checkImageHeight; j++) { */
296 /* int c = 102 + pow((random()%1000)/1000.0, 4)*103; */
297 /* checkers[i][j][0] = c; */
298 /* checkers[i][j][1] = c; */
299 /* checkers[i][j][2] = c; */
304 /* for (i = 0; i < checkImageWidth; i++) { */
305 /* for (j = 0; j < checkImageHeight; j++) { */
306 /* int a = checkers[(i+checkImageWidth+1)%checkImageWidth][j][0] + */
307 /* 4*checkers[i][j][0] + checkers[(i+1)%checkImageWidth][j][0]; */
309 /* checkers[i][j][0] = a; */
310 /* checkers[i][j][1] = a; */
311 /* checkers[i][j][2] = a; */
315 glGenTextures(1, &mp->brushedtexture);
316 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
318 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
319 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
320 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
321 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
322 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
323 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
324 &mp->checkers[0][0]);
325 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
329 static void draw_wall(ModeInfo *mi, double x1, double z1, double x2, double z2)
331 float x = fabs(x2 - x1)/2.0;
336 glNormal3f(0.0, 1.0, 0.0);
337 glTexCoord2f(0.0, 0.0);
338 glVertex3f(x1, 1.0, z1+0.25);
339 glTexCoord2f(x, 0.0);
340 glVertex3f(x2, 1.0, z2+0.25);
341 glTexCoord2f(x, 0.25);
342 glVertex3f(x2, 1.0, z2-0.25);
343 glTexCoord2f(0.0, 0.25);
344 glVertex3f(x1, 1.0, z1-0.25);
348 glNormal3f(0.0, 0.0, 1.0);
349 glTexCoord2f(0.0, 0.0);
350 glVertex3f(x1, 0.0, z1+0.25);
351 glTexCoord2f(x, 0.0);
352 glVertex3f(x2, 0.0, z2+0.25);
353 glTexCoord2f(x, 0.5);
354 glVertex3f(x2, 1.0, z2+0.25);
355 glTexCoord2f(0.0, 0.5);
356 glVertex3f(x1, 1.0, z1+0.25);
359 glNormal3f(0.0, 0.0, -1.0);
360 glTexCoord2f(0.0, 0.0);
361 glVertex3f(x1, 0.0, z1-0.25);
362 glTexCoord2f(x, 0.0);
363 glVertex3f(x2, 0.0, z2-0.25);
364 glTexCoord2f(x, 0.5);
365 glVertex3f(x2, 1.0, z2-0.25);
366 glTexCoord2f(0.0, 0.5);
367 glVertex3f(x1, 1.0, z1-0.25);
371 glNormal3f(1.0, 0.0, 0.0);
372 glTexCoord2f(0.0, 0.0);
373 glVertex3f(x2, 0.0, z2+0.25);
374 glTexCoord2f(0.25, 0.0);
375 glVertex3f(x2, 0.0, z2-0.25);
376 glTexCoord2f(0.25, 0.5);
377 glVertex3f(x2, 1.0, z2-0.25);
378 glTexCoord2f(0.0, 0.5);
379 glVertex3f(x2, 1.0, z2+0.25);
382 glNormal3f(-1.0, 0.0, 0.0);
383 glTexCoord2f(0.0, 0.0);
384 glVertex3f(x1, 0.0, z1-0.25);
385 glTexCoord2f(0.25, 0.0);
386 glVertex3f(x1, 0.0, z1+0.25);
387 glTexCoord2f(0.25, 0.5);
388 glVertex3f(x1, 1.0, z1+0.25);
389 glTexCoord2f(0.0, 0.5);
390 glVertex3f(x1, 1.0, z1-0.25);
397 static void draw_board(ModeInfo *mi, antmazestruct *mp)
404 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
408 for(i = 0; i < BOARDSIZE; ++i)
409 for(j = 0; j < BOARDSIZE; ++j) {
410 if(mp->board[mp->currentboard][j][i]) {
412 /* /\* draw top *\/ */
413 /* glNormal3f(0.0, 1.0, 0.0); */
414 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
415 /* glVertex3f(i-0.5, h, j+0.5); */
416 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
417 /* glVertex3f(i+0.5, h, j+0.5); */
418 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
419 /* glVertex3f(i+0.5, h, j-0.5); */
420 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
421 /* glVertex3f(i-0.5, h, j-0.5); */
424 glNormal3f(0.0, 1.0, 0.0);
425 glTexCoord2f(0.0 + stf, 0.0 + stf);
426 glVertex3f(i-0.5, h, j+0.5);
427 glTexCoord2f(1.0 + stf, 0.0 + stf);
428 glVertex3f(i+0.5, h, j+0.5);
429 glTexCoord2f(1.0 + stf, 1.0 + stf);
430 glVertex3f(i+0.5, h, j-0.5);
431 glTexCoord2f(0.0 + stf, 1.0 + stf);
432 glVertex3f(i-0.5, h, j-0.5);
435 /* draw south face */
436 if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
437 glNormal3f(0.0, 0.0, 1.0);
438 glTexCoord2f(0.0 + stf, 0.0 + stf);
439 glVertex3f(i-0.5, 0.0, j+0.5);
440 glTexCoord2f(1.0 + stf, 0.0 + stf);
441 glVertex3f(i+0.5, 0.0, j+0.5);
442 glTexCoord2f(1.0 + stf, h + stf);
443 glVertex3f(i+0.5, h, j+0.5);
444 glTexCoord2f(0.0 + stf, h + stf);
445 glVertex3f(i-0.5, h, j+0.5);
449 /* draw north face */
450 if(j == 0 || !mp->board[mp->currentboard][j-1][i]) {
451 glNormal3f(0.0, 0.0, -1.0);
452 glTexCoord2f(0.0 + stf, 0.0 + stf);
453 glVertex3f(i+0.5, 0.0, j-0.5);
454 glTexCoord2f(1.0 + stf, 0.0 + stf);
455 glVertex3f(i-0.5, 0.0, j-0.5);
456 glTexCoord2f(1.0 + stf, h + stf);
457 glVertex3f(i-0.5, h, j-0.5);
458 glTexCoord2f(0.0 + stf, h + stf);
459 glVertex3f(i+0.5, h, j-0.5);
464 if(i == 9 || !mp->board[mp->currentboard][j][i+1]) {
465 glNormal3f(1.0, 0.0, 0.0);
466 glTexCoord2f(0.0 + stf, 0.0 + stf);
467 glVertex3f(i+0.5, 0.0, j+0.5);
468 glTexCoord2f(1.0 + stf, 0.0 + stf);
469 glVertex3f(i+0.5, 0.0, j-0.5);
470 glTexCoord2f(1.0 + stf, h + stf);
471 glVertex3f(i+0.5, h, j-0.5);
472 glTexCoord2f(0.0 + stf, h + stf);
473 glVertex3f(i+0.5, h, j+0.5);
478 if(i == 0 || !mp->board[mp->currentboard][j][i-1]) {
479 glNormal3f(-1.0, 0.0, 0.0);
480 glTexCoord2f(0.0 + stf, 0.0 + stf);
481 glVertex3f(i-0.5, 0.0, j-0.5);
482 glTexCoord2f(1.0 + stf, 0.0 + stf);
483 glVertex3f(i-0.5, 0.0, j+0.5);
484 glTexCoord2f(1.0 + stf, h + stf);
485 glVertex3f(i-0.5, h, j+0.5);
486 glTexCoord2f(0.0 + stf, h + stf);
487 glVertex3f(i-0.5, h, j-0.5);
493 glNormal3f(0.0, 1.0, 0.0);
494 glTexCoord2f(0.0, 0.0);
495 glVertex3f(i-0.5, 0.0, j+0.5);
496 glTexCoord2f(tx, 0.0);
497 glVertex3f(i+0.5, 0.0, j+0.5);
498 glTexCoord2f(tx, tx);
499 glVertex3f(i+0.5, 0.0, j-0.5);
500 glTexCoord2f(0.0, tx);
501 glVertex3f(i-0.5, 0.0, j-0.5);
507 /* /\* draw elevator *\/ */
508 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
510 /* glBegin(GL_QUADS); */
512 /* glNormal3f(0.0, 1.0, 0.0); */
514 /* if(pastfirst) { */
516 /* glTexCoord2f(0.0, 0.0); */
517 /* glVertex3f(0.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
518 /* glTexCoord2f(1.0, 0.0); */
519 /* glVertex3f(1.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
520 /* glTexCoord2f(1.0, 1.5); */
521 /* glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
522 /* glTexCoord2f(0.0, 1.5); */
523 /* glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
524 /* mi->polygon_count++; */
527 /* /\* destination *\/ */
528 /* glTexCoord2f(0.0, 0.0); */
529 /* glVertex3f(BOARDSIZE - 2.5, elevator, -2.0 - 0.2); */
530 /* glTexCoord2f(1.0, 0.0); */
531 /* glVertex3f(BOARDSIZE - 1.5, elevator, -2.0 - 0.2); */
532 /* glTexCoord2f(1.0, 1.5); */
533 /* glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
534 /* glTexCoord2f(0.0, 1.5); */
535 /* glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
536 /* mi->polygon_count++; */
540 /* for(i = 0; i < BOARDSIZE; ++i) */
541 /* for(j = 0; j < BOARDSIZE; ++j) { */
542 /* if(board[j][i]) { */
544 /* /\* draw brushed boxtop *\/ */
545 /* glNormal3f(0.0, 1.0, 0.0); */
546 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
547 /* glVertex3f(i-0.5 + stf, h+0.001, j+0.5 - stf); */
548 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
549 /* glVertex3f(i+0.5 - stf, h+0.001, j+0.5 - stf); */
550 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
551 /* glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
552 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
553 /* glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
554 /* mi->polygon_count++; */
561 static void build_board(antmazestruct *mp, int b)
565 for(i = 0; i < BOARDSIZE; ++i)
566 for(j = 0; j < BOARDSIZE; ++j)
567 mp->board[b][i][j] = 1;
569 /* for(i = 0; i < BOARDSIZE; ++i) { */
570 /* board[0][i] = 1; */
571 /* board[i][0] = 1; */
572 /* board[BOARDSIZE-1][BOARDSIZE-i] = 1; */
573 /* board[BOARDSIZE-i][BOARDSIZE-1] = 1; */
576 /* board[0][BOARDSIZE-2] = 0; */
577 /* board[BOARDSIZE-1][1] = 0; */
580 mp->board[b][BOARDSIZE-1][1] = 0;
581 mp->board[b][0][BOARDSIZE-2] = 0;
583 /* build the ant paths */
584 if(mp->currentboard == b) {
585 for(i = 0; i < ANTCOUNT; ++i) {
586 int sx = BOARDSIZE-2;
590 mp->board[b][sx][sy] = 0;
591 mp->antpath[i][j][0] = sy - 5.0;
592 mp->antpath[i][j][1] = sx - 5.0;
597 else if(sy < BOARDSIZE-2)
613 mp->antpath[i][j][0] = BOARDSIZE-7.0;
614 mp->antpath[i][j][1] = -7.0;
615 mp->antpathlength[i] = j;
619 /* for(i = 0; i < 20; ++i) { */
620 /* int x = 1 + random()%(BOARDSIZE-2); */
621 /* int y = 1 + random()%(BOARDSIZE-2); */
622 /* board[x][y] = 1; */
626 /* compute nearness */
627 static int near(double a[2], double b[2])
629 return fabs(a[0] - b[0]) < 0.5 && fabs(a[1] - b[1]) < 0.5;
632 static double sign(double d)
634 return d < 0.0 ? -1.0 : 1.0;
637 static double min(double a, double b)
639 return a < b ? a : b;
642 /* draw method for ant */
643 static Bool draw_ant(ModeInfo *mi, antmazestruct *mp,
644 const float *Material, int mono, int shadow,
645 float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
648 float cos1 = cos(mp->ant_step);
649 float cos2 = cos(mp->ant_step + 2 * Pi / 3);
650 float cos3 = cos(mp->ant_step + 4 * Pi / 3);
651 float sin1 = sin(mp->ant_step);
652 float sin2 = sin(mp->ant_step + 2 * Pi / 3);
653 float sin3 = sin(mp->ant_step + 4 * Pi / 3);
655 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : Material);
657 /* glEnable(GL_CULL_FACE); */
661 if(!((*sphere)(0.18)))
663 glScalef(1, 1 / 1.3, 1);
664 glTranslatef(0.00, 0.30, 0.00);
665 if(!((*sphere)(0.2)))
668 glTranslatef(-0.05, 0.17, 0.05);
669 glRotatef(-90, 1, 0, 0);
670 glRotatef(-25, 0, 1, 0);
673 glTranslatef(0.00, 0.10, 0.00);
676 glRotatef(25, 0, 1, 0);
677 glRotatef(90, 1, 0, 0);
680 glTranslatef(0.15, -0.65, 0.05);
681 if(!((*sphere)(0.25)))
683 glScalef(1, 1 / 1.3, 1);
686 /* glDisable(GL_CULL_FACE); */
688 glDisable(GL_LIGHTING);
692 glColor3fv(mono ? MaterialGray5 : Material);
693 glVertex3f(0.00, 0.30, 0.00);
694 glColor3fv(MaterialGray);
695 glVertex3f(0.40, 0.70, 0.40);
697 glColor3fv(mono ? MaterialGray5 : Material);
698 glVertex3f(0.00, 0.30, 0.00);
699 glColor3fv(MaterialGray);
700 glVertex3f(0.40, 0.70, -0.40);
706 glColor3fv(mono ? MaterialGray6 : MaterialRed);
707 glVertex3f(0.40, 0.70, 0.40);
709 glVertex3f(0.40, 0.70, -0.40);
715 glBegin(GL_LINE_STRIP);
716 glColor3fv(mono ? MaterialGray5 : Material);
717 glVertex3f(0.00, 0.05, 0.18);
718 glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
720 glColor3fv(MaterialGray);
721 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
725 /* LEFT-CENTER ARM */
726 glBegin(GL_LINE_STRIP);
727 glColor3fv(mono ? MaterialGray5 : Material);
728 glVertex3f(0.00, 0.00, 0.18);
729 glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
731 glColor3fv(MaterialGray);
732 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
737 glBegin(GL_LINE_STRIP);
738 glColor3fv(mono ? MaterialGray5 : Material);
739 glVertex3f(0.00, -0.05, 0.18);
740 glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
742 glColor3fv(MaterialGray);
743 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
747 /* RIGHT-FRONT ARM */
748 glBegin(GL_LINE_STRIP);
749 glColor3fv(mono ? MaterialGray5 : Material);
750 glVertex3f(0.00, 0.05, -0.18);
751 glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
753 glColor3fv(MaterialGray);
754 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
758 /* RIGHT-CENTER ARM */
759 glBegin(GL_LINE_STRIP);
760 glColor3fv(mono ? MaterialGray5 : Material);
761 glVertex3f(0.00, 0.00, -0.18);
762 glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
764 glColor3fv(MaterialGray);
765 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
770 glBegin(GL_LINE_STRIP);
771 glColor3fv(mono ? MaterialGray5 : Material);
772 glVertex3f(0.00, -0.05, -0.18);
773 glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
775 glColor3fv(MaterialGray);
776 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
782 glColor3fv(mono ? MaterialGray8 : MaterialGray35);
783 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
784 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
785 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
786 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
787 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
788 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
789 mi->polygon_count += 6;
793 glEnable(GL_LIGHTING);
798 static Bool draw_antmaze_strip(ModeInfo * mi)
800 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
802 int mono = MI_IS_MONO(mi);
804 /* glMatrixMode(GL_MODELVIEW); */
805 /* glLoadIdentity(); */
806 /* glPushMatrix(); */
808 glEnable(GL_LIGHTING);
809 /* glDisable(GL_BLEND); */
814 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
815 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
816 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
817 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
820 if(mp->elevator < 1.0) {
821 glEnable(GL_TEXTURE_2D);
822 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
823 glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
825 glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
826 glDisable(GL_TEXTURE_2D);
831 glTranslatef(0.0, -0.1, 0.0);
833 for(i = 0; i < ANTCOUNT; ++i) {
835 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
836 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
838 if(!mp->anton[i]) { continue; }
840 /* determine location, move to goal */
842 glTranslatef(0.0, 0.01, 0.0);
843 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
844 /* glScalef(1.0, 0.01, 1.0); */
845 glScalef(0.6, 0.01, 0.6);
846 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
847 glRotatef(90.0, 0.0, 0.0, 1.0);
848 glDisable(GL_LIGHTING);
850 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
851 glColor4fv(MaterialGrayB);
853 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
855 /* slow down first ant */
856 if(i == 0 && mp->part[i] == mp->antpathlength[i])
857 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
859 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
864 glEnable(GL_LIGHTING);
867 /* glTranslatef(0.0, 0.18, 0.0); */
868 glTranslatef(0.0, 0.12, 0.0);
869 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
870 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
871 glRotatef(90.0, 0.0, 0.0, 1.0);
872 glScalef(0.6, 0.6, 0.6);
874 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
876 /* glEnable(GL_TEXTURE_2D); */
877 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
879 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed); */
881 /* slow down first ant */
882 if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
883 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
884 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
885 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
888 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
889 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
891 glEnable(GL_TEXTURE_2D);
892 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
893 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
894 glDisable(GL_TEXTURE_2D);
898 /* draw_ant(mi, antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
899 /* glDisable(GL_TEXTURE_2D); */
905 /* /\* now draw overlay *\/ */
906 /* glDisable(GL_LIGHTING); */
907 /* glDisable(GL_BLEND); */
909 /* /\* go to ortho mode *\/ */
910 /* glMatrixMode(GL_PROJECTION); */
911 /* glPushMatrix(); */
912 /* glLoadIdentity(); */
913 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
915 /* /\* translate to corner *\/ */
916 /* glTranslatef(4.0-1.2, 3.0-1.2, 0.0); */
918 /* glDisable(GL_LIGHTING); */
919 /* glEnable(GL_BLEND); */
921 /* /\* draw the 2d board *\/ */
922 /* glBegin(GL_QUADS); */
925 /* double sz = 1.0; */
926 /* for(i = 0; i < BOARDSIZE; ++i) */
927 /* for(j = 0; j < BOARDSIZE; ++j) { */
928 /* int par = board[i][j]; */
929 /* glColor4f(par ? 0.4 : 0.6, */
930 /* par ? 0.4 : 0.6, */
931 /* par ? 0.4 : 0.6, */
933 /* glNormal3f(0.0, 0.0, 1.0); */
934 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
935 /* glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
936 /* glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
937 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
938 /* mi->polygon_count++; */
946 /* but the step size is the same! */
947 mp->ant_step += 0.18;
948 /* if(ant_step > 2*Pi) { */
949 /* ant_step = 0.0; */
952 if(mp->ant_step > 5*Pi)
955 mp->ant_position += 1;
958 #undef AntmazeDivisions
959 #undef AntmazeTransversals
961 ENTRYPOINT void reshape_antmaze(ModeInfo * mi, int width, int height)
963 double h = (GLfloat) height / (GLfloat) width;
964 int size = (width / 512) + 1;
965 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
967 glViewport(0, 0, mp->WindW = (GLint) width, mp->WindH = (GLint) height);
968 glMatrixMode(GL_PROJECTION);
971 gluPerspective(45, 1/h, 1, 25.0);
973 glMatrixMode(GL_MODELVIEW);
974 /* glLineWidth(3.0); */
979 static void update_ants(antmazestruct *mp)
983 df[0] = df[1] = df[2] = 0.8*mp->fadeout;
987 if(mp->fadeoutspeed < -0.00001) {
989 if(mp->fadeout <= 0.0) {
990 /* switch boards: rebuild old board, increment current */
991 mp->currentboard = (mp->currentboard+1)%BOARDCOUNT;
992 build_board(mp, mp->currentboard);
993 mp->fadeoutspeed = 0.02;
996 mp->fadeout += mp->fadeoutspeed;
998 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
999 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1003 if(mp->fadeoutspeed > 0.0001) {
1004 mp->fadeout += mp->fadeoutspeed;
1005 if(mp->fadeout >= 1.0) {
1007 mp->fadeoutspeed = 0.0;
1008 mp->entroducing = 12;
1010 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
1011 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1014 for(i = 0; i < ANTCOUNT; ++i) {
1016 if(!mp->anton[i] && mp->elevator < 1.0) {
1019 if(mp->entroducing > 0 && mp->introduced <= 0 && random()%100 == 0) {
1022 mp->antsize[i] = 0.0;
1023 mp->antposition[i][0] = -4.0;
1024 mp->antposition[i][1] = 5.0;
1025 mp->antdirection[i] = PI/2.0;
1026 mp->bposition[i][0] = 0;
1027 mp->bposition[i][1] = 8;
1028 mp->introduced = 300;
1035 if(mp->part[i] == 0 && mp->antsize[i] < 1.0) {
1036 mp->antsize[i] += 0.02;
1040 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] > 0.0) {
1041 mp->antsize[i] -= 0.02;
1042 if(mp->antvelocity[i] > 0.0) {
1043 mp->antvelocity[i] -= 0.02;
1045 else { mp->antvelocity[i] = 0.0; }
1050 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] <= 0.0) {
1051 mp->antvelocity[i] = 0.02;
1054 antmaterial[i] = materials[random()%MATERIALS];
1057 mp->antdirection[i] = PI/2.0;
1058 mp->bposition[i][0] = 0;
1059 mp->bposition[i][1] = 8;
1062 mp->antsize[i] = 0.0;
1066 mp->antposition[i][0] = -4.0;
1067 mp->antposition[i][1] = 5.0;
1069 /* /\* reset camera *\/ */
1070 /* if(i == focus) { */
1072 /* ant_step = 0.0; */
1075 /* check for the end */
1076 if(mp->entroducing <= 0) {
1078 for(z = 0; z < ANTCOUNT; ++z) {
1079 if(mp->anton[z]) { ao = 1; break; }
1083 mp->fadeoutspeed = -0.02;
1089 /* near goal, bend path towards next step */
1090 if(near(mp->antposition[i], mp->antpath[i][mp->part[i]])) {
1094 /* /\* special first ant *\/ */
1095 /* if(i == 0 && part[i] > antpathlength[i]) { */
1097 /* first_ant_step = ant_step; */
1099 /* antvelocity[i] = 0.0; */
1100 /* /\* antposition[i][2] += 0.025; *\/ */
1101 /* elevator += 0.025; */
1103 /* /\* set light *\/ */
1104 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
1105 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
1106 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
1107 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
1109 /* /\* draw next board *\/ */
1110 /* if(elevator > 1.0) { */
1112 /* if(makenew == 1) { */
1115 /* /\* switch boards: rebuild old board, increment current *\/ */
1116 /* currentboard = (currentboard+1)%BOARDCOUNT; */
1117 /* build_board(currentboard); */
1119 /* for(re = 1; re < ANTCOUNT; ++re) { */
1120 /* anton[re] = 0; */
1121 /* antmaterial[re] = materials[random()%MATERIALS]; */
1128 /* /\* draw the other board *\/ */
1129 /* glEnable(GL_TEXTURE_2D); */
1130 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6); */
1132 /* glPushMatrix(); */
1133 /* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */
1134 /* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
1135 /* draw_board(mi, mp); */
1136 /* glPopMatrix(); */
1137 /* glDisable(GL_TEXTURE_2D); */
1140 /* if(elevator > 2.0) { */
1141 /* antposition[i][0] = -4.0;/\*-= -(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0);*\//\*= -4.0;*\/ */
1142 /* antposition[i][1] = 5.5;/\*-(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0);*\/ */
1143 /* /\* antposition[i][2] = 0.15; *\/ */
1144 /* antdirection[i] = PI/2.0; */
1145 /* bposition[i][0] = 0; */
1146 /* bposition[i][1] = 8; */
1148 /* antvelocity[i] = 0.02; */
1150 /* antmaterial[i] = MaterialRed; */
1154 /* elevator = 0.0; */
1155 /* introduced = 200; */
1164 /* move toward goal, correct ant direction if required */
1168 double dx = mp->antpath[i][mp->part[i]][0] - mp->antposition[i][0];
1169 double dz = - mp->antpath[i][mp->part[i]][1] + mp->antposition[i][1];
1170 double theta, ideal;
1173 theta = atan(dz/dx);
1175 theta = dx > EPSILON ? 0.0 : PI;
1177 ideal = theta - mp->antdirection[i];
1181 /* compute correction */
1183 double dt = sign(ideal) * min(fabs(ideal), PI/90.0);
1184 mp->antdirection[i] += dt;
1185 if(mp->antdirection[i] > 2.0*PI)
1186 mp->antdirection[i] = 0.0;
1190 mp->antposition[i][0] += mp->antvelocity[i] * cos(mp->antdirection[i]);
1191 mp->antposition[i][1] += mp->antvelocity[i] * sin(-mp->antdirection[i]);
1195 static void pinit(antmazestruct *mp)
1198 glClearColor(0.0, 0.0, 0.0, 1.0);
1200 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
1201 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1202 glLightfv(GL_LIGHT0, GL_POSITION, position0);
1203 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
1204 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1205 glLightfv(GL_LIGHT1, GL_POSITION, position1);
1207 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
1208 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001);
1209 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
1211 glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05);
1212 glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001);
1213 glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
1216 /* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
1217 /* glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */
1218 glEnable(GL_LIGHTING);
1219 glEnable(GL_LIGHT0);
1220 glEnable(GL_LIGHT1);
1221 glEnable(GL_NORMALIZE);
1222 glFrontFace(GL_CCW);
1223 glCullFace(GL_BACK);
1226 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
1227 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
1229 glShadeModel(GL_SMOOTH);
1230 glEnable(GL_DEPTH_TEST);
1231 glDisable(GL_TEXTURE_2D);
1233 /* setup textures */
1235 makeBrushedImage(mp);
1240 /* makeCheckImage(); */
1241 /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */
1242 /* glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, */
1243 /* checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */
1244 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */
1245 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */
1247 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
1248 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
1249 /* glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */
1250 glEnable(GL_TEXTURE_2D);
1252 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */
1253 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
1256 ENTRYPOINT void release_antmaze(ModeInfo * mi)
1259 free((void *) antmaze);
1260 antmaze = (antmazestruct *) NULL;
1265 #define MAX_MAGNIFICATION 10
1266 #define max(a, b) a < b ? b : a
1267 #define min(a, b) a < b ? a : b
1269 ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
1271 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1273 switch(event->xany.type) {
1276 switch(event->xbutton.button) {
1279 mp->button_down_p = True;
1280 gltrackball_start(mp->trackball,
1281 event->xbutton.x, event->xbutton.y,
1282 MI_WIDTH (mi), MI_HEIGHT (mi));
1286 mp->focus = (mp->focus + 1) % ANTCOUNT;
1290 mp->mag = max(mp->mag-1, 1);
1294 mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
1302 switch(event->xbutton.button) {
1304 mp->button_down_p = False;
1311 if(mp->button_down_p)
1312 gltrackball_track(mp->trackball,
1313 event->xmotion.x, event->xmotion.y,
1314 MI_WIDTH (mi), MI_HEIGHT (mi));
1324 ENTRYPOINT void init_antmaze(ModeInfo * mi)
1326 double rot_speed = 0.3;
1331 if (antmaze == NULL) {
1332 if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
1333 sizeof (antmazestruct))) == NULL)
1336 mp = &antmaze[MI_SCREEN(mi)];
1337 mp->step = NRAND(90);
1338 mp->ant_position = NRAND(90);
1341 mp->antdirection[0] = PI/2.0;
1342 mp->antdirection[1] = PI/2.0;
1343 mp->antdirection[2] = 0;
1344 mp->antdirection[3] = PI/2.0;
1345 mp->antdirection[4] = PI/2.0;
1347 mp->antposition[0][0] = -4.0;
1348 mp->antposition[0][1] = 5.0;
1349 mp->antposition[0][1] = 0.15;
1351 mp->antposition[1][0] = -4.0;
1352 mp->antposition[1][1] = 3.0;
1353 mp->antposition[1][1] = 0.15;
1355 mp->antposition[2][0] = -1.0;
1356 mp->antposition[2][1] = -2.0;
1357 mp->antposition[2][1] = 0.15;
1359 mp->antposition[3][0] = -3.9;
1360 mp->antposition[3][1] = 6.0;
1361 mp->antposition[3][1] = 0.15;
1363 mp->antposition[4][0] = 2.0;
1364 mp->antposition[4][1] = -2.0;
1365 mp->antposition[4][1] = 0.15;
1369 for (i = 0; i < ANTCOUNT; i++) {
1370 mp->antvelocity[i] = 0.02;
1371 mp->antsize[i] = 1.0;
1375 mp->bposition[0][0] = 0;
1376 mp->bposition[0][1] = 8;
1378 mp->bposition[1][0] = 9;
1379 mp->bposition[1][1] = 1;
1381 mp->bposition[2][0] = 1;
1382 mp->bposition[2][1] = 1;
1384 mp->bposition[3][0] = 4;
1385 mp->bposition[3][1] = 8;
1387 mp->bposition[4][0] = 2;
1388 mp->bposition[4][1] = 1;
1397 mp->entroducing = 12;
1401 mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
1402 mp->trackball = gltrackball_init ();
1404 if ((mp->glx_context = init_GL(mi)) != NULL) {
1405 reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1406 glDrawBuffer(GL_BACK);
1413 ENTRYPOINT void draw_antmaze(ModeInfo * mi)
1415 double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1419 Display *display = MI_DISPLAY(mi);
1420 Window window = MI_WINDOW(mi);
1424 mp = &antmaze[MI_SCREEN(mi)];
1426 MI_IS_DRAWN(mi) = True;
1428 if(!mp->glx_context)
1431 mi->polygon_count = 0;
1432 glXMakeCurrent(display, window, *(mp->glx_context));
1434 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1438 /* h = ((GLfloat) MI_HEIGHT(mi)/2) / (3*(GLfloat)MI_WIDTH(mi)/4); */
1439 glViewport(MI_WIDTH(mi)/32, MI_HEIGHT(mi)/8, (9*MI_WIDTH(mi))/16, 3*MI_HEIGHT(mi)/4);
1440 glMatrixMode(GL_PROJECTION);
1443 /* h = (3*MI_HEIGHT(mi)/4) / (3*MI_WIDTH(mi)/4); */
1444 gluPerspective(45, 1/h, 1, 25.0);
1446 glMatrixMode(GL_MODELVIEW);
1451 /* follow focused ant */
1452 glTranslatef(0.0, 0.0, -mp->mag - 5.0);
1453 glRotatef(20.0+5.0*sin(mp->ant_step/40.0), 1.0, 0.0, 0.0);
1454 /* glTranslatef(0.0, */
1455 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0)), */
1456 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0))); */
1458 gltrackball_rotate(mp->trackball);
1460 glRotatef(mp->ant_step*0.6, 0.0, 1.0, 0.0);
1462 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1464 /* glTranslatef(-antposition[0][0]-0.5, 0.0, -antposition[focus][1]); */
1468 if(!draw_antmaze_strip(mi)) {
1469 release_antmaze(mi);
1476 h = (GLfloat) (3*MI_HEIGHT(mi)/8) / (GLfloat) (MI_WIDTH(mi)/2);
1480 glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
1481 glMatrixMode(GL_PROJECTION);
1483 gluPerspective(45, 1/h, 1, 25.0);
1484 glMatrixMode(GL_MODELVIEW);
1487 glTranslatef(0.0, 0.0, -16.0);
1488 glRotatef(60.0, 1.0, 0.0, 0.0);
1489 glRotatef(-15.0 + mp->ant_step/10.0, 0.0, 1.0, 0.0);
1490 gltrackball_rotate(mp->trackball);
1493 if(!draw_antmaze_strip(mi)) {
1494 release_antmaze(mi);
1500 /* draw ant display */
1502 glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
1503 glMatrixMode(GL_PROJECTION);
1505 gluPerspective(45, 1/h, 1, 25.0);
1506 glMatrixMode(GL_MODELVIEW);
1509 glTranslatef(0.0, 0.0, -1.6);
1510 glRotatef(30.0, 1.0, 0.0, 0.0);
1511 glRotatef(mp->ant_step, 0.0, 1.0, 0.0);
1512 glRotatef(90.0, 0.0, 0.0, 1.0);
1514 /* /\* draw ant shadow *\/ */
1515 /* glPushMatrix(); */
1516 /* glScalef(1.0, 0.01, 1.0); */
1517 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1518 /* glRotatef(90.0, 0.0, 1.0, 0.0); */
1519 /* glDisable(GL_LIGHTING); */
1520 /* glColor4fv(MaterialGray6); */
1522 /* /\* slow down first ant *\/ */
1523 /* draw_ant(MaterialGrayB, 0, 1, first_ant_step, mySphere, myCone); */
1524 /* glPopMatrix(); */
1527 glEnable(GL_TEXTURE_2D);
1528 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1529 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1530 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
1531 draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
1532 glDisable(GL_TEXTURE_2D);
1536 /* /\* draw overlay *\/ */
1537 /* glPushMatrix(); */
1539 /* /\* go to ortho mode *\/ */
1540 /* glViewport(MI_WIDTH(mi)/2, MI_HEIGHT(mi)/8, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); */
1542 /* glMatrixMode(GL_PROJECTION); */
1543 /* glLoadIdentity(); */
1545 /* glPushMatrix (); */
1546 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
1548 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); */
1549 /* glColor4fv(MaterialGrayB); */
1551 /* glDisable(GL_LIGHTING); */
1552 /* glEnable(GL_BLEND); */
1554 /* glBegin(GL_QUADS); */
1555 /* glNormal3f(0.0, 0.0, 1.0); */
1556 /* glVertex3f(4.0, 3.0, 0.0); */
1557 /* glVertex3f(2.0, 3.0, 0.0); */
1558 /* glVertex3f(2.0, -3.0, 0.0); */
1559 /* glVertex3f(4.0, -3.0, 0.0); */
1560 /* mi->polygon_count++; */
1563 /* glEnable(GL_LIGHTING); */
1564 /* glDisable(GL_BLEND); */
1566 /* glPopMatrix(); */
1567 /* glPopMatrix(); */
1569 if (MI_IS_FPS(mi)) do_fps (mi);
1572 glXSwapBuffers(display, window);
1580 ENTRYPOINT void change_antmaze(ModeInfo * mi)
1582 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1584 if (!mp->glx_context)
1587 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context));
1590 #endif /* !STANDALONE */
1592 XSCREENSAVER_MODULE ("AntMaze", antmaze)