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
19 static const char sccsid[] = "@(#)antmaze.c 5.01 2001/03/01 xlockmore";
24 # define DEFAULTS "*delay: 20000 \n" \
25 "*showFPS: False \n" \
28 # define refresh_antmaze 0
29 # define release_antmaze 0
30 # include "xlockmore.h" /* from the xscreensaver distribution */
31 #else /* !STANDALONE */
32 # include "xlock.h" /* from the xlockmore distribution */
33 #endif /* !STANDALONE */
38 # include <X11/Xlib.h>
45 #endif /* HAVE_JWZGLES */
53 #include "gltrackball.h"
55 #define DEF_SOLIDANTMAZE "False"
56 #define DEF_NOANTS "False"
58 static int solidantmaze;
61 static XrmOptionDescRec opts[] =
63 {"-solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "on"},
64 {"+solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "off"},
65 {"-noants", ".antmaze.noants", XrmoptionNoArg, "on"},
66 {"+noants", ".antmaze.noants", XrmoptionNoArg, "off"}
68 static argtype vars[] =
70 {&solidantmaze, "solidantmaze", "Solidantmaze", DEF_SOLIDANTMAZE, t_Bool},
71 {&noants, "noants", "Noants", DEF_NOANTS, t_Bool}
74 static OptionStruct desc[] =
76 {"-/+solidantmaze", "select between a SOLID or a NET Antmaze Strip"},
77 {"-/+noants", "turn on/off walking ants"}
80 ENTRYPOINT ModeSpecOpt antmaze_opts =
81 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
84 ModStruct antmaze_description =
85 {"antmaze", "init_antmaze", "draw_antmaze", NULL,
86 "draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
87 1000, 1, 1, 1, 4, 1.0, "",
88 "draws some ants", 0, NULL};
92 #define Scale4Window 0.3
93 #define Scale4Iconic 0.4
95 #define sqr(A) ((A)*(A))
101 #define ObjAntmazeStrip 0
105 /*************************************************************************/
117 #define checkImageWidth 64
118 #define checkImageHeight 64
123 GLfloat ant_position;
124 GLXContext *glx_context;
126 trackball_state *trackball;
132 double antdirection[ANTCOUNT];
133 double antposition[ANTCOUNT][3];
136 double antvelocity[ANTCOUNT];
137 double antsize[ANTCOUNT];
138 int bposition[ANTCOUNT][2];
139 int board[BOARDCOUNT][10][10];
142 double antpath[ANTCOUNT][PARTS][2];
143 int antpathlength[ANTCOUNT];
145 GLubyte checkers[checkImageWidth][checkImageHeight][3];
147 GLuint checktexture, brushedtexture;
151 double first_ant_step;
163 static antmazestruct *antmaze = (antmazestruct *) NULL;
166 static const GLfloat MaterialRed[] = {0.6, 0.0, 0.0, 1.0};
167 /*static const GLfloat MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};*/
168 static const GLfloat MaterialGray8[] = {0.8, 0.8, 0.8, 1.0};
169 static const GLfloat MaterialGray35[] = {0.30, 0.30, 0.30, 1.0};
170 static const GLfloat MaterialGray4[] = {0.40, 0.40, 0.40, 1.0};
171 static const GLfloat MaterialOrange[] = {1.0, 0.69, 0.00, 1.0};
172 static const GLfloat MaterialGreen[] = {0.1, 0.4, 0.2, 1.0};
174 /* lighting variables */
175 static const GLfloat front_shininess[] = {60.0};
176 static const GLfloat front_specular[] = {0.8, 0.8, 0.8, 1.0};
177 static const GLfloat ambient[] = {0.1, 0.1, 0.1, 1.0};
178 /*static const GLfloat ambient2[] = {0.0, 0.0, 0.0, 0.0};*/
179 static const GLfloat diffuse[] = {0.8, 0.8, 0.8, 1.0};
180 static const GLfloat position0[] = {1.0, 5.0, 1.0, 1.0};
181 static const GLfloat position1[] = {-1.0, -5.0, 1.0, 1.0};
182 /*static const GLfloat lmodel_ambient[] = {0.8, 0.8, 0.8, 1.0};*/
183 /*static const GLfloat lmodel_twoside[] = {GL_TRUE};*/
184 /*static const GLfloat spotlight_ambient[] = { 0.0, 0.0, 0.0, 1.0 };*/
185 /*static const GLfloat spotlight_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };*/
190 static Bool mySphere(float radius)
193 GLUquadricObj *quadObj;
195 if((quadObj = gluNewQuadric()) == 0)
197 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
198 gluSphere(quadObj, radius, 16, 16);
199 gluDeleteQuadric(quadObj);
202 glScalef (radius, radius, radius);
203 glRotatef (90, 1, 0, 0);
204 unit_sphere (16, 16, False);
211 /* silhouette sphere */
212 static Bool mySphere2(float radius)
214 GLUquadricObj *quadObj;
216 if((quadObj = gluNewQuadric()) == 0)
218 gluQuadricDrawStyle(quadObj, (GLenum) GLU_SILHOUETTE);
219 gluSphere(quadObj, radius, 16, 8);
220 gluDeleteQuadric(quadObj);
226 /* textured sphere */
227 static Bool mySphereTex(float radius)
230 GLUquadricObj *quadObj;
232 if((quadObj = gluNewQuadric()) == 0)
234 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
235 gluQuadricTexture(quadObj, GL_TRUE);
236 gluQuadricNormals(quadObj, GLU_SMOOTH);
237 gluSphere(quadObj, radius, 32, 16);
238 gluDeleteQuadric(quadObj);
241 glScalef (radius, radius, radius);
242 glRotatef (90, 1, 0, 0);
243 unit_sphere (32, 16, False);
251 static Bool myCone(float radius)
254 GLUquadricObj *quadObj;
256 if ((quadObj = gluNewQuadric()) == 0)
258 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
259 gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
260 gluDeleteQuadric(quadObj);
265 8, True, True, False);
271 static Bool myCone2(float radius) { return True; }
274 static const float *antmaterial[ANTCOUNT] =
275 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange, MaterialGreen};
277 static const float *materials[MATERIALS] =
278 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange};
281 static void makeCheckImage(antmazestruct *mp)
285 for (i = 0; i < checkImageWidth; i++) {
286 for (j = 0; j < checkImageHeight; j++) {
287 if(((((i&0x8)==0)^((j&0x8)))==0)) {
288 int c = 102 + random()%32;
289 mp->checkers[i][j][0] = c;
290 mp->checkers[i][j][1] = c;
291 mp->checkers[i][j][2] = c;
294 int c = 153 + random()%32;
295 mp->checkers[i][j][0] = c;/*153;*/
296 mp->checkers[i][j][1] = c;/*c;*//*0;*/
297 mp->checkers[i][j][2] = c;/*c;*//*0;*/
302 glGenTextures(1, &mp->checktexture);
303 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
305 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
306 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
307 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
308 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
309 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
310 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
311 &mp->checkers[0][0]);
312 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
315 static void makeBrushedImage(antmazestruct *mp)
319 for(i = 0; i < checkImageWidth; ++i)
320 for(j = 0; j < checkImageHeight; ++j) {
322 c = 102+102*fabs(sin(2.0*i / Pi)*sin(2.0*j/Pi)) + random()%51;
324 /* c = (i+j)%8==0 || (i+j+5)%8==0 ? 153 : 102; */
326 mp->checkers[i][j][0] = c;
327 mp->checkers[i][j][1] = c;
328 mp->checkers[i][j][2] = c;
331 /* for (i = 0; i < checkImageWidth; i++) { */
332 /* for (j = 0; j < checkImageHeight; j++) { */
333 /* int c = 102 + pow((random()%1000)/1000.0, 4)*103; */
334 /* checkers[i][j][0] = c; */
335 /* checkers[i][j][1] = c; */
336 /* checkers[i][j][2] = c; */
341 /* for (i = 0; i < checkImageWidth; i++) { */
342 /* for (j = 0; j < checkImageHeight; j++) { */
343 /* int a = checkers[(i+checkImageWidth+1)%checkImageWidth][j][0] + */
344 /* 4*checkers[i][j][0] + checkers[(i+1)%checkImageWidth][j][0]; */
346 /* checkers[i][j][0] = a; */
347 /* checkers[i][j][1] = a; */
348 /* checkers[i][j][2] = a; */
352 glGenTextures(1, &mp->brushedtexture);
353 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
355 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
356 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
357 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
358 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
359 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
360 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
361 &mp->checkers[0][0]);
362 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
366 static void draw_wall(ModeInfo *mi, double x1, double z1, double x2, double z2)
368 float x = fabs(x2 - x1)/2.0;
373 glNormal3f(0.0, 1.0, 0.0);
374 glTexCoord2f(0.0, 0.0);
375 glVertex3f(x1, 1.0, z1+0.25);
376 glTexCoord2f(x, 0.0);
377 glVertex3f(x2, 1.0, z2+0.25);
378 glTexCoord2f(x, 0.25);
379 glVertex3f(x2, 1.0, z2-0.25);
380 glTexCoord2f(0.0, 0.25);
381 glVertex3f(x1, 1.0, z1-0.25);
385 glNormal3f(0.0, 0.0, 1.0);
386 glTexCoord2f(0.0, 0.0);
387 glVertex3f(x1, 0.0, z1+0.25);
388 glTexCoord2f(x, 0.0);
389 glVertex3f(x2, 0.0, z2+0.25);
390 glTexCoord2f(x, 0.5);
391 glVertex3f(x2, 1.0, z2+0.25);
392 glTexCoord2f(0.0, 0.5);
393 glVertex3f(x1, 1.0, z1+0.25);
396 glNormal3f(0.0, 0.0, -1.0);
397 glTexCoord2f(0.0, 0.0);
398 glVertex3f(x1, 0.0, z1-0.25);
399 glTexCoord2f(x, 0.0);
400 glVertex3f(x2, 0.0, z2-0.25);
401 glTexCoord2f(x, 0.5);
402 glVertex3f(x2, 1.0, z2-0.25);
403 glTexCoord2f(0.0, 0.5);
404 glVertex3f(x1, 1.0, z1-0.25);
408 glNormal3f(1.0, 0.0, 0.0);
409 glTexCoord2f(0.0, 0.0);
410 glVertex3f(x2, 0.0, z2+0.25);
411 glTexCoord2f(0.25, 0.0);
412 glVertex3f(x2, 0.0, z2-0.25);
413 glTexCoord2f(0.25, 0.5);
414 glVertex3f(x2, 1.0, z2-0.25);
415 glTexCoord2f(0.0, 0.5);
416 glVertex3f(x2, 1.0, z2+0.25);
419 glNormal3f(-1.0, 0.0, 0.0);
420 glTexCoord2f(0.0, 0.0);
421 glVertex3f(x1, 0.0, z1-0.25);
422 glTexCoord2f(0.25, 0.0);
423 glVertex3f(x1, 0.0, z1+0.25);
424 glTexCoord2f(0.25, 0.5);
425 glVertex3f(x1, 1.0, z1+0.25);
426 glTexCoord2f(0.0, 0.5);
427 glVertex3f(x1, 1.0, z1-0.25);
434 static void draw_board(ModeInfo *mi, antmazestruct *mp)
441 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
445 for(i = 0; i < BOARDSIZE; ++i)
446 for(j = 0; j < BOARDSIZE; ++j) {
447 if(mp->board[mp->currentboard][j][i]) {
449 /* /\* draw top *\/ */
450 /* glNormal3f(0.0, 1.0, 0.0); */
451 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
452 /* glVertex3f(i-0.5, h, j+0.5); */
453 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
454 /* glVertex3f(i+0.5, h, j+0.5); */
455 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
456 /* glVertex3f(i+0.5, h, j-0.5); */
457 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
458 /* glVertex3f(i-0.5, h, j-0.5); */
461 glNormal3f(0.0, 1.0, 0.0);
462 glTexCoord2f(0.0 + stf, 0.0 + stf);
463 glVertex3f(i-0.5, h, j+0.5);
464 glTexCoord2f(1.0 + stf, 0.0 + stf);
465 glVertex3f(i+0.5, h, j+0.5);
466 glTexCoord2f(1.0 + stf, 1.0 + stf);
467 glVertex3f(i+0.5, h, j-0.5);
468 glTexCoord2f(0.0 + stf, 1.0 + stf);
469 glVertex3f(i-0.5, h, j-0.5);
472 /* draw south face */
473 if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
474 glNormal3f(0.0, 0.0, 1.0);
475 glTexCoord2f(0.0 + stf, 0.0 + stf);
476 glVertex3f(i-0.5, 0.0, j+0.5);
477 glTexCoord2f(1.0 + stf, 0.0 + stf);
478 glVertex3f(i+0.5, 0.0, j+0.5);
479 glTexCoord2f(1.0 + stf, h + stf);
480 glVertex3f(i+0.5, h, j+0.5);
481 glTexCoord2f(0.0 + stf, h + stf);
482 glVertex3f(i-0.5, h, j+0.5);
486 /* draw north face */
487 if(j == 0 || !mp->board[mp->currentboard][j-1][i]) {
488 glNormal3f(0.0, 0.0, -1.0);
489 glTexCoord2f(0.0 + stf, 0.0 + stf);
490 glVertex3f(i+0.5, 0.0, j-0.5);
491 glTexCoord2f(1.0 + stf, 0.0 + stf);
492 glVertex3f(i-0.5, 0.0, j-0.5);
493 glTexCoord2f(1.0 + stf, h + stf);
494 glVertex3f(i-0.5, h, j-0.5);
495 glTexCoord2f(0.0 + stf, h + stf);
496 glVertex3f(i+0.5, h, j-0.5);
501 if(i == 9 || !mp->board[mp->currentboard][j][i+1]) {
502 glNormal3f(1.0, 0.0, 0.0);
503 glTexCoord2f(0.0 + stf, 0.0 + stf);
504 glVertex3f(i+0.5, 0.0, j+0.5);
505 glTexCoord2f(1.0 + stf, 0.0 + stf);
506 glVertex3f(i+0.5, 0.0, j-0.5);
507 glTexCoord2f(1.0 + stf, h + stf);
508 glVertex3f(i+0.5, h, j-0.5);
509 glTexCoord2f(0.0 + stf, h + stf);
510 glVertex3f(i+0.5, h, j+0.5);
515 if(i == 0 || !mp->board[mp->currentboard][j][i-1]) {
516 glNormal3f(-1.0, 0.0, 0.0);
517 glTexCoord2f(0.0 + stf, 0.0 + stf);
518 glVertex3f(i-0.5, 0.0, j-0.5);
519 glTexCoord2f(1.0 + stf, 0.0 + stf);
520 glVertex3f(i-0.5, 0.0, j+0.5);
521 glTexCoord2f(1.0 + stf, h + stf);
522 glVertex3f(i-0.5, h, j+0.5);
523 glTexCoord2f(0.0 + stf, h + stf);
524 glVertex3f(i-0.5, h, j-0.5);
530 glNormal3f(0.0, 1.0, 0.0);
531 glTexCoord2f(0.0, 0.0);
532 glVertex3f(i-0.5, 0.0, j+0.5);
533 glTexCoord2f(tx, 0.0);
534 glVertex3f(i+0.5, 0.0, j+0.5);
535 glTexCoord2f(tx, tx);
536 glVertex3f(i+0.5, 0.0, j-0.5);
537 glTexCoord2f(0.0, tx);
538 glVertex3f(i-0.5, 0.0, j-0.5);
544 /* /\* draw elevator *\/ */
545 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
547 /* glBegin(GL_QUADS); */
549 /* glNormal3f(0.0, 1.0, 0.0); */
551 /* if(pastfirst) { */
553 /* glTexCoord2f(0.0, 0.0); */
554 /* glVertex3f(0.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
555 /* glTexCoord2f(1.0, 0.0); */
556 /* glVertex3f(1.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
557 /* glTexCoord2f(1.0, 1.5); */
558 /* glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
559 /* glTexCoord2f(0.0, 1.5); */
560 /* glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
561 /* mi->polygon_count++; */
564 /* /\* destination *\/ */
565 /* glTexCoord2f(0.0, 0.0); */
566 /* glVertex3f(BOARDSIZE - 2.5, elevator, -2.0 - 0.2); */
567 /* glTexCoord2f(1.0, 0.0); */
568 /* glVertex3f(BOARDSIZE - 1.5, elevator, -2.0 - 0.2); */
569 /* glTexCoord2f(1.0, 1.5); */
570 /* glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
571 /* glTexCoord2f(0.0, 1.5); */
572 /* glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
573 /* mi->polygon_count++; */
577 /* for(i = 0; i < BOARDSIZE; ++i) */
578 /* for(j = 0; j < BOARDSIZE; ++j) { */
579 /* if(board[j][i]) { */
581 /* /\* draw brushed boxtop *\/ */
582 /* glNormal3f(0.0, 1.0, 0.0); */
583 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
584 /* glVertex3f(i-0.5 + stf, h+0.001, j+0.5 - stf); */
585 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
586 /* glVertex3f(i+0.5 - stf, h+0.001, j+0.5 - stf); */
587 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
588 /* glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
589 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
590 /* glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
591 /* mi->polygon_count++; */
598 static void build_board(antmazestruct *mp, int b)
602 for(i = 0; i < BOARDSIZE; ++i)
603 for(j = 0; j < BOARDSIZE; ++j)
604 mp->board[b][i][j] = 1;
606 /* for(i = 0; i < BOARDSIZE; ++i) { */
607 /* board[0][i] = 1; */
608 /* board[i][0] = 1; */
609 /* board[BOARDSIZE-1][BOARDSIZE-i] = 1; */
610 /* board[BOARDSIZE-i][BOARDSIZE-1] = 1; */
613 /* board[0][BOARDSIZE-2] = 0; */
614 /* board[BOARDSIZE-1][1] = 0; */
617 mp->board[b][BOARDSIZE-1][1] = 0;
618 mp->board[b][0][BOARDSIZE-2] = 0;
620 /* build the ant paths */
621 if(mp->currentboard == b) {
622 for(i = 0; i < ANTCOUNT; ++i) {
623 int sx = BOARDSIZE-2;
627 mp->board[b][sx][sy] = 0;
628 mp->antpath[i][j][0] = sy - 5.0;
629 mp->antpath[i][j][1] = sx - 5.0;
634 else if(sy < BOARDSIZE-2)
650 mp->antpath[i][j][0] = BOARDSIZE-7.0;
651 mp->antpath[i][j][1] = -7.0;
652 mp->antpathlength[i] = j;
656 /* for(i = 0; i < 20; ++i) { */
657 /* int x = 1 + random()%(BOARDSIZE-2); */
658 /* int y = 1 + random()%(BOARDSIZE-2); */
659 /* board[x][y] = 1; */
663 /* compute nearness */
664 static int near(double a[2], double b[2])
666 return fabs(a[0] - b[0]) < 0.5 && fabs(a[1] - b[1]) < 0.5;
669 static double sign(double d)
671 return d < 0.0 ? -1.0 : 1.0;
674 static double min(double a, double b)
676 return a < b ? a : b;
679 /* draw method for ant */
680 static Bool draw_ant(ModeInfo *mi, antmazestruct *mp,
681 const float *Material, int mono, int shadow,
682 float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
685 float cos1 = cos(mp->ant_step);
686 float cos2 = cos(mp->ant_step + 2 * Pi / 3);
687 float cos3 = cos(mp->ant_step + 4 * Pi / 3);
688 float sin1 = sin(mp->ant_step);
689 float sin2 = sin(mp->ant_step + 2 * Pi / 3);
690 float sin3 = sin(mp->ant_step + 4 * Pi / 3);
692 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : Material);
694 /* glEnable(GL_CULL_FACE); */
698 if(!((*sphere)(0.18)))
700 glScalef(1, 1 / 1.3, 1);
701 glTranslatef(0.00, 0.30, 0.00);
702 if(!((*sphere)(0.2)))
705 glTranslatef(-0.05, 0.17, 0.05);
706 glRotatef(-90, 1, 0, 0);
707 glRotatef(-25, 0, 1, 0);
710 glTranslatef(0.00, 0.10, 0.00);
713 glRotatef(25, 0, 1, 0);
714 glRotatef(90, 1, 0, 0);
717 glTranslatef(0.15, -0.65, 0.05);
718 if(!((*sphere)(0.25)))
720 glScalef(1, 1 / 1.3, 1);
723 /* glDisable(GL_CULL_FACE); */
725 glDisable(GL_LIGHTING);
729 glColor3fv(mono ? MaterialGray5 : Material);
730 glVertex3f(0.00, 0.30, 0.00);
731 glColor3fv(MaterialGray);
732 glVertex3f(0.40, 0.70, 0.40);
734 glColor3fv(mono ? MaterialGray5 : Material);
735 glVertex3f(0.00, 0.30, 0.00);
736 glColor3fv(MaterialGray);
737 glVertex3f(0.40, 0.70, -0.40);
743 glColor3fv(mono ? MaterialGray6 : MaterialRed);
744 glVertex3f(0.40, 0.70, 0.40);
746 glVertex3f(0.40, 0.70, -0.40);
752 glBegin(GL_LINE_STRIP);
753 glColor3fv(mono ? MaterialGray5 : Material);
754 glVertex3f(0.00, 0.05, 0.18);
755 glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
757 glColor3fv(MaterialGray);
758 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
762 /* LEFT-CENTER ARM */
763 glBegin(GL_LINE_STRIP);
764 glColor3fv(mono ? MaterialGray5 : Material);
765 glVertex3f(0.00, 0.00, 0.18);
766 glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
768 glColor3fv(MaterialGray);
769 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
774 glBegin(GL_LINE_STRIP);
775 glColor3fv(mono ? MaterialGray5 : Material);
776 glVertex3f(0.00, -0.05, 0.18);
777 glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
779 glColor3fv(MaterialGray);
780 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
784 /* RIGHT-FRONT ARM */
785 glBegin(GL_LINE_STRIP);
786 glColor3fv(mono ? MaterialGray5 : Material);
787 glVertex3f(0.00, 0.05, -0.18);
788 glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
790 glColor3fv(MaterialGray);
791 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
795 /* RIGHT-CENTER ARM */
796 glBegin(GL_LINE_STRIP);
797 glColor3fv(mono ? MaterialGray5 : Material);
798 glVertex3f(0.00, 0.00, -0.18);
799 glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
801 glColor3fv(MaterialGray);
802 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
807 glBegin(GL_LINE_STRIP);
808 glColor3fv(mono ? MaterialGray5 : Material);
809 glVertex3f(0.00, -0.05, -0.18);
810 glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
812 glColor3fv(MaterialGray);
813 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
819 glColor3fv(mono ? MaterialGray8 : MaterialGray35);
820 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
821 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
822 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
823 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
824 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
825 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
826 mi->polygon_count += 6;
830 glEnable(GL_LIGHTING);
835 static Bool draw_antmaze_strip(ModeInfo * mi)
837 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
839 int mono = MI_IS_MONO(mi);
841 /* glMatrixMode(GL_MODELVIEW); */
842 /* glLoadIdentity(); */
843 /* glPushMatrix(); */
845 glEnable(GL_LIGHTING);
846 /* glDisable(GL_BLEND); */
851 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
852 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
853 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
854 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
857 if(mp->elevator < 1.0) {
858 glEnable(GL_TEXTURE_2D);
859 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
860 glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
862 glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
863 glDisable(GL_TEXTURE_2D);
868 glTranslatef(0.0, -0.1, 0.0);
870 for(i = 0; i < ANTCOUNT; ++i) {
872 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
873 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
875 if(!mp->anton[i]) { continue; }
877 /* determine location, move to goal */
879 glTranslatef(0.0, 0.01, 0.0);
880 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
881 /* glScalef(1.0, 0.01, 1.0); */
882 glScalef(0.6, 0.01, 0.6);
883 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
884 glRotatef(90.0, 0.0, 0.0, 1.0);
885 glDisable(GL_LIGHTING);
887 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
888 glColor4fv(MaterialGrayB);
890 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
892 /* slow down first ant */
893 if(i == 0 && mp->part[i] == mp->antpathlength[i])
894 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
896 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
901 glEnable(GL_LIGHTING);
904 /* glTranslatef(0.0, 0.18, 0.0); */
905 glTranslatef(0.0, 0.12, 0.0);
906 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
907 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
908 glRotatef(90.0, 0.0, 0.0, 1.0);
909 glScalef(0.6, 0.6, 0.6);
911 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
913 /* glEnable(GL_TEXTURE_2D); */
914 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
916 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed); */
918 /* slow down first ant */
919 if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
920 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
921 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
922 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
925 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
926 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
928 glEnable(GL_TEXTURE_2D);
929 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
930 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
931 glDisable(GL_TEXTURE_2D);
935 /* draw_ant(mi, antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
936 /* glDisable(GL_TEXTURE_2D); */
942 /* /\* now draw overlay *\/ */
943 /* glDisable(GL_LIGHTING); */
944 /* glDisable(GL_BLEND); */
946 /* /\* go to ortho mode *\/ */
947 /* glMatrixMode(GL_PROJECTION); */
948 /* glPushMatrix(); */
949 /* glLoadIdentity(); */
950 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
952 /* /\* translate to corner *\/ */
953 /* glTranslatef(4.0-1.2, 3.0-1.2, 0.0); */
955 /* glDisable(GL_LIGHTING); */
956 /* glEnable(GL_BLEND); */
958 /* /\* draw the 2d board *\/ */
959 /* glBegin(GL_QUADS); */
962 /* double sz = 1.0; */
963 /* for(i = 0; i < BOARDSIZE; ++i) */
964 /* for(j = 0; j < BOARDSIZE; ++j) { */
965 /* int par = board[i][j]; */
966 /* glColor4f(par ? 0.4 : 0.6, */
967 /* par ? 0.4 : 0.6, */
968 /* par ? 0.4 : 0.6, */
970 /* glNormal3f(0.0, 0.0, 1.0); */
971 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
972 /* glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
973 /* glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
974 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
975 /* mi->polygon_count++; */
983 /* but the step size is the same! */
984 mp->ant_step += 0.18;
985 /* if(ant_step > 2*Pi) { */
986 /* ant_step = 0.0; */
989 if(mp->ant_step > 5*Pi)
992 mp->ant_position += 1;
995 #undef AntmazeDivisions
996 #undef AntmazeTransversals
998 ENTRYPOINT void reshape_antmaze(ModeInfo * mi, int width, int height)
1000 double h = (GLfloat) height / (GLfloat) width;
1001 int size = (width / 512) + 1;
1002 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1004 glViewport(0, 0, mp->WindW = (GLint) width, mp->WindH = (GLint) height);
1005 glMatrixMode(GL_PROJECTION);
1008 gluPerspective(45, 1/h, 1, 25.0);
1010 glMatrixMode(GL_MODELVIEW);
1011 /* glLineWidth(3.0); */
1016 static void update_ants(antmazestruct *mp)
1020 df[0] = df[1] = df[2] = 0.8*mp->fadeout;
1024 if(mp->fadeoutspeed < -0.00001) {
1026 if(mp->fadeout <= 0.0) {
1027 /* switch boards: rebuild old board, increment current */
1028 mp->currentboard = (mp->currentboard+1)%BOARDCOUNT;
1029 build_board(mp, mp->currentboard);
1030 mp->fadeoutspeed = 0.02;
1033 mp->fadeout += mp->fadeoutspeed;
1035 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
1036 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1040 if(mp->fadeoutspeed > 0.0001) {
1041 mp->fadeout += mp->fadeoutspeed;
1042 if(mp->fadeout >= 1.0) {
1044 mp->fadeoutspeed = 0.0;
1045 mp->entroducing = 12;
1047 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
1048 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1051 for(i = 0; i < ANTCOUNT; ++i) {
1053 if(!mp->anton[i] && mp->elevator < 1.0) {
1056 if(mp->entroducing > 0 && mp->introduced <= 0 && random()%100 == 0) {
1059 mp->antsize[i] = 0.0;
1060 mp->antposition[i][0] = -4.0;
1061 mp->antposition[i][1] = 5.0;
1062 mp->antdirection[i] = PI/2.0;
1063 mp->bposition[i][0] = 0;
1064 mp->bposition[i][1] = 8;
1065 mp->introduced = 300;
1072 if(mp->part[i] == 0 && mp->antsize[i] < 1.0) {
1073 mp->antsize[i] += 0.02;
1077 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] > 0.0) {
1078 mp->antsize[i] -= 0.02;
1079 if(mp->antvelocity[i] > 0.0) {
1080 mp->antvelocity[i] -= 0.02;
1082 else { mp->antvelocity[i] = 0.0; }
1087 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] <= 0.0) {
1088 mp->antvelocity[i] = 0.02;
1091 antmaterial[i] = materials[random()%MATERIALS];
1094 mp->antdirection[i] = PI/2.0;
1095 mp->bposition[i][0] = 0;
1096 mp->bposition[i][1] = 8;
1099 mp->antsize[i] = 0.0;
1103 mp->antposition[i][0] = -4.0;
1104 mp->antposition[i][1] = 5.0;
1106 /* /\* reset camera *\/ */
1107 /* if(i == focus) { */
1109 /* ant_step = 0.0; */
1112 /* check for the end */
1113 if(mp->entroducing <= 0) {
1115 for(z = 0; z < ANTCOUNT; ++z) {
1116 if(mp->anton[z]) { ao = 1; break; }
1120 mp->fadeoutspeed = -0.02;
1126 /* near goal, bend path towards next step */
1127 if(near(mp->antposition[i], mp->antpath[i][mp->part[i]])) {
1131 /* /\* special first ant *\/ */
1132 /* if(i == 0 && part[i] > antpathlength[i]) { */
1134 /* first_ant_step = ant_step; */
1136 /* antvelocity[i] = 0.0; */
1137 /* /\* antposition[i][2] += 0.025; *\/ */
1138 /* elevator += 0.025; */
1140 /* /\* set light *\/ */
1141 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
1142 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
1143 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
1144 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
1146 /* /\* draw next board *\/ */
1147 /* if(elevator > 1.0) { */
1149 /* if(makenew == 1) { */
1152 /* /\* switch boards: rebuild old board, increment current *\/ */
1153 /* currentboard = (currentboard+1)%BOARDCOUNT; */
1154 /* build_board(currentboard); */
1156 /* for(re = 1; re < ANTCOUNT; ++re) { */
1157 /* anton[re] = 0; */
1158 /* antmaterial[re] = materials[random()%MATERIALS]; */
1165 /* /\* draw the other board *\/ */
1166 /* glEnable(GL_TEXTURE_2D); */
1167 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6); */
1169 /* glPushMatrix(); */
1170 /* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */
1171 /* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
1172 /* draw_board(mi, mp); */
1173 /* glPopMatrix(); */
1174 /* glDisable(GL_TEXTURE_2D); */
1177 /* if(elevator > 2.0) { */
1178 /* antposition[i][0] = -4.0;/\*-= -(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0);*\//\*= -4.0;*\/ */
1179 /* antposition[i][1] = 5.5;/\*-(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0);*\/ */
1180 /* /\* antposition[i][2] = 0.15; *\/ */
1181 /* antdirection[i] = PI/2.0; */
1182 /* bposition[i][0] = 0; */
1183 /* bposition[i][1] = 8; */
1185 /* antvelocity[i] = 0.02; */
1187 /* antmaterial[i] = MaterialRed; */
1191 /* elevator = 0.0; */
1192 /* introduced = 200; */
1201 /* move toward goal, correct ant direction if required */
1205 double dx = mp->antpath[i][mp->part[i]][0] - mp->antposition[i][0];
1206 double dz = - mp->antpath[i][mp->part[i]][1] + mp->antposition[i][1];
1207 double theta, ideal;
1210 theta = atan(dz/dx);
1212 theta = dx > EPSILON ? 0.0 : PI;
1214 ideal = theta - mp->antdirection[i];
1218 /* compute correction */
1220 double dt = sign(ideal) * min(fabs(ideal), PI/90.0);
1221 mp->antdirection[i] += dt;
1222 if(mp->antdirection[i] > 2.0*PI)
1223 mp->antdirection[i] = 0.0;
1227 mp->antposition[i][0] += mp->antvelocity[i] * cos(mp->antdirection[i]);
1228 mp->antposition[i][1] += mp->antvelocity[i] * sin(-mp->antdirection[i]);
1232 static void pinit(antmazestruct *mp)
1235 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
1236 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1237 glLightfv(GL_LIGHT0, GL_POSITION, position0);
1238 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
1239 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1240 glLightfv(GL_LIGHT1, GL_POSITION, position1);
1242 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
1243 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001);
1244 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
1246 glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05);
1247 glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001);
1248 glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
1251 /* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
1252 /* glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */
1253 glEnable(GL_LIGHTING);
1254 glEnable(GL_LIGHT0);
1255 glEnable(GL_LIGHT1);
1256 glEnable(GL_NORMALIZE);
1257 glFrontFace(GL_CCW);
1258 glCullFace(GL_BACK);
1261 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
1262 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
1264 glShadeModel(GL_SMOOTH);
1265 glEnable(GL_DEPTH_TEST);
1266 glDisable(GL_TEXTURE_2D);
1268 /* setup textures */
1270 makeBrushedImage(mp);
1275 /* makeCheckImage(); */
1276 /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */
1277 /* glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, */
1278 /* checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */
1279 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */
1280 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */
1282 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
1283 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
1284 /* glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */
1285 glEnable(GL_TEXTURE_2D);
1287 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */
1288 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
1291 #define MAX_MAGNIFICATION 10
1292 #define max(a, b) a < b ? b : a
1293 #define min(a, b) a < b ? a : b
1295 ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
1297 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1299 if (gltrackball_event_handler (event, mp->trackball,
1300 MI_WIDTH (mi), MI_HEIGHT (mi),
1301 &mp->button_down_p))
1304 if (event->xany.type == ButtonPress)
1306 switch(event->xbutton.button) {
1309 mp->focus = (mp->focus + 1) % ANTCOUNT;
1313 mp->mag = max(mp->mag-1, 1);
1317 mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
1325 ENTRYPOINT void init_antmaze(ModeInfo * mi)
1327 double rot_speed = 0.3;
1332 MI_INIT(mi, antmaze, NULL);
1333 mp = &antmaze[MI_SCREEN(mi)];
1334 mp->step = NRAND(90);
1335 mp->ant_position = NRAND(90);
1338 mp->antdirection[0] = PI/2.0;
1339 mp->antdirection[1] = PI/2.0;
1340 mp->antdirection[2] = 0;
1341 mp->antdirection[3] = PI/2.0;
1342 mp->antdirection[4] = PI/2.0;
1344 mp->antposition[0][0] = -4.0;
1345 mp->antposition[0][1] = 5.0;
1346 mp->antposition[0][1] = 0.15;
1348 mp->antposition[1][0] = -4.0;
1349 mp->antposition[1][1] = 3.0;
1350 mp->antposition[1][1] = 0.15;
1352 mp->antposition[2][0] = -1.0;
1353 mp->antposition[2][1] = -2.0;
1354 mp->antposition[2][1] = 0.15;
1356 mp->antposition[3][0] = -3.9;
1357 mp->antposition[3][1] = 6.0;
1358 mp->antposition[3][1] = 0.15;
1360 mp->antposition[4][0] = 2.0;
1361 mp->antposition[4][1] = -2.0;
1362 mp->antposition[4][1] = 0.15;
1366 for (i = 0; i < ANTCOUNT; i++) {
1367 mp->antvelocity[i] = 0.02;
1368 mp->antsize[i] = 1.0;
1372 mp->bposition[0][0] = 0;
1373 mp->bposition[0][1] = 8;
1375 mp->bposition[1][0] = 9;
1376 mp->bposition[1][1] = 1;
1378 mp->bposition[2][0] = 1;
1379 mp->bposition[2][1] = 1;
1381 mp->bposition[3][0] = 4;
1382 mp->bposition[3][1] = 8;
1384 mp->bposition[4][0] = 2;
1385 mp->bposition[4][1] = 1;
1394 mp->entroducing = 12;
1398 mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
1399 mp->trackball = gltrackball_init (False);
1401 if ((mp->glx_context = init_GL(mi)) != NULL) {
1402 reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1403 glDrawBuffer(GL_BACK);
1411 device_rotate(ModeInfo *mi)
1414 GLfloat rot = current_device_rotation();
1415 glRotatef(rot, 0, 0, 1);
1416 if ((rot > 45 && rot < 135) ||
1417 (rot < -45 && rot > -135))
1419 GLfloat s = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1420 glScalef (1/s, s, 1);
1426 ENTRYPOINT void draw_antmaze(ModeInfo * mi)
1428 double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1432 Display *display = MI_DISPLAY(mi);
1433 Window window = MI_WINDOW(mi);
1437 mp = &antmaze[MI_SCREEN(mi)];
1439 MI_IS_DRAWN(mi) = True;
1441 if(!mp->glx_context)
1444 mi->polygon_count = 0;
1445 glXMakeCurrent(display, window, *(mp->glx_context));
1447 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1451 /* h = ((GLfloat) MI_HEIGHT(mi)/2) / (3*(GLfloat)MI_WIDTH(mi)/4); */
1452 glViewport(MI_WIDTH(mi)/32, MI_HEIGHT(mi)/8, (9*MI_WIDTH(mi))/16, 3*MI_HEIGHT(mi)/4);
1453 glMatrixMode(GL_PROJECTION);
1456 /* h = (3*MI_HEIGHT(mi)/4) / (3*MI_WIDTH(mi)/4); */
1457 gluPerspective(45, 1/h, 1, 25.0);
1459 glMatrixMode(GL_MODELVIEW);
1465 /* follow focused ant */
1466 glTranslatef(0.0, 0.0, -mp->mag - 5.0);
1467 glRotatef(20.0+5.0*sin(mp->ant_step/40.0), 1.0, 0.0, 0.0);
1468 /* glTranslatef(0.0, */
1469 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0)), */
1470 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0))); */
1472 gltrackball_rotate(mp->trackball);
1474 glRotatef(mp->ant_step*0.6, 0.0, 1.0, 0.0);
1476 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1478 /* glTranslatef(-antposition[0][0]-0.5, 0.0, -antposition[focus][1]); */
1482 if(!draw_antmaze_strip(mi)) {
1490 h = (GLfloat) (3*MI_HEIGHT(mi)/8) / (GLfloat) (MI_WIDTH(mi)/2);
1494 glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
1495 glMatrixMode(GL_PROJECTION);
1498 gluPerspective(45, 1/h, 1, 25.0);
1499 glMatrixMode(GL_MODELVIEW);
1502 glTranslatef(0.0, 0.0, -16.0);
1503 glRotatef(60.0, 1.0, 0.0, 0.0);
1504 glRotatef(-15.0 + mp->ant_step/10.0, 0.0, 1.0, 0.0);
1505 gltrackball_rotate(mp->trackball);
1508 if(!draw_antmaze_strip(mi)) {
1515 /* draw ant display */
1517 glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
1518 glMatrixMode(GL_PROJECTION);
1521 gluPerspective(45, 1/h, 1, 25.0);
1522 glMatrixMode(GL_MODELVIEW);
1525 glTranslatef(0.0, 0.0, -1.6);
1526 glRotatef(30.0, 1.0, 0.0, 0.0);
1527 glRotatef(mp->ant_step, 0.0, 1.0, 0.0);
1528 glRotatef(90.0, 0.0, 0.0, 1.0);
1530 /* /\* draw ant shadow *\/ */
1531 /* glPushMatrix(); */
1532 /* glScalef(1.0, 0.01, 1.0); */
1533 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1534 /* glRotatef(90.0, 0.0, 1.0, 0.0); */
1535 /* glDisable(GL_LIGHTING); */
1536 /* glColor4fv(MaterialGray6); */
1538 /* /\* slow down first ant *\/ */
1539 /* draw_ant(MaterialGrayB, 0, 1, first_ant_step, mySphere, myCone); */
1540 /* glPopMatrix(); */
1543 glEnable(GL_TEXTURE_2D);
1544 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1545 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1546 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
1547 draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
1548 glDisable(GL_TEXTURE_2D);
1552 /* /\* draw overlay *\/ */
1553 /* glPushMatrix(); */
1555 /* /\* go to ortho mode *\/ */
1556 /* glViewport(MI_WIDTH(mi)/2, MI_HEIGHT(mi)/8, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); */
1558 /* glMatrixMode(GL_PROJECTION); */
1559 /* glLoadIdentity(); */
1561 /* glPushMatrix (); */
1562 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
1564 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); */
1565 /* glColor4fv(MaterialGrayB); */
1567 /* glDisable(GL_LIGHTING); */
1568 /* glEnable(GL_BLEND); */
1570 /* glBegin(GL_QUADS); */
1571 /* glNormal3f(0.0, 0.0, 1.0); */
1572 /* glVertex3f(4.0, 3.0, 0.0); */
1573 /* glVertex3f(2.0, 3.0, 0.0); */
1574 /* glVertex3f(2.0, -3.0, 0.0); */
1575 /* glVertex3f(4.0, -3.0, 0.0); */
1576 /* mi->polygon_count++; */
1579 /* glEnable(GL_LIGHTING); */
1580 /* glDisable(GL_BLEND); */
1582 /* glPopMatrix(); */
1583 /* glPopMatrix(); */
1585 if (MI_IS_FPS(mi)) {
1586 glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
1591 glXSwapBuffers(display, window);
1599 ENTRYPOINT void change_antmaze(ModeInfo * mi)
1601 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1603 if (!mp->glx_context)
1606 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context));
1609 #endif /* !STANDALONE */
1611 XSCREENSAVER_MODULE ("AntMaze", antmaze)