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" \
25 "*showFPS: False \n" \
28 # define refresh_antmaze 0
29 # include "xlockmore.h" /* from the xscreensaver distribution */
30 #else /* !STANDALONE */
31 # include "xlock.h" /* from the xlockmore distribution */
32 #endif /* !STANDALONE */
37 # include <X11/Xlib.h>
44 #endif /* HAVE_JWZGLES */
52 #include "gltrackball.h"
54 #define DEF_SOLIDANTMAZE "False"
55 #define DEF_NOANTS "False"
57 static int solidantmaze;
60 static XrmOptionDescRec opts[] =
62 {"-solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "on"},
63 {"+solidantmaze", ".antmaze.solidantmaze", XrmoptionNoArg, "off"},
64 {"-noants", ".antmaze.noants", XrmoptionNoArg, "on"},
65 {"+noants", ".antmaze.noants", XrmoptionNoArg, "off"}
67 static argtype vars[] =
69 {&solidantmaze, "solidantmaze", "Solidantmaze", DEF_SOLIDANTMAZE, t_Bool},
70 {&noants, "noants", "Noants", DEF_NOANTS, t_Bool}
73 static OptionStruct desc[] =
75 {"-/+solidantmaze", "select between a SOLID or a NET Antmaze Strip"},
76 {"-/+noants", "turn on/off walking ants"}
79 ENTRYPOINT ModeSpecOpt antmaze_opts =
80 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
83 ModStruct antmaze_description =
84 {"antmaze", "init_antmaze", "draw_antmaze", "release_antmaze",
85 "draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
86 1000, 1, 1, 1, 4, 1.0, "",
87 "draws some ants", 0, NULL};
91 #define Scale4Window 0.3
92 #define Scale4Iconic 0.4
94 #define sqr(A) ((A)*(A))
100 #define ObjAntmazeStrip 0
104 /*************************************************************************/
116 #define checkImageWidth 64
117 #define checkImageHeight 64
122 GLfloat ant_position;
123 GLXContext *glx_context;
125 trackball_state *trackball;
131 double antdirection[ANTCOUNT];
132 double antposition[ANTCOUNT][3];
135 double antvelocity[ANTCOUNT];
136 double antsize[ANTCOUNT];
137 int bposition[ANTCOUNT][2];
138 int board[BOARDCOUNT][10][10];
141 double antpath[ANTCOUNT][PARTS][2];
142 int antpathlength[ANTCOUNT];
144 GLubyte checkers[checkImageWidth][checkImageHeight][3];
146 GLuint checktexture, brushedtexture;
150 double first_ant_step;
162 static antmazestruct *antmaze = (antmazestruct *) NULL;
165 static const GLfloat MaterialRed[] = {0.6, 0.0, 0.0, 1.0};
166 /*static const GLfloat MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};*/
167 static const GLfloat MaterialGray8[] = {0.8, 0.8, 0.8, 1.0};
168 static const GLfloat MaterialGray35[] = {0.30, 0.30, 0.30, 1.0};
169 static const GLfloat MaterialGray4[] = {0.40, 0.40, 0.40, 1.0};
170 static const GLfloat MaterialOrange[] = {1.0, 0.69, 0.00, 1.0};
171 static const GLfloat MaterialGreen[] = {0.1, 0.4, 0.2, 1.0};
173 /* lighting variables */
174 static const GLfloat front_shininess[] = {60.0};
175 static const GLfloat front_specular[] = {0.8, 0.8, 0.8, 1.0};
176 static const GLfloat ambient[] = {0.1, 0.1, 0.1, 1.0};
177 /*static const GLfloat ambient2[] = {0.0, 0.0, 0.0, 0.0};*/
178 static const GLfloat diffuse[] = {0.8, 0.8, 0.8, 1.0};
179 static const GLfloat position0[] = {1.0, 5.0, 1.0, 1.0};
180 static const GLfloat position1[] = {-1.0, -5.0, 1.0, 1.0};
181 /*static const GLfloat lmodel_ambient[] = {0.8, 0.8, 0.8, 1.0};*/
182 /*static const GLfloat lmodel_twoside[] = {GL_TRUE};*/
183 /*static const GLfloat spotlight_ambient[] = { 0.0, 0.0, 0.0, 1.0 };*/
184 /*static const GLfloat spotlight_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };*/
189 static Bool mySphere(float radius)
192 GLUquadricObj *quadObj;
194 if((quadObj = gluNewQuadric()) == 0)
196 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
197 gluSphere(quadObj, radius, 16, 16);
198 gluDeleteQuadric(quadObj);
201 glScalef (radius, radius, radius);
202 glRotatef (90, 1, 0, 0);
203 unit_sphere (16, 16, False);
210 /* silhouette sphere */
211 static Bool mySphere2(float radius)
213 GLUquadricObj *quadObj;
215 if((quadObj = gluNewQuadric()) == 0)
217 gluQuadricDrawStyle(quadObj, (GLenum) GLU_SILHOUETTE);
218 gluSphere(quadObj, radius, 16, 8);
219 gluDeleteQuadric(quadObj);
225 /* textured sphere */
226 static Bool mySphereTex(float radius)
229 GLUquadricObj *quadObj;
231 if((quadObj = gluNewQuadric()) == 0)
233 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
234 gluQuadricTexture(quadObj, GL_TRUE);
235 gluQuadricNormals(quadObj, GLU_SMOOTH);
236 gluSphere(quadObj, radius, 32, 16);
237 gluDeleteQuadric(quadObj);
240 glScalef (radius, radius, radius);
241 glRotatef (90, 1, 0, 0);
242 unit_sphere (32, 16, False);
250 static Bool myCone(float radius)
253 GLUquadricObj *quadObj;
255 if ((quadObj = gluNewQuadric()) == 0)
257 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
258 gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
259 gluDeleteQuadric(quadObj);
264 8, True, True, False);
270 static Bool myCone2(float radius) { return True; }
273 static const float *antmaterial[ANTCOUNT] =
274 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange, MaterialGreen};
276 static const float *materials[MATERIALS] =
277 {MaterialRed, MaterialGray35, MaterialGray4, MaterialOrange};
280 static void makeCheckImage(antmazestruct *mp)
284 for (i = 0; i < checkImageWidth; i++) {
285 for (j = 0; j < checkImageHeight; j++) {
286 if(((((i&0x8)==0)^((j&0x8)))==0)) {
287 int c = 102 + random()%32;
288 mp->checkers[i][j][0] = c;
289 mp->checkers[i][j][1] = c;
290 mp->checkers[i][j][2] = c;
293 int c = 153 + random()%32;
294 mp->checkers[i][j][0] = c;/*153;*/
295 mp->checkers[i][j][1] = c;/*c;*//*0;*/
296 mp->checkers[i][j][2] = c;/*c;*//*0;*/
301 glGenTextures(1, &mp->checktexture);
302 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
304 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
305 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
306 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
307 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
308 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
309 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
310 &mp->checkers[0][0]);
311 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
314 static void makeBrushedImage(antmazestruct *mp)
318 for(i = 0; i < checkImageWidth; ++i)
319 for(j = 0; j < checkImageHeight; ++j) {
321 c = 102+102*fabs(sin(2.0*i / Pi)*sin(2.0*j/Pi)) + random()%51;
323 /* c = (i+j)%8==0 || (i+j+5)%8==0 ? 153 : 102; */
325 mp->checkers[i][j][0] = c;
326 mp->checkers[i][j][1] = c;
327 mp->checkers[i][j][2] = c;
330 /* for (i = 0; i < checkImageWidth; i++) { */
331 /* for (j = 0; j < checkImageHeight; j++) { */
332 /* int c = 102 + pow((random()%1000)/1000.0, 4)*103; */
333 /* checkers[i][j][0] = c; */
334 /* checkers[i][j][1] = c; */
335 /* checkers[i][j][2] = c; */
340 /* for (i = 0; i < checkImageWidth; i++) { */
341 /* for (j = 0; j < checkImageHeight; j++) { */
342 /* int a = checkers[(i+checkImageWidth+1)%checkImageWidth][j][0] + */
343 /* 4*checkers[i][j][0] + checkers[(i+1)%checkImageWidth][j][0]; */
345 /* checkers[i][j][0] = a; */
346 /* checkers[i][j][1] = a; */
347 /* checkers[i][j][2] = a; */
351 glGenTextures(1, &mp->brushedtexture);
352 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
354 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
355 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
356 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
357 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
358 glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
359 checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
360 &mp->checkers[0][0]);
361 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
365 static void draw_wall(ModeInfo *mi, double x1, double z1, double x2, double z2)
367 float x = fabs(x2 - x1)/2.0;
372 glNormal3f(0.0, 1.0, 0.0);
373 glTexCoord2f(0.0, 0.0);
374 glVertex3f(x1, 1.0, z1+0.25);
375 glTexCoord2f(x, 0.0);
376 glVertex3f(x2, 1.0, z2+0.25);
377 glTexCoord2f(x, 0.25);
378 glVertex3f(x2, 1.0, z2-0.25);
379 glTexCoord2f(0.0, 0.25);
380 glVertex3f(x1, 1.0, z1-0.25);
384 glNormal3f(0.0, 0.0, 1.0);
385 glTexCoord2f(0.0, 0.0);
386 glVertex3f(x1, 0.0, z1+0.25);
387 glTexCoord2f(x, 0.0);
388 glVertex3f(x2, 0.0, z2+0.25);
389 glTexCoord2f(x, 0.5);
390 glVertex3f(x2, 1.0, z2+0.25);
391 glTexCoord2f(0.0, 0.5);
392 glVertex3f(x1, 1.0, z1+0.25);
395 glNormal3f(0.0, 0.0, -1.0);
396 glTexCoord2f(0.0, 0.0);
397 glVertex3f(x1, 0.0, z1-0.25);
398 glTexCoord2f(x, 0.0);
399 glVertex3f(x2, 0.0, z2-0.25);
400 glTexCoord2f(x, 0.5);
401 glVertex3f(x2, 1.0, z2-0.25);
402 glTexCoord2f(0.0, 0.5);
403 glVertex3f(x1, 1.0, z1-0.25);
407 glNormal3f(1.0, 0.0, 0.0);
408 glTexCoord2f(0.0, 0.0);
409 glVertex3f(x2, 0.0, z2+0.25);
410 glTexCoord2f(0.25, 0.0);
411 glVertex3f(x2, 0.0, z2-0.25);
412 glTexCoord2f(0.25, 0.5);
413 glVertex3f(x2, 1.0, z2-0.25);
414 glTexCoord2f(0.0, 0.5);
415 glVertex3f(x2, 1.0, z2+0.25);
418 glNormal3f(-1.0, 0.0, 0.0);
419 glTexCoord2f(0.0, 0.0);
420 glVertex3f(x1, 0.0, z1-0.25);
421 glTexCoord2f(0.25, 0.0);
422 glVertex3f(x1, 0.0, z1+0.25);
423 glTexCoord2f(0.25, 0.5);
424 glVertex3f(x1, 1.0, z1+0.25);
425 glTexCoord2f(0.0, 0.5);
426 glVertex3f(x1, 1.0, z1-0.25);
433 static void draw_board(ModeInfo *mi, antmazestruct *mp)
440 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
444 for(i = 0; i < BOARDSIZE; ++i)
445 for(j = 0; j < BOARDSIZE; ++j) {
446 if(mp->board[mp->currentboard][j][i]) {
448 /* /\* draw top *\/ */
449 /* glNormal3f(0.0, 1.0, 0.0); */
450 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
451 /* glVertex3f(i-0.5, h, j+0.5); */
452 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
453 /* glVertex3f(i+0.5, h, j+0.5); */
454 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
455 /* glVertex3f(i+0.5, h, j-0.5); */
456 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
457 /* glVertex3f(i-0.5, h, j-0.5); */
460 glNormal3f(0.0, 1.0, 0.0);
461 glTexCoord2f(0.0 + stf, 0.0 + stf);
462 glVertex3f(i-0.5, h, j+0.5);
463 glTexCoord2f(1.0 + stf, 0.0 + stf);
464 glVertex3f(i+0.5, h, j+0.5);
465 glTexCoord2f(1.0 + stf, 1.0 + stf);
466 glVertex3f(i+0.5, h, j-0.5);
467 glTexCoord2f(0.0 + stf, 1.0 + stf);
468 glVertex3f(i-0.5, h, j-0.5);
471 /* draw south face */
472 if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
473 glNormal3f(0.0, 0.0, 1.0);
474 glTexCoord2f(0.0 + stf, 0.0 + stf);
475 glVertex3f(i-0.5, 0.0, j+0.5);
476 glTexCoord2f(1.0 + stf, 0.0 + stf);
477 glVertex3f(i+0.5, 0.0, j+0.5);
478 glTexCoord2f(1.0 + stf, h + stf);
479 glVertex3f(i+0.5, h, j+0.5);
480 glTexCoord2f(0.0 + stf, h + stf);
481 glVertex3f(i-0.5, h, j+0.5);
485 /* draw north face */
486 if(j == 0 || !mp->board[mp->currentboard][j-1][i]) {
487 glNormal3f(0.0, 0.0, -1.0);
488 glTexCoord2f(0.0 + stf, 0.0 + stf);
489 glVertex3f(i+0.5, 0.0, j-0.5);
490 glTexCoord2f(1.0 + stf, 0.0 + stf);
491 glVertex3f(i-0.5, 0.0, j-0.5);
492 glTexCoord2f(1.0 + stf, h + stf);
493 glVertex3f(i-0.5, h, j-0.5);
494 glTexCoord2f(0.0 + stf, h + stf);
495 glVertex3f(i+0.5, h, j-0.5);
500 if(i == 9 || !mp->board[mp->currentboard][j][i+1]) {
501 glNormal3f(1.0, 0.0, 0.0);
502 glTexCoord2f(0.0 + stf, 0.0 + stf);
503 glVertex3f(i+0.5, 0.0, j+0.5);
504 glTexCoord2f(1.0 + stf, 0.0 + stf);
505 glVertex3f(i+0.5, 0.0, j-0.5);
506 glTexCoord2f(1.0 + stf, h + stf);
507 glVertex3f(i+0.5, h, j-0.5);
508 glTexCoord2f(0.0 + stf, h + stf);
509 glVertex3f(i+0.5, h, j+0.5);
514 if(i == 0 || !mp->board[mp->currentboard][j][i-1]) {
515 glNormal3f(-1.0, 0.0, 0.0);
516 glTexCoord2f(0.0 + stf, 0.0 + stf);
517 glVertex3f(i-0.5, 0.0, j-0.5);
518 glTexCoord2f(1.0 + stf, 0.0 + stf);
519 glVertex3f(i-0.5, 0.0, j+0.5);
520 glTexCoord2f(1.0 + stf, h + stf);
521 glVertex3f(i-0.5, h, j+0.5);
522 glTexCoord2f(0.0 + stf, h + stf);
523 glVertex3f(i-0.5, h, j-0.5);
529 glNormal3f(0.0, 1.0, 0.0);
530 glTexCoord2f(0.0, 0.0);
531 glVertex3f(i-0.5, 0.0, j+0.5);
532 glTexCoord2f(tx, 0.0);
533 glVertex3f(i+0.5, 0.0, j+0.5);
534 glTexCoord2f(tx, tx);
535 glVertex3f(i+0.5, 0.0, j-0.5);
536 glTexCoord2f(0.0, tx);
537 glVertex3f(i-0.5, 0.0, j-0.5);
543 /* /\* draw elevator *\/ */
544 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
546 /* glBegin(GL_QUADS); */
548 /* glNormal3f(0.0, 1.0, 0.0); */
550 /* if(pastfirst) { */
552 /* glTexCoord2f(0.0, 0.0); */
553 /* glVertex3f(0.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
554 /* glTexCoord2f(1.0, 0.0); */
555 /* glVertex3f(1.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
556 /* glTexCoord2f(1.0, 1.5); */
557 /* glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
558 /* glTexCoord2f(0.0, 1.5); */
559 /* glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
560 /* mi->polygon_count++; */
563 /* /\* destination *\/ */
564 /* glTexCoord2f(0.0, 0.0); */
565 /* glVertex3f(BOARDSIZE - 2.5, elevator, -2.0 - 0.2); */
566 /* glTexCoord2f(1.0, 0.0); */
567 /* glVertex3f(BOARDSIZE - 1.5, elevator, -2.0 - 0.2); */
568 /* glTexCoord2f(1.0, 1.5); */
569 /* glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
570 /* glTexCoord2f(0.0, 1.5); */
571 /* glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
572 /* mi->polygon_count++; */
576 /* for(i = 0; i < BOARDSIZE; ++i) */
577 /* for(j = 0; j < BOARDSIZE; ++j) { */
578 /* if(board[j][i]) { */
580 /* /\* draw brushed boxtop *\/ */
581 /* glNormal3f(0.0, 1.0, 0.0); */
582 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
583 /* glVertex3f(i-0.5 + stf, h+0.001, j+0.5 - stf); */
584 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
585 /* glVertex3f(i+0.5 - stf, h+0.001, j+0.5 - stf); */
586 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
587 /* glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
588 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
589 /* glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
590 /* mi->polygon_count++; */
597 static void build_board(antmazestruct *mp, int b)
601 for(i = 0; i < BOARDSIZE; ++i)
602 for(j = 0; j < BOARDSIZE; ++j)
603 mp->board[b][i][j] = 1;
605 /* for(i = 0; i < BOARDSIZE; ++i) { */
606 /* board[0][i] = 1; */
607 /* board[i][0] = 1; */
608 /* board[BOARDSIZE-1][BOARDSIZE-i] = 1; */
609 /* board[BOARDSIZE-i][BOARDSIZE-1] = 1; */
612 /* board[0][BOARDSIZE-2] = 0; */
613 /* board[BOARDSIZE-1][1] = 0; */
616 mp->board[b][BOARDSIZE-1][1] = 0;
617 mp->board[b][0][BOARDSIZE-2] = 0;
619 /* build the ant paths */
620 if(mp->currentboard == b) {
621 for(i = 0; i < ANTCOUNT; ++i) {
622 int sx = BOARDSIZE-2;
626 mp->board[b][sx][sy] = 0;
627 mp->antpath[i][j][0] = sy - 5.0;
628 mp->antpath[i][j][1] = sx - 5.0;
633 else if(sy < BOARDSIZE-2)
649 mp->antpath[i][j][0] = BOARDSIZE-7.0;
650 mp->antpath[i][j][1] = -7.0;
651 mp->antpathlength[i] = j;
655 /* for(i = 0; i < 20; ++i) { */
656 /* int x = 1 + random()%(BOARDSIZE-2); */
657 /* int y = 1 + random()%(BOARDSIZE-2); */
658 /* board[x][y] = 1; */
662 /* compute nearness */
663 static int near(double a[2], double b[2])
665 return fabs(a[0] - b[0]) < 0.5 && fabs(a[1] - b[1]) < 0.5;
668 static double sign(double d)
670 return d < 0.0 ? -1.0 : 1.0;
673 static double min(double a, double b)
675 return a < b ? a : b;
678 /* draw method for ant */
679 static Bool draw_ant(ModeInfo *mi, antmazestruct *mp,
680 const float *Material, int mono, int shadow,
681 float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
684 float cos1 = cos(mp->ant_step);
685 float cos2 = cos(mp->ant_step + 2 * Pi / 3);
686 float cos3 = cos(mp->ant_step + 4 * Pi / 3);
687 float sin1 = sin(mp->ant_step);
688 float sin2 = sin(mp->ant_step + 2 * Pi / 3);
689 float sin3 = sin(mp->ant_step + 4 * Pi / 3);
691 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : Material);
693 /* glEnable(GL_CULL_FACE); */
697 if(!((*sphere)(0.18)))
699 glScalef(1, 1 / 1.3, 1);
700 glTranslatef(0.00, 0.30, 0.00);
701 if(!((*sphere)(0.2)))
704 glTranslatef(-0.05, 0.17, 0.05);
705 glRotatef(-90, 1, 0, 0);
706 glRotatef(-25, 0, 1, 0);
709 glTranslatef(0.00, 0.10, 0.00);
712 glRotatef(25, 0, 1, 0);
713 glRotatef(90, 1, 0, 0);
716 glTranslatef(0.15, -0.65, 0.05);
717 if(!((*sphere)(0.25)))
719 glScalef(1, 1 / 1.3, 1);
722 /* glDisable(GL_CULL_FACE); */
724 glDisable(GL_LIGHTING);
728 glColor3fv(mono ? MaterialGray5 : Material);
729 glVertex3f(0.00, 0.30, 0.00);
730 glColor3fv(MaterialGray);
731 glVertex3f(0.40, 0.70, 0.40);
733 glColor3fv(mono ? MaterialGray5 : Material);
734 glVertex3f(0.00, 0.30, 0.00);
735 glColor3fv(MaterialGray);
736 glVertex3f(0.40, 0.70, -0.40);
742 glColor3fv(mono ? MaterialGray6 : MaterialRed);
743 glVertex3f(0.40, 0.70, 0.40);
745 glVertex3f(0.40, 0.70, -0.40);
751 glBegin(GL_LINE_STRIP);
752 glColor3fv(mono ? MaterialGray5 : Material);
753 glVertex3f(0.00, 0.05, 0.18);
754 glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
756 glColor3fv(MaterialGray);
757 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
761 /* LEFT-CENTER ARM */
762 glBegin(GL_LINE_STRIP);
763 glColor3fv(mono ? MaterialGray5 : Material);
764 glVertex3f(0.00, 0.00, 0.18);
765 glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
767 glColor3fv(MaterialGray);
768 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
773 glBegin(GL_LINE_STRIP);
774 glColor3fv(mono ? MaterialGray5 : Material);
775 glVertex3f(0.00, -0.05, 0.18);
776 glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
778 glColor3fv(MaterialGray);
779 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
783 /* RIGHT-FRONT ARM */
784 glBegin(GL_LINE_STRIP);
785 glColor3fv(mono ? MaterialGray5 : Material);
786 glVertex3f(0.00, 0.05, -0.18);
787 glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
789 glColor3fv(MaterialGray);
790 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
794 /* RIGHT-CENTER ARM */
795 glBegin(GL_LINE_STRIP);
796 glColor3fv(mono ? MaterialGray5 : Material);
797 glVertex3f(0.00, 0.00, -0.18);
798 glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
800 glColor3fv(MaterialGray);
801 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
806 glBegin(GL_LINE_STRIP);
807 glColor3fv(mono ? MaterialGray5 : Material);
808 glVertex3f(0.00, -0.05, -0.18);
809 glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
811 glColor3fv(MaterialGray);
812 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
818 glColor3fv(mono ? MaterialGray8 : MaterialGray35);
819 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
820 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
821 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
822 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
823 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
824 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
825 mi->polygon_count += 6;
829 glEnable(GL_LIGHTING);
834 static Bool draw_antmaze_strip(ModeInfo * mi)
836 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
838 int mono = MI_IS_MONO(mi);
840 /* glMatrixMode(GL_MODELVIEW); */
841 /* glLoadIdentity(); */
842 /* glPushMatrix(); */
844 glEnable(GL_LIGHTING);
845 /* glDisable(GL_BLEND); */
850 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
851 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
852 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
853 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
856 if(mp->elevator < 1.0) {
857 glEnable(GL_TEXTURE_2D);
858 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
859 glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
861 glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
862 glDisable(GL_TEXTURE_2D);
867 glTranslatef(0.0, -0.1, 0.0);
869 for(i = 0; i < ANTCOUNT; ++i) {
871 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
872 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
874 if(!mp->anton[i]) { continue; }
876 /* determine location, move to goal */
878 glTranslatef(0.0, 0.01, 0.0);
879 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
880 /* glScalef(1.0, 0.01, 1.0); */
881 glScalef(0.6, 0.01, 0.6);
882 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
883 glRotatef(90.0, 0.0, 0.0, 1.0);
884 glDisable(GL_LIGHTING);
886 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
887 glColor4fv(MaterialGrayB);
889 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
891 /* slow down first ant */
892 if(i == 0 && mp->part[i] == mp->antpathlength[i])
893 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
895 draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
900 glEnable(GL_LIGHTING);
903 /* glTranslatef(0.0, 0.18, 0.0); */
904 glTranslatef(0.0, 0.12, 0.0);
905 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
906 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
907 glRotatef(90.0, 0.0, 0.0, 1.0);
908 glScalef(0.6, 0.6, 0.6);
910 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
912 /* glEnable(GL_TEXTURE_2D); */
913 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
915 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed); */
917 /* slow down first ant */
918 if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
919 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
920 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
921 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
924 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
925 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
927 glEnable(GL_TEXTURE_2D);
928 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
929 draw_ant(mi, mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
930 glDisable(GL_TEXTURE_2D);
934 /* draw_ant(mi, antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
935 /* glDisable(GL_TEXTURE_2D); */
941 /* /\* now draw overlay *\/ */
942 /* glDisable(GL_LIGHTING); */
943 /* glDisable(GL_BLEND); */
945 /* /\* go to ortho mode *\/ */
946 /* glMatrixMode(GL_PROJECTION); */
947 /* glPushMatrix(); */
948 /* glLoadIdentity(); */
949 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
951 /* /\* translate to corner *\/ */
952 /* glTranslatef(4.0-1.2, 3.0-1.2, 0.0); */
954 /* glDisable(GL_LIGHTING); */
955 /* glEnable(GL_BLEND); */
957 /* /\* draw the 2d board *\/ */
958 /* glBegin(GL_QUADS); */
961 /* double sz = 1.0; */
962 /* for(i = 0; i < BOARDSIZE; ++i) */
963 /* for(j = 0; j < BOARDSIZE; ++j) { */
964 /* int par = board[i][j]; */
965 /* glColor4f(par ? 0.4 : 0.6, */
966 /* par ? 0.4 : 0.6, */
967 /* par ? 0.4 : 0.6, */
969 /* glNormal3f(0.0, 0.0, 1.0); */
970 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
971 /* glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
972 /* glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
973 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
974 /* mi->polygon_count++; */
982 /* but the step size is the same! */
983 mp->ant_step += 0.18;
984 /* if(ant_step > 2*Pi) { */
985 /* ant_step = 0.0; */
988 if(mp->ant_step > 5*Pi)
991 mp->ant_position += 1;
994 #undef AntmazeDivisions
995 #undef AntmazeTransversals
997 ENTRYPOINT void reshape_antmaze(ModeInfo * mi, int width, int height)
999 double h = (GLfloat) height / (GLfloat) width;
1000 int size = (width / 512) + 1;
1001 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1003 glViewport(0, 0, mp->WindW = (GLint) width, mp->WindH = (GLint) height);
1004 glMatrixMode(GL_PROJECTION);
1007 gluPerspective(45, 1/h, 1, 25.0);
1009 glMatrixMode(GL_MODELVIEW);
1010 /* glLineWidth(3.0); */
1015 static void update_ants(antmazestruct *mp)
1019 df[0] = df[1] = df[2] = 0.8*mp->fadeout;
1023 if(mp->fadeoutspeed < -0.00001) {
1025 if(mp->fadeout <= 0.0) {
1026 /* switch boards: rebuild old board, increment current */
1027 mp->currentboard = (mp->currentboard+1)%BOARDCOUNT;
1028 build_board(mp, mp->currentboard);
1029 mp->fadeoutspeed = 0.02;
1032 mp->fadeout += mp->fadeoutspeed;
1034 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
1035 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1039 if(mp->fadeoutspeed > 0.0001) {
1040 mp->fadeout += mp->fadeoutspeed;
1041 if(mp->fadeout >= 1.0) {
1043 mp->fadeoutspeed = 0.0;
1044 mp->entroducing = 12;
1046 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
1047 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
1050 for(i = 0; i < ANTCOUNT; ++i) {
1052 if(!mp->anton[i] && mp->elevator < 1.0) {
1055 if(mp->entroducing > 0 && mp->introduced <= 0 && random()%100 == 0) {
1058 mp->antsize[i] = 0.0;
1059 mp->antposition[i][0] = -4.0;
1060 mp->antposition[i][1] = 5.0;
1061 mp->antdirection[i] = PI/2.0;
1062 mp->bposition[i][0] = 0;
1063 mp->bposition[i][1] = 8;
1064 mp->introduced = 300;
1071 if(mp->part[i] == 0 && mp->antsize[i] < 1.0) {
1072 mp->antsize[i] += 0.02;
1076 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] > 0.0) {
1077 mp->antsize[i] -= 0.02;
1078 if(mp->antvelocity[i] > 0.0) {
1079 mp->antvelocity[i] -= 0.02;
1081 else { mp->antvelocity[i] = 0.0; }
1086 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] <= 0.0) {
1087 mp->antvelocity[i] = 0.02;
1090 antmaterial[i] = materials[random()%MATERIALS];
1093 mp->antdirection[i] = PI/2.0;
1094 mp->bposition[i][0] = 0;
1095 mp->bposition[i][1] = 8;
1098 mp->antsize[i] = 0.0;
1102 mp->antposition[i][0] = -4.0;
1103 mp->antposition[i][1] = 5.0;
1105 /* /\* reset camera *\/ */
1106 /* if(i == focus) { */
1108 /* ant_step = 0.0; */
1111 /* check for the end */
1112 if(mp->entroducing <= 0) {
1114 for(z = 0; z < ANTCOUNT; ++z) {
1115 if(mp->anton[z]) { ao = 1; break; }
1119 mp->fadeoutspeed = -0.02;
1125 /* near goal, bend path towards next step */
1126 if(near(mp->antposition[i], mp->antpath[i][mp->part[i]])) {
1130 /* /\* special first ant *\/ */
1131 /* if(i == 0 && part[i] > antpathlength[i]) { */
1133 /* first_ant_step = ant_step; */
1135 /* antvelocity[i] = 0.0; */
1136 /* /\* antposition[i][2] += 0.025; *\/ */
1137 /* elevator += 0.025; */
1139 /* /\* set light *\/ */
1140 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
1141 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
1142 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
1143 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
1145 /* /\* draw next board *\/ */
1146 /* if(elevator > 1.0) { */
1148 /* if(makenew == 1) { */
1151 /* /\* switch boards: rebuild old board, increment current *\/ */
1152 /* currentboard = (currentboard+1)%BOARDCOUNT; */
1153 /* build_board(currentboard); */
1155 /* for(re = 1; re < ANTCOUNT; ++re) { */
1156 /* anton[re] = 0; */
1157 /* antmaterial[re] = materials[random()%MATERIALS]; */
1164 /* /\* draw the other board *\/ */
1165 /* glEnable(GL_TEXTURE_2D); */
1166 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6); */
1168 /* glPushMatrix(); */
1169 /* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */
1170 /* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
1171 /* draw_board(mi, mp); */
1172 /* glPopMatrix(); */
1173 /* glDisable(GL_TEXTURE_2D); */
1176 /* if(elevator > 2.0) { */
1177 /* antposition[i][0] = -4.0;/\*-= -(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0);*\//\*= -4.0;*\/ */
1178 /* antposition[i][1] = 5.5;/\*-(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0);*\/ */
1179 /* /\* antposition[i][2] = 0.15; *\/ */
1180 /* antdirection[i] = PI/2.0; */
1181 /* bposition[i][0] = 0; */
1182 /* bposition[i][1] = 8; */
1184 /* antvelocity[i] = 0.02; */
1186 /* antmaterial[i] = MaterialRed; */
1190 /* elevator = 0.0; */
1191 /* introduced = 200; */
1200 /* move toward goal, correct ant direction if required */
1204 double dx = mp->antpath[i][mp->part[i]][0] - mp->antposition[i][0];
1205 double dz = - mp->antpath[i][mp->part[i]][1] + mp->antposition[i][1];
1206 double theta, ideal;
1209 theta = atan(dz/dx);
1211 theta = dx > EPSILON ? 0.0 : PI;
1213 ideal = theta - mp->antdirection[i];
1217 /* compute correction */
1219 double dt = sign(ideal) * min(fabs(ideal), PI/90.0);
1220 mp->antdirection[i] += dt;
1221 if(mp->antdirection[i] > 2.0*PI)
1222 mp->antdirection[i] = 0.0;
1226 mp->antposition[i][0] += mp->antvelocity[i] * cos(mp->antdirection[i]);
1227 mp->antposition[i][1] += mp->antvelocity[i] * sin(-mp->antdirection[i]);
1231 static void pinit(antmazestruct *mp)
1234 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
1235 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1236 glLightfv(GL_LIGHT0, GL_POSITION, position0);
1237 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
1238 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1239 glLightfv(GL_LIGHT1, GL_POSITION, position1);
1241 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
1242 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001);
1243 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
1245 glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05);
1246 glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001);
1247 glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
1250 /* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
1251 /* glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */
1252 glEnable(GL_LIGHTING);
1253 glEnable(GL_LIGHT0);
1254 glEnable(GL_LIGHT1);
1255 glEnable(GL_NORMALIZE);
1256 glFrontFace(GL_CCW);
1257 glCullFace(GL_BACK);
1260 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
1261 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
1263 glShadeModel(GL_SMOOTH);
1264 glEnable(GL_DEPTH_TEST);
1265 glDisable(GL_TEXTURE_2D);
1267 /* setup textures */
1269 makeBrushedImage(mp);
1274 /* makeCheckImage(); */
1275 /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */
1276 /* glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, */
1277 /* checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */
1278 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */
1279 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */
1281 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
1282 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
1283 /* glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */
1284 glEnable(GL_TEXTURE_2D);
1286 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */
1287 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
1290 ENTRYPOINT void release_antmaze(ModeInfo * mi)
1293 free((void *) antmaze);
1294 antmaze = (antmazestruct *) NULL;
1299 #define MAX_MAGNIFICATION 10
1300 #define max(a, b) a < b ? b : a
1301 #define min(a, b) a < b ? a : b
1303 ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
1305 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1307 switch(event->xany.type) {
1310 switch(event->xbutton.button) {
1313 mp->button_down_p = True;
1314 gltrackball_start(mp->trackball,
1315 event->xbutton.x, event->xbutton.y,
1316 MI_WIDTH (mi), MI_HEIGHT (mi));
1320 mp->focus = (mp->focus + 1) % ANTCOUNT;
1324 mp->mag = max(mp->mag-1, 1);
1328 mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
1336 switch(event->xbutton.button) {
1338 mp->button_down_p = False;
1345 if(mp->button_down_p)
1346 gltrackball_track(mp->trackball,
1347 event->xmotion.x, event->xmotion.y,
1348 MI_WIDTH (mi), MI_HEIGHT (mi));
1358 ENTRYPOINT void init_antmaze(ModeInfo * mi)
1360 double rot_speed = 0.3;
1365 if (antmaze == NULL) {
1366 if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
1367 sizeof (antmazestruct))) == NULL)
1370 mp = &antmaze[MI_SCREEN(mi)];
1371 mp->step = NRAND(90);
1372 mp->ant_position = NRAND(90);
1375 mp->antdirection[0] = PI/2.0;
1376 mp->antdirection[1] = PI/2.0;
1377 mp->antdirection[2] = 0;
1378 mp->antdirection[3] = PI/2.0;
1379 mp->antdirection[4] = PI/2.0;
1381 mp->antposition[0][0] = -4.0;
1382 mp->antposition[0][1] = 5.0;
1383 mp->antposition[0][1] = 0.15;
1385 mp->antposition[1][0] = -4.0;
1386 mp->antposition[1][1] = 3.0;
1387 mp->antposition[1][1] = 0.15;
1389 mp->antposition[2][0] = -1.0;
1390 mp->antposition[2][1] = -2.0;
1391 mp->antposition[2][1] = 0.15;
1393 mp->antposition[3][0] = -3.9;
1394 mp->antposition[3][1] = 6.0;
1395 mp->antposition[3][1] = 0.15;
1397 mp->antposition[4][0] = 2.0;
1398 mp->antposition[4][1] = -2.0;
1399 mp->antposition[4][1] = 0.15;
1403 for (i = 0; i < ANTCOUNT; i++) {
1404 mp->antvelocity[i] = 0.02;
1405 mp->antsize[i] = 1.0;
1409 mp->bposition[0][0] = 0;
1410 mp->bposition[0][1] = 8;
1412 mp->bposition[1][0] = 9;
1413 mp->bposition[1][1] = 1;
1415 mp->bposition[2][0] = 1;
1416 mp->bposition[2][1] = 1;
1418 mp->bposition[3][0] = 4;
1419 mp->bposition[3][1] = 8;
1421 mp->bposition[4][0] = 2;
1422 mp->bposition[4][1] = 1;
1431 mp->entroducing = 12;
1435 mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
1436 mp->trackball = gltrackball_init ();
1438 if ((mp->glx_context = init_GL(mi)) != NULL) {
1439 reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1440 glDrawBuffer(GL_BACK);
1448 device_rotate(ModeInfo *mi)
1450 GLfloat rot = current_device_rotation();
1451 glRotatef(rot, 0, 0, 1);
1452 if ((rot > 45 && rot < 135) ||
1453 (rot < -45 && rot > -135))
1455 GLfloat s = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1456 glScalef (1/s, s, 1);
1461 ENTRYPOINT void draw_antmaze(ModeInfo * mi)
1463 double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1467 Display *display = MI_DISPLAY(mi);
1468 Window window = MI_WINDOW(mi);
1472 mp = &antmaze[MI_SCREEN(mi)];
1474 MI_IS_DRAWN(mi) = True;
1476 if(!mp->glx_context)
1479 mi->polygon_count = 0;
1480 glXMakeCurrent(display, window, *(mp->glx_context));
1482 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1486 /* h = ((GLfloat) MI_HEIGHT(mi)/2) / (3*(GLfloat)MI_WIDTH(mi)/4); */
1487 glViewport(MI_WIDTH(mi)/32, MI_HEIGHT(mi)/8, (9*MI_WIDTH(mi))/16, 3*MI_HEIGHT(mi)/4);
1488 glMatrixMode(GL_PROJECTION);
1491 /* h = (3*MI_HEIGHT(mi)/4) / (3*MI_WIDTH(mi)/4); */
1492 gluPerspective(45, 1/h, 1, 25.0);
1494 glMatrixMode(GL_MODELVIEW);
1500 /* follow focused ant */
1501 glTranslatef(0.0, 0.0, -mp->mag - 5.0);
1502 glRotatef(20.0+5.0*sin(mp->ant_step/40.0), 1.0, 0.0, 0.0);
1503 /* glTranslatef(0.0, */
1504 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0)), */
1505 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0))); */
1507 gltrackball_rotate(mp->trackball);
1509 glRotatef(mp->ant_step*0.6, 0.0, 1.0, 0.0);
1511 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1513 /* glTranslatef(-antposition[0][0]-0.5, 0.0, -antposition[focus][1]); */
1517 if(!draw_antmaze_strip(mi)) {
1518 release_antmaze(mi);
1525 h = (GLfloat) (3*MI_HEIGHT(mi)/8) / (GLfloat) (MI_WIDTH(mi)/2);
1529 glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
1530 glMatrixMode(GL_PROJECTION);
1533 gluPerspective(45, 1/h, 1, 25.0);
1534 glMatrixMode(GL_MODELVIEW);
1537 glTranslatef(0.0, 0.0, -16.0);
1538 glRotatef(60.0, 1.0, 0.0, 0.0);
1539 glRotatef(-15.0 + mp->ant_step/10.0, 0.0, 1.0, 0.0);
1540 gltrackball_rotate(mp->trackball);
1543 if(!draw_antmaze_strip(mi)) {
1544 release_antmaze(mi);
1550 /* draw ant display */
1552 glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
1553 glMatrixMode(GL_PROJECTION);
1556 gluPerspective(45, 1/h, 1, 25.0);
1557 glMatrixMode(GL_MODELVIEW);
1560 glTranslatef(0.0, 0.0, -1.6);
1561 glRotatef(30.0, 1.0, 0.0, 0.0);
1562 glRotatef(mp->ant_step, 0.0, 1.0, 0.0);
1563 glRotatef(90.0, 0.0, 0.0, 1.0);
1565 /* /\* draw ant shadow *\/ */
1566 /* glPushMatrix(); */
1567 /* glScalef(1.0, 0.01, 1.0); */
1568 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1569 /* glRotatef(90.0, 0.0, 1.0, 0.0); */
1570 /* glDisable(GL_LIGHTING); */
1571 /* glColor4fv(MaterialGray6); */
1573 /* /\* slow down first ant *\/ */
1574 /* draw_ant(MaterialGrayB, 0, 1, first_ant_step, mySphere, myCone); */
1575 /* glPopMatrix(); */
1578 glEnable(GL_TEXTURE_2D);
1579 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1580 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1581 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
1582 draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
1583 glDisable(GL_TEXTURE_2D);
1587 /* /\* draw overlay *\/ */
1588 /* glPushMatrix(); */
1590 /* /\* go to ortho mode *\/ */
1591 /* glViewport(MI_WIDTH(mi)/2, MI_HEIGHT(mi)/8, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); */
1593 /* glMatrixMode(GL_PROJECTION); */
1594 /* glLoadIdentity(); */
1596 /* glPushMatrix (); */
1597 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
1599 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); */
1600 /* glColor4fv(MaterialGrayB); */
1602 /* glDisable(GL_LIGHTING); */
1603 /* glEnable(GL_BLEND); */
1605 /* glBegin(GL_QUADS); */
1606 /* glNormal3f(0.0, 0.0, 1.0); */
1607 /* glVertex3f(4.0, 3.0, 0.0); */
1608 /* glVertex3f(2.0, 3.0, 0.0); */
1609 /* glVertex3f(2.0, -3.0, 0.0); */
1610 /* glVertex3f(4.0, -3.0, 0.0); */
1611 /* mi->polygon_count++; */
1614 /* glEnable(GL_LIGHTING); */
1615 /* glDisable(GL_BLEND); */
1617 /* glPopMatrix(); */
1618 /* glPopMatrix(); */
1620 if (MI_IS_FPS(mi)) {
1621 glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
1626 glXSwapBuffers(display, window);
1634 ENTRYPOINT void change_antmaze(ModeInfo * mi)
1636 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1638 if (!mp->glx_context)
1641 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context));
1644 #endif /* !STANDALONE */
1646 XSCREENSAVER_MODULE ("AntMaze", antmaze)