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(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);
347 glNormal3f(0.0, 0.0, 1.0);
348 glTexCoord2f(0.0, 0.0);
349 glVertex3f(x1, 0.0, z1+0.25);
350 glTexCoord2f(x, 0.0);
351 glVertex3f(x2, 0.0, z2+0.25);
352 glTexCoord2f(x, 0.5);
353 glVertex3f(x2, 1.0, z2+0.25);
354 glTexCoord2f(0.0, 0.5);
355 glVertex3f(x1, 1.0, z1+0.25);
357 glNormal3f(0.0, 0.0, -1.0);
358 glTexCoord2f(0.0, 0.0);
359 glVertex3f(x1, 0.0, z1-0.25);
360 glTexCoord2f(x, 0.0);
361 glVertex3f(x2, 0.0, z2-0.25);
362 glTexCoord2f(x, 0.5);
363 glVertex3f(x2, 1.0, z2-0.25);
364 glTexCoord2f(0.0, 0.5);
365 glVertex3f(x1, 1.0, z1-0.25);
368 glNormal3f(1.0, 0.0, 0.0);
369 glTexCoord2f(0.0, 0.0);
370 glVertex3f(x2, 0.0, z2+0.25);
371 glTexCoord2f(0.25, 0.0);
372 glVertex3f(x2, 0.0, z2-0.25);
373 glTexCoord2f(0.25, 0.5);
374 glVertex3f(x2, 1.0, z2-0.25);
375 glTexCoord2f(0.0, 0.5);
376 glVertex3f(x2, 1.0, z2+0.25);
378 glNormal3f(-1.0, 0.0, 0.0);
379 glTexCoord2f(0.0, 0.0);
380 glVertex3f(x1, 0.0, z1-0.25);
381 glTexCoord2f(0.25, 0.0);
382 glVertex3f(x1, 0.0, z1+0.25);
383 glTexCoord2f(0.25, 0.5);
384 glVertex3f(x1, 1.0, z1+0.25);
385 glTexCoord2f(0.0, 0.5);
386 glVertex3f(x1, 1.0, z1-0.25);
392 static void draw_board(antmazestruct *mp)
399 glBindTexture(GL_TEXTURE_2D, mp->checktexture);
403 for(i = 0; i < BOARDSIZE; ++i)
404 for(j = 0; j < BOARDSIZE; ++j) {
405 if(mp->board[mp->currentboard][j][i]) {
407 /* /\* draw top *\/ */
408 /* glNormal3f(0.0, 1.0, 0.0); */
409 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
410 /* glVertex3f(i-0.5, h, j+0.5); */
411 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
412 /* glVertex3f(i+0.5, h, j+0.5); */
413 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
414 /* glVertex3f(i+0.5, h, j-0.5); */
415 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
416 /* glVertex3f(i-0.5, h, j-0.5); */
419 glNormal3f(0.0, 1.0, 0.0);
420 glTexCoord2f(0.0 + stf, 0.0 + stf);
421 glVertex3f(i-0.5, h, j+0.5);
422 glTexCoord2f(1.0 + stf, 0.0 + stf);
423 glVertex3f(i+0.5, h, j+0.5);
424 glTexCoord2f(1.0 + stf, 1.0 + stf);
425 glVertex3f(i+0.5, h, j-0.5);
426 glTexCoord2f(0.0 + stf, 1.0 + stf);
427 glVertex3f(i-0.5, h, j-0.5);
429 /* draw south face */
430 if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
431 glNormal3f(0.0, 0.0, 1.0);
432 glTexCoord2f(0.0 + stf, 0.0 + stf);
433 glVertex3f(i-0.5, 0.0, j+0.5);
434 glTexCoord2f(1.0 + stf, 0.0 + stf);
435 glVertex3f(i+0.5, 0.0, j+0.5);
436 glTexCoord2f(1.0 + stf, h + stf);
437 glVertex3f(i+0.5, h, j+0.5);
438 glTexCoord2f(0.0 + stf, h + stf);
439 glVertex3f(i-0.5, h, j+0.5);
442 /* draw north face */
443 if(j == 0 || !mp->board[mp->currentboard][j-1][i]) {
444 glNormal3f(0.0, 0.0, -1.0);
445 glTexCoord2f(0.0 + stf, 0.0 + stf);
446 glVertex3f(i+0.5, 0.0, j-0.5);
447 glTexCoord2f(1.0 + stf, 0.0 + stf);
448 glVertex3f(i-0.5, 0.0, j-0.5);
449 glTexCoord2f(1.0 + stf, h + stf);
450 glVertex3f(i-0.5, h, j-0.5);
451 glTexCoord2f(0.0 + stf, h + stf);
452 glVertex3f(i+0.5, h, j-0.5);
456 if(i == 9 || !mp->board[mp->currentboard][j][i+1]) {
457 glNormal3f(1.0, 0.0, 0.0);
458 glTexCoord2f(0.0 + stf, 0.0 + stf);
459 glVertex3f(i+0.5, 0.0, j+0.5);
460 glTexCoord2f(1.0 + stf, 0.0 + stf);
461 glVertex3f(i+0.5, 0.0, j-0.5);
462 glTexCoord2f(1.0 + stf, h + stf);
463 glVertex3f(i+0.5, h, j-0.5);
464 glTexCoord2f(0.0 + stf, h + stf);
465 glVertex3f(i+0.5, h, j+0.5);
469 if(i == 0 || !mp->board[mp->currentboard][j][i-1]) {
470 glNormal3f(-1.0, 0.0, 0.0);
471 glTexCoord2f(0.0 + stf, 0.0 + stf);
472 glVertex3f(i-0.5, 0.0, j-0.5);
473 glTexCoord2f(1.0 + stf, 0.0 + stf);
474 glVertex3f(i-0.5, 0.0, j+0.5);
475 glTexCoord2f(1.0 + stf, h + stf);
476 glVertex3f(i-0.5, h, j+0.5);
477 glTexCoord2f(0.0 + stf, h + stf);
478 glVertex3f(i-0.5, h, j-0.5);
483 glNormal3f(0.0, 1.0, 0.0);
484 glTexCoord2f(0.0, 0.0);
485 glVertex3f(i-0.5, 0.0, j+0.5);
486 glTexCoord2f(tx, 0.0);
487 glVertex3f(i+0.5, 0.0, j+0.5);
488 glTexCoord2f(tx, tx);
489 glVertex3f(i+0.5, 0.0, j-0.5);
490 glTexCoord2f(0.0, tx);
491 glVertex3f(i-0.5, 0.0, j-0.5);
496 /* /\* draw elevator *\/ */
497 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
499 /* glBegin(GL_QUADS); */
501 /* glNormal3f(0.0, 1.0, 0.0); */
503 /* if(pastfirst) { */
505 /* glTexCoord2f(0.0, 0.0); */
506 /* glVertex3f(0.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
507 /* glTexCoord2f(1.0, 0.0); */
508 /* glVertex3f(1.5, 0.0, BOARDSIZE - 0.5 + 0.2); */
509 /* glTexCoord2f(1.0, 1.5); */
510 /* glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
511 /* glTexCoord2f(0.0, 1.5); */
512 /* glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
515 /* /\* destination *\/ */
516 /* glTexCoord2f(0.0, 0.0); */
517 /* glVertex3f(BOARDSIZE - 2.5, elevator, -2.0 - 0.2); */
518 /* glTexCoord2f(1.0, 0.0); */
519 /* glVertex3f(BOARDSIZE - 1.5, elevator, -2.0 - 0.2); */
520 /* glTexCoord2f(1.0, 1.5); */
521 /* glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
522 /* glTexCoord2f(0.0, 1.5); */
523 /* glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
527 /* for(i = 0; i < BOARDSIZE; ++i) */
528 /* for(j = 0; j < BOARDSIZE; ++j) { */
529 /* if(board[j][i]) { */
531 /* /\* draw brushed boxtop *\/ */
532 /* glNormal3f(0.0, 1.0, 0.0); */
533 /* glTexCoord2f(0.0 + stf, 0.0 + stf); */
534 /* glVertex3f(i-0.5 + stf, h+0.001, j+0.5 - stf); */
535 /* glTexCoord2f(1.0 + stf, 0.0 + stf); */
536 /* glVertex3f(i+0.5 - stf, h+0.001, j+0.5 - stf); */
537 /* glTexCoord2f(1.0 + stf, 1.0 + stf); */
538 /* glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
539 /* glTexCoord2f(0.0 + stf, 1.0 + stf); */
540 /* glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
547 static void build_board(antmazestruct *mp, int b)
551 for(i = 0; i < BOARDSIZE; ++i)
552 for(j = 0; j < BOARDSIZE; ++j)
553 mp->board[b][i][j] = 1;
555 /* for(i = 0; i < BOARDSIZE; ++i) { */
556 /* board[0][i] = 1; */
557 /* board[i][0] = 1; */
558 /* board[BOARDSIZE-1][BOARDSIZE-i] = 1; */
559 /* board[BOARDSIZE-i][BOARDSIZE-1] = 1; */
562 /* board[0][BOARDSIZE-2] = 0; */
563 /* board[BOARDSIZE-1][1] = 0; */
566 mp->board[b][BOARDSIZE-1][1] = 0;
567 mp->board[b][0][BOARDSIZE-2] = 0;
569 /* build the ant paths */
570 if(mp->currentboard == b) {
571 for(i = 0; i < ANTCOUNT; ++i) {
572 int sx = BOARDSIZE-2;
576 mp->board[b][sx][sy] = 0;
577 mp->antpath[i][j][0] = sy - 5.0;
578 mp->antpath[i][j][1] = sx - 5.0;
583 else if(sy < BOARDSIZE-2)
599 mp->antpath[i][j][0] = BOARDSIZE-7.0;
600 mp->antpath[i][j][1] = -7.0;
601 mp->antpathlength[i] = j;
605 /* for(i = 0; i < 20; ++i) { */
606 /* int x = 1 + random()%(BOARDSIZE-2); */
607 /* int y = 1 + random()%(BOARDSIZE-2); */
608 /* board[x][y] = 1; */
612 /* compute nearness */
613 static int near(double a[2], double b[2])
615 return fabs(a[0] - b[0]) < 0.5 && fabs(a[1] - b[1]) < 0.5;
618 static double sign(double d)
620 return d < 0.0 ? -1.0 : 1.0;
623 static double min(double a, double b)
625 return a < b ? a : b;
628 /* draw method for ant */
629 static Bool draw_ant(antmazestruct *mp,
630 const float *Material, int mono, int shadow,
631 float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
634 float cos1 = cos(mp->ant_step);
635 float cos2 = cos(mp->ant_step + 2 * Pi / 3);
636 float cos3 = cos(mp->ant_step + 4 * Pi / 3);
637 float sin1 = sin(mp->ant_step);
638 float sin2 = sin(mp->ant_step + 2 * Pi / 3);
639 float sin3 = sin(mp->ant_step + 4 * Pi / 3);
641 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : Material);
643 /* glEnable(GL_CULL_FACE); */
647 if(!((*sphere)(0.18)))
649 glScalef(1, 1 / 1.3, 1);
650 glTranslatef(0.00, 0.30, 0.00);
651 if(!((*sphere)(0.2)))
654 glTranslatef(-0.05, 0.17, 0.05);
655 glRotatef(-90, 1, 0, 0);
656 glRotatef(-25, 0, 1, 0);
659 glTranslatef(0.00, 0.10, 0.00);
662 glRotatef(25, 0, 1, 0);
663 glRotatef(90, 1, 0, 0);
666 glTranslatef(0.15, -0.65, 0.05);
667 if(!((*sphere)(0.25)))
669 glScalef(1, 1 / 1.3, 1);
672 /* glDisable(GL_CULL_FACE); */
674 glDisable(GL_LIGHTING);
678 glColor3fv(mono ? MaterialGray5 : Material);
679 glVertex3f(0.00, 0.30, 0.00);
680 glColor3fv(MaterialGray);
681 glVertex3f(0.40, 0.70, 0.40);
682 glColor3fv(mono ? MaterialGray5 : Material);
683 glVertex3f(0.00, 0.30, 0.00);
684 glColor3fv(MaterialGray);
685 glVertex3f(0.40, 0.70, -0.40);
690 glColor3fv(mono ? MaterialGray6 : MaterialRed);
691 glVertex3f(0.40, 0.70, 0.40);
692 glVertex3f(0.40, 0.70, -0.40);
697 glBegin(GL_LINE_STRIP);
698 glColor3fv(mono ? MaterialGray5 : Material);
699 glVertex3f(0.00, 0.05, 0.18);
700 glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
701 glColor3fv(MaterialGray);
702 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
705 /* LEFT-CENTER ARM */
706 glBegin(GL_LINE_STRIP);
707 glColor3fv(mono ? MaterialGray5 : Material);
708 glVertex3f(0.00, 0.00, 0.18);
709 glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
710 glColor3fv(MaterialGray);
711 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
715 glBegin(GL_LINE_STRIP);
716 glColor3fv(mono ? MaterialGray5 : Material);
717 glVertex3f(0.00, -0.05, 0.18);
718 glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
719 glColor3fv(MaterialGray);
720 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
723 /* RIGHT-FRONT ARM */
724 glBegin(GL_LINE_STRIP);
725 glColor3fv(mono ? MaterialGray5 : Material);
726 glVertex3f(0.00, 0.05, -0.18);
727 glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
728 glColor3fv(MaterialGray);
729 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
732 /* RIGHT-CENTER ARM */
733 glBegin(GL_LINE_STRIP);
734 glColor3fv(mono ? MaterialGray5 : Material);
735 glVertex3f(0.00, 0.00, -0.18);
736 glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
737 glColor3fv(MaterialGray);
738 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
742 glBegin(GL_LINE_STRIP);
743 glColor3fv(mono ? MaterialGray5 : Material);
744 glVertex3f(0.00, -0.05, -0.18);
745 glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
746 glColor3fv(MaterialGray);
747 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
752 glColor3fv(mono ? MaterialGray8 : MaterialGray35);
753 glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
754 glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
755 glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
756 glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
757 glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
758 glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
762 glEnable(GL_LIGHTING);
767 static Bool draw_antmaze_strip(ModeInfo * mi)
769 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
771 int mono = MI_IS_MONO(mi);
773 /* glMatrixMode(GL_MODELVIEW); */
774 /* glLoadIdentity(); */
775 /* glPushMatrix(); */
777 glEnable(GL_LIGHTING);
778 /* glDisable(GL_BLEND); */
783 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
784 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
785 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
786 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
789 if(mp->elevator < 1.0) {
790 glEnable(GL_TEXTURE_2D);
791 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
792 glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
794 glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
795 glDisable(GL_TEXTURE_2D);
800 glTranslatef(0.0, -0.1, 0.0);
802 for(i = 0; i < ANTCOUNT; ++i) {
804 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
805 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
807 if(!mp->anton[i]) { continue; }
809 /* determine location, move to goal */
811 glTranslatef(0.0, 0.01, 0.0);
812 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
813 /* glScalef(1.0, 0.01, 1.0); */
814 glScalef(0.6, 0.01, 0.6);
815 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
816 glRotatef(90.0, 0.0, 0.0, 1.0);
817 glDisable(GL_LIGHTING);
819 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
820 glColor4fv(MaterialGrayB);
822 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
824 /* slow down first ant */
825 if(i == 0 && mp->part[i] == mp->antpathlength[i])
826 draw_ant(mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
828 draw_ant(mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
833 glEnable(GL_LIGHTING);
836 /* glTranslatef(0.0, 0.18, 0.0); */
837 glTranslatef(0.0, 0.12, 0.0);
838 glTranslatef(mp->antposition[i][0], mp->antposition[i][2], mp->antposition[i][1]);
839 glRotatef(180.0 + mp->antdirection[i]*180.0/PI, 0.0, 1.0, 0.0);
840 glRotatef(90.0, 0.0, 0.0, 1.0);
841 glScalef(0.6, 0.6, 0.6);
843 glScalef(mp->antsize[i], mp->antsize[i], mp->antsize[i]);
845 /* glEnable(GL_TEXTURE_2D); */
846 /* glBindTexture(GL_TEXTURE_2D, brushedtexture); */
848 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed); */
850 /* slow down first ant */
851 if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
852 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
853 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
854 draw_ant(mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
857 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
858 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
860 glEnable(GL_TEXTURE_2D);
861 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
862 draw_ant(mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
863 glDisable(GL_TEXTURE_2D);
867 /* draw_ant(antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
868 /* glDisable(GL_TEXTURE_2D); */
874 /* /\* now draw overlay *\/ */
875 /* glDisable(GL_LIGHTING); */
876 /* glDisable(GL_BLEND); */
878 /* /\* go to ortho mode *\/ */
879 /* glMatrixMode(GL_PROJECTION); */
880 /* glPushMatrix(); */
881 /* glLoadIdentity(); */
882 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
884 /* /\* translate to corner *\/ */
885 /* glTranslatef(4.0-1.2, 3.0-1.2, 0.0); */
887 /* glDisable(GL_LIGHTING); */
888 /* glEnable(GL_BLEND); */
890 /* /\* draw the 2d board *\/ */
891 /* glBegin(GL_QUADS); */
894 /* double sz = 1.0; */
895 /* for(i = 0; i < BOARDSIZE; ++i) */
896 /* for(j = 0; j < BOARDSIZE; ++j) { */
897 /* int par = board[i][j]; */
898 /* glColor4f(par ? 0.4 : 0.6, */
899 /* par ? 0.4 : 0.6, */
900 /* par ? 0.4 : 0.6, */
902 /* glNormal3f(0.0, 0.0, 1.0); */
903 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
904 /* glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
905 /* glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
906 /* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
914 /* but the step size is the same! */
915 mp->ant_step += 0.18;
916 /* if(ant_step > 2*Pi) { */
917 /* ant_step = 0.0; */
920 if(mp->ant_step > 5*Pi)
923 mp->ant_position += 1;
926 #undef AntmazeDivisions
927 #undef AntmazeTransversals
929 ENTRYPOINT void reshape_antmaze(ModeInfo * mi, int width, int height)
931 double h = (GLfloat) height / (GLfloat) width;
932 int size = (width / 512) + 1;
933 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
935 glViewport(0, 0, mp->WindW = (GLint) width, mp->WindH = (GLint) height);
936 glMatrixMode(GL_PROJECTION);
939 gluPerspective(45, 1/h, 1, 25.0);
941 glMatrixMode(GL_MODELVIEW);
942 /* glLineWidth(3.0); */
947 static void update_ants(antmazestruct *mp)
951 df[0] = df[1] = df[2] = 0.8*mp->fadeout;
955 if(mp->fadeoutspeed < -0.00001) {
957 if(mp->fadeout <= 0.0) {
958 /* switch boards: rebuild old board, increment current */
959 mp->currentboard = (mp->currentboard+1)%BOARDCOUNT;
960 build_board(mp, mp->currentboard);
961 mp->fadeoutspeed = 0.02;
964 mp->fadeout += mp->fadeoutspeed;
966 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
967 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
971 if(mp->fadeoutspeed > 0.0001) {
972 mp->fadeout += mp->fadeoutspeed;
973 if(mp->fadeout >= 1.0) {
975 mp->fadeoutspeed = 0.0;
976 mp->entroducing = 12;
978 glLightfv(GL_LIGHT0, GL_DIFFUSE, df);
979 glLightfv(GL_LIGHT1, GL_DIFFUSE, df);
982 for(i = 0; i < ANTCOUNT; ++i) {
984 if(!mp->anton[i] && mp->elevator < 1.0) {
987 if(mp->entroducing > 0 && mp->introduced <= 0 && random()%100 == 0) {
990 mp->antsize[i] = 0.0;
991 mp->antposition[i][0] = -4.0;
992 mp->antposition[i][1] = 5.0;
993 mp->antdirection[i] = PI/2.0;
994 mp->bposition[i][0] = 0;
995 mp->bposition[i][1] = 8;
996 mp->introduced = 300;
1003 if(mp->part[i] == 0 && mp->antsize[i] < 1.0) {
1004 mp->antsize[i] += 0.02;
1008 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] > 0.0) {
1009 mp->antsize[i] -= 0.02;
1010 if(mp->antvelocity[i] > 0.0) {
1011 mp->antvelocity[i] -= 0.02;
1013 else { mp->antvelocity[i] = 0.0; }
1018 if(mp->part[i] > mp->antpathlength[i] && mp->antsize[i] <= 0.0) {
1019 mp->antvelocity[i] = 0.02;
1022 antmaterial[i] = materials[random()%MATERIALS];
1025 mp->antdirection[i] = PI/2.0;
1026 mp->bposition[i][0] = 0;
1027 mp->bposition[i][1] = 8;
1030 mp->antsize[i] = 0.0;
1034 mp->antposition[i][0] = -4.0;
1035 mp->antposition[i][1] = 5.0;
1037 /* /\* reset camera *\/ */
1038 /* if(i == focus) { */
1040 /* ant_step = 0.0; */
1043 /* check for the end */
1044 if(mp->entroducing <= 0) {
1046 for(z = 0; z < ANTCOUNT; ++z) {
1047 if(mp->anton[z]) { ao = 1; break; }
1051 mp->fadeoutspeed = -0.02;
1057 /* near goal, bend path towards next step */
1058 if(near(mp->antposition[i], mp->antpath[i][mp->part[i]])) {
1062 /* /\* special first ant *\/ */
1063 /* if(i == 0 && part[i] > antpathlength[i]) { */
1065 /* first_ant_step = ant_step; */
1067 /* antvelocity[i] = 0.0; */
1068 /* /\* antposition[i][2] += 0.025; *\/ */
1069 /* elevator += 0.025; */
1071 /* /\* set light *\/ */
1072 /* double l1 = 1.0 - (elevator < 1.0 ? elevator : 2.0 - elevator); */
1073 /* GLfloat df[4] = {0.8*l1, 0.8*l1, 0.8*l1, 1.0}; */
1074 /* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
1075 /* glLightfv(GL_LIGHT1, GL_DIFFUSE, df); */
1077 /* /\* draw next board *\/ */
1078 /* if(elevator > 1.0) { */
1080 /* if(makenew == 1) { */
1083 /* /\* switch boards: rebuild old board, increment current *\/ */
1084 /* currentboard = (currentboard+1)%BOARDCOUNT; */
1085 /* build_board(currentboard); */
1087 /* for(re = 1; re < ANTCOUNT; ++re) { */
1088 /* anton[re] = 0; */
1089 /* antmaterial[re] = materials[random()%MATERIALS]; */
1096 /* /\* draw the other board *\/ */
1097 /* glEnable(GL_TEXTURE_2D); */
1098 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6); */
1100 /* glPushMatrix(); */
1101 /* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */
1102 /* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
1104 /* glPopMatrix(); */
1105 /* glDisable(GL_TEXTURE_2D); */
1108 /* if(elevator > 2.0) { */
1109 /* antposition[i][0] = -4.0;/\*-= -(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0);*\//\*= -4.0;*\/ */
1110 /* antposition[i][1] = 5.5;/\*-(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0);*\/ */
1111 /* /\* antposition[i][2] = 0.15; *\/ */
1112 /* antdirection[i] = PI/2.0; */
1113 /* bposition[i][0] = 0; */
1114 /* bposition[i][1] = 8; */
1116 /* antvelocity[i] = 0.02; */
1118 /* antmaterial[i] = MaterialRed; */
1122 /* elevator = 0.0; */
1123 /* introduced = 200; */
1132 /* move toward goal, correct ant direction if required */
1136 double dx = mp->antpath[i][mp->part[i]][0] - mp->antposition[i][0];
1137 double dz = - mp->antpath[i][mp->part[i]][1] + mp->antposition[i][1];
1138 double theta, ideal;
1141 theta = atan(dz/dx);
1143 theta = dx > EPSILON ? 0.0 : PI;
1145 ideal = theta - mp->antdirection[i];
1149 /* compute correction */
1151 double dt = sign(ideal) * min(fabs(ideal), PI/90.0);
1152 mp->antdirection[i] += dt;
1153 if(mp->antdirection[i] > 2.0*PI)
1154 mp->antdirection[i] = 0.0;
1158 mp->antposition[i][0] += mp->antvelocity[i] * cos(mp->antdirection[i]);
1159 mp->antposition[i][1] += mp->antvelocity[i] * sin(-mp->antdirection[i]);
1163 static void pinit(antmazestruct *mp)
1166 glClearColor(0.0, 0.0, 0.0, 1.0);
1168 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
1169 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1170 glLightfv(GL_LIGHT0, GL_POSITION, position0);
1171 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
1172 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1173 glLightfv(GL_LIGHT1, GL_POSITION, position1);
1175 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
1176 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001);
1177 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
1179 glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05);
1180 glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001);
1181 glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);
1184 /* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
1185 /* glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */
1186 glEnable(GL_LIGHTING);
1187 glEnable(GL_LIGHT0);
1188 glEnable(GL_LIGHT1);
1189 glEnable(GL_NORMALIZE);
1190 glFrontFace(GL_CCW);
1191 glCullFace(GL_BACK);
1194 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
1195 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
1197 glShadeModel(GL_SMOOTH);
1198 glEnable(GL_DEPTH_TEST);
1199 glDisable(GL_TEXTURE_2D);
1201 /* setup textures */
1203 makeBrushedImage(mp);
1208 /* makeCheckImage(); */
1209 /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */
1210 /* glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, */
1211 /* checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */
1212 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */
1213 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */
1215 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
1216 /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
1217 /* glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */
1218 glEnable(GL_TEXTURE_2D);
1220 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */
1221 /* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
1224 ENTRYPOINT void release_antmaze(ModeInfo * mi)
1227 free((void *) antmaze);
1228 antmaze = (antmazestruct *) NULL;
1233 #define MAX_MAGNIFICATION 10
1234 #define max(a, b) a < b ? b : a
1235 #define min(a, b) a < b ? a : b
1237 ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
1239 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1241 switch(event->xany.type) {
1244 switch(event->xbutton.button) {
1247 mp->button_down_p = True;
1248 gltrackball_start(mp->trackball,
1249 event->xbutton.x, event->xbutton.y,
1250 MI_WIDTH (mi), MI_HEIGHT (mi));
1254 mp->focus = (mp->focus + 1) % ANTCOUNT;
1258 mp->mag = max(mp->mag-1, 1);
1262 mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
1270 switch(event->xbutton.button) {
1272 mp->button_down_p = False;
1279 if(mp->button_down_p)
1280 gltrackball_track(mp->trackball,
1281 event->xmotion.x, event->xmotion.y,
1282 MI_WIDTH (mi), MI_HEIGHT (mi));
1292 ENTRYPOINT void init_antmaze(ModeInfo * mi)
1294 double rot_speed = 0.3;
1299 if (antmaze == NULL) {
1300 if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
1301 sizeof (antmazestruct))) == NULL)
1304 mp = &antmaze[MI_SCREEN(mi)];
1305 mp->step = NRAND(90);
1306 mp->ant_position = NRAND(90);
1309 mp->antdirection[0] = PI/2.0;
1310 mp->antdirection[1] = PI/2.0;
1311 mp->antdirection[2] = 0;
1312 mp->antdirection[3] = PI/2.0;
1313 mp->antdirection[4] = PI/2.0;
1315 mp->antposition[0][0] = -4.0;
1316 mp->antposition[0][1] = 5.0;
1317 mp->antposition[0][1] = 0.15;
1319 mp->antposition[1][0] = -4.0;
1320 mp->antposition[1][1] = 3.0;
1321 mp->antposition[1][1] = 0.15;
1323 mp->antposition[2][0] = -1.0;
1324 mp->antposition[2][1] = -2.0;
1325 mp->antposition[2][1] = 0.15;
1327 mp->antposition[3][0] = -3.9;
1328 mp->antposition[3][1] = 6.0;
1329 mp->antposition[3][1] = 0.15;
1331 mp->antposition[4][0] = 2.0;
1332 mp->antposition[4][1] = -2.0;
1333 mp->antposition[4][1] = 0.15;
1337 for (i = 0; i < ANTCOUNT; i++) {
1338 mp->antvelocity[i] = 0.02;
1339 mp->antsize[i] = 1.0;
1343 mp->bposition[0][0] = 0;
1344 mp->bposition[0][1] = 8;
1346 mp->bposition[1][0] = 9;
1347 mp->bposition[1][1] = 1;
1349 mp->bposition[2][0] = 1;
1350 mp->bposition[2][1] = 1;
1352 mp->bposition[3][0] = 4;
1353 mp->bposition[3][1] = 8;
1355 mp->bposition[4][0] = 2;
1356 mp->bposition[4][1] = 1;
1365 mp->entroducing = 12;
1369 mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
1370 mp->trackball = gltrackball_init ();
1372 if ((mp->glx_context = init_GL(mi)) != NULL) {
1373 reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1374 glDrawBuffer(GL_BACK);
1381 ENTRYPOINT void draw_antmaze(ModeInfo * mi)
1383 double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
1387 Display *display = MI_DISPLAY(mi);
1388 Window window = MI_WINDOW(mi);
1392 mp = &antmaze[MI_SCREEN(mi)];
1394 MI_IS_DRAWN(mi) = True;
1396 if(!mp->glx_context)
1399 glXMakeCurrent(display, window, *(mp->glx_context));
1401 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1405 /* h = ((GLfloat) MI_HEIGHT(mi)/2) / (3*(GLfloat)MI_WIDTH(mi)/4); */
1406 glViewport(MI_WIDTH(mi)/32, MI_HEIGHT(mi)/8, (9*MI_WIDTH(mi))/16, 3*MI_HEIGHT(mi)/4);
1407 glMatrixMode(GL_PROJECTION);
1410 /* h = (3*MI_HEIGHT(mi)/4) / (3*MI_WIDTH(mi)/4); */
1411 gluPerspective(45, 1/h, 1, 25.0);
1413 glMatrixMode(GL_MODELVIEW);
1418 /* follow focused ant */
1419 glTranslatef(0.0, 0.0, -mp->mag - 5.0);
1420 glRotatef(20.0+5.0*sin(mp->ant_step/40.0), 1.0, 0.0, 0.0);
1421 /* glTranslatef(0.0, */
1422 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0)), */
1423 /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0))); */
1425 gltrackball_rotate(mp->trackball);
1427 glRotatef(mp->ant_step*0.6, 0.0, 1.0, 0.0);
1429 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1431 /* glTranslatef(-antposition[0][0]-0.5, 0.0, -antposition[focus][1]); */
1435 if(!draw_antmaze_strip(mi)) {
1436 release_antmaze(mi);
1443 h = (GLfloat) (3*MI_HEIGHT(mi)/8) / (GLfloat) (MI_WIDTH(mi)/2);
1447 glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
1448 glMatrixMode(GL_PROJECTION);
1450 gluPerspective(45, 1/h, 1, 25.0);
1451 glMatrixMode(GL_MODELVIEW);
1454 glTranslatef(0.0, 0.0, -16.0);
1455 glRotatef(60.0, 1.0, 0.0, 0.0);
1456 glRotatef(-15.0 + mp->ant_step/10.0, 0.0, 1.0, 0.0);
1457 gltrackball_rotate(mp->trackball);
1460 if(!draw_antmaze_strip(mi)) {
1461 release_antmaze(mi);
1467 /* draw ant display */
1469 glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
1470 glMatrixMode(GL_PROJECTION);
1472 gluPerspective(45, 1/h, 1, 25.0);
1473 glMatrixMode(GL_MODELVIEW);
1476 glTranslatef(0.0, 0.0, -1.6);
1477 glRotatef(30.0, 1.0, 0.0, 0.0);
1478 glRotatef(mp->ant_step, 0.0, 1.0, 0.0);
1479 glRotatef(90.0, 0.0, 0.0, 1.0);
1481 /* /\* draw ant shadow *\/ */
1482 /* glPushMatrix(); */
1483 /* glScalef(1.0, 0.01, 1.0); */
1484 /* glRotatef(90.0, 0.0, 0.0, 1.0); */
1485 /* glRotatef(90.0, 0.0, 1.0, 0.0); */
1486 /* glDisable(GL_LIGHTING); */
1487 /* glColor4fv(MaterialGray6); */
1489 /* /\* slow down first ant *\/ */
1490 /* draw_ant(MaterialGrayB, 0, 1, first_ant_step, mySphere, myCone); */
1491 /* glPopMatrix(); */
1494 glEnable(GL_TEXTURE_2D);
1495 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
1496 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
1497 glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
1498 draw_ant(mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
1499 glDisable(GL_TEXTURE_2D);
1503 /* /\* draw overlay *\/ */
1504 /* glPushMatrix(); */
1506 /* /\* go to ortho mode *\/ */
1507 /* glViewport(MI_WIDTH(mi)/2, MI_HEIGHT(mi)/8, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); */
1509 /* glMatrixMode(GL_PROJECTION); */
1510 /* glLoadIdentity(); */
1512 /* glPushMatrix (); */
1513 /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */
1515 /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); */
1516 /* glColor4fv(MaterialGrayB); */
1518 /* glDisable(GL_LIGHTING); */
1519 /* glEnable(GL_BLEND); */
1521 /* glBegin(GL_QUADS); */
1522 /* glNormal3f(0.0, 0.0, 1.0); */
1523 /* glVertex3f(4.0, 3.0, 0.0); */
1524 /* glVertex3f(2.0, 3.0, 0.0); */
1525 /* glVertex3f(2.0, -3.0, 0.0); */
1526 /* glVertex3f(4.0, -3.0, 0.0); */
1529 /* glEnable(GL_LIGHTING); */
1530 /* glDisable(GL_BLEND); */
1532 /* glPopMatrix(); */
1533 /* glPopMatrix(); */
1535 if (MI_IS_FPS(mi)) do_fps (mi);
1538 glXSwapBuffers(display, window);
1546 ENTRYPOINT void change_antmaze(ModeInfo * mi)
1548 antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
1550 if (!mp->glx_context)
1553 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context));
1556 #endif /* !STANDALONE */
1558 XSCREENSAVER_MODULE ("AntMaze", antmaze)