* tennessy@cs.ubc.ca
*/
-#if !defined( lint ) && !defined( SABER )
+#if 0
static const char sccsid[] = "@(#)antmaze.c 5.01 2001/03/01 xlockmore";
#endif
#ifdef STANDALONE
# define MODE_antmaze
# define DEFAULTS "*delay: 20000 \n" \
- "*showFPS: False \n"
+ "*showFPS: False \n" \
+ "*fpsSolid: True \n"
# define refresh_antmaze 0
+# define release_antmaze 0
# include "xlockmore.h" /* from the xscreensaver distribution */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
-
#endif /* !STANDALONE */
+#ifdef HAVE_JWXYZ
+# include "jwxyz.h"
+#else
+# include <X11/Xlib.h>
+# include <GL/gl.h>
+# include <GL/glu.h>
+#endif
+
+#ifdef HAVE_JWZGLES
+# include "jwzgles.h"
+#endif /* HAVE_JWZGLES */
+
#ifdef MODE_antmaze
+#include "sphere.h"
+#include "tube.h"
#include "rotator.h"
#include "gltrackball.h"
#ifdef USE_MODULES
ModStruct antmaze_description =
-{"antmaze", "init_antmaze", "draw_antmaze", "release_antmaze",
+{"antmaze", "init_antmaze", "draw_antmaze", NULL,
"draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
1000, 1, 1, 1, 4, 1.0, "",
"draws some ants", 0, NULL};
/* filled sphere */
static Bool mySphere(float radius)
{
+#if 0
GLUquadricObj *quadObj;
if((quadObj = gluNewQuadric()) == 0)
gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
gluSphere(quadObj, radius, 16, 16);
gluDeleteQuadric(quadObj);
-
+#else
+ glPushMatrix();
+ glScalef (radius, radius, radius);
+ glRotatef (90, 1, 0, 0);
+ unit_sphere (16, 16, False);
+ glPopMatrix();
+#endif
return True;
}
/* textured sphere */
static Bool mySphereTex(float radius)
{
+#if 0
GLUquadricObj *quadObj;
if((quadObj = gluNewQuadric()) == 0)
gluQuadricNormals(quadObj, GLU_SMOOTH);
gluSphere(quadObj, radius, 32, 16);
gluDeleteQuadric(quadObj);
+#else
+ glPushMatrix();
+ glScalef (radius, radius, radius);
+ glRotatef (90, 1, 0, 0);
+ unit_sphere (32, 16, False);
+ glPopMatrix();
+#endif
return True;
}
/* filled cone */
static Bool myCone(float radius)
{
+#if 0
GLUquadricObj *quadObj;
if ((quadObj = gluNewQuadric()) == 0)
gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
gluDeleteQuadric(quadObj);
+#else
+ cone (0, 0, 0,
+ 0, 0, radius * 2,
+ radius, 0,
+ 8, True, True, False);
+#endif
return True;
}
}
#if 0
-static void draw_wall(double x1, double z1, double x2, double z2)
+static void draw_wall(ModeInfo *mi, double x1, double z1, double x2, double z2)
{
float x = fabs(x2 - x1)/2.0;
glVertex3f(x2, 1.0, z2-0.25);
glTexCoord2f(0.0, 0.25);
glVertex3f(x1, 1.0, z1-0.25);
+ mi->polygon_count++;
/* draw sides */
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(x2, 1.0, z2+0.25);
glTexCoord2f(0.0, 0.5);
glVertex3f(x1, 1.0, z1+0.25);
+ mi->polygon_count++;
glNormal3f(0.0, 0.0, -1.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(x2, 1.0, z2-0.25);
glTexCoord2f(0.0, 0.5);
glVertex3f(x1, 1.0, z1-0.25);
+ mi->polygon_count++;
/* draw ends */
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(x2, 1.0, z2-0.25);
glTexCoord2f(0.0, 0.5);
glVertex3f(x2, 1.0, z2+0.25);
+ mi->polygon_count++;
glNormal3f(-1.0, 0.0, 0.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(x1, 1.0, z1+0.25);
glTexCoord2f(0.0, 0.5);
glVertex3f(x1, 1.0, z1-0.25);
+ mi->polygon_count++;
glEnd();
}
#endif
-static void draw_board(antmazestruct *mp)
+static void draw_board(ModeInfo *mi, antmazestruct *mp)
{
int i, j;
glVertex3f(i+0.5, h, j-0.5);
glTexCoord2f(0.0 + stf, 1.0 + stf);
glVertex3f(i-0.5, h, j-0.5);
+ mi->polygon_count++;
/* draw south face */
if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
glVertex3f(i+0.5, h, j+0.5);
glTexCoord2f(0.0 + stf, h + stf);
glVertex3f(i-0.5, h, j+0.5);
+ mi->polygon_count++;
}
/* draw north face */
glVertex3f(i-0.5, h, j-0.5);
glTexCoord2f(0.0 + stf, h + stf);
glVertex3f(i+0.5, h, j-0.5);
+ mi->polygon_count++;
}
/* draw east face */
glVertex3f(i+0.5, h, j-0.5);
glTexCoord2f(0.0 + stf, h + stf);
glVertex3f(i+0.5, h, j+0.5);
+ mi->polygon_count++;
}
/* draw west face */
glVertex3f(i-0.5, h, j+0.5);
glTexCoord2f(0.0 + stf, h + stf);
glVertex3f(i-0.5, h, j-0.5);
+ mi->polygon_count++;
}
}
else {
glVertex3f(i+0.5, 0.0, j-0.5);
glTexCoord2f(0.0, tx);
glVertex3f(i-0.5, 0.0, j-0.5);
+ mi->polygon_count++;
}
}
glEnd();
/* glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
/* glTexCoord2f(0.0, 1.5); */
/* glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
+/* mi->polygon_count++; */
/* } */
/* /\* destination *\/ */
/* glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
/* glTexCoord2f(0.0, 1.5); */
/* glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
+/* mi->polygon_count++; */
/* glEnd(); */
/* glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
/* glTexCoord2f(0.0 + stf, 1.0 + stf); */
/* glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
+/* mi->polygon_count++; */
/* } */
/* } */
}
/* draw method for ant */
-static Bool draw_ant(antmazestruct *mp,
+static Bool draw_ant(ModeInfo *mi, antmazestruct *mp,
const float *Material, int mono, int shadow,
float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
{
glVertex3f(0.00, 0.30, 0.00);
glColor3fv(MaterialGray);
glVertex3f(0.40, 0.70, 0.40);
+ mi->polygon_count++;
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.30, 0.00);
glColor3fv(MaterialGray);
glVertex3f(0.40, 0.70, -0.40);
+ mi->polygon_count++;
glEnd();
if(!shadow) {
glBegin(GL_POINTS);
glColor3fv(mono ? MaterialGray6 : MaterialRed);
glVertex3f(0.40, 0.70, 0.40);
+ mi->polygon_count++;
glVertex3f(0.40, 0.70, -0.40);
+ mi->polygon_count++;
glEnd();
}
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.05, 0.18);
glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
+ mi->polygon_count++;
glEnd();
/* LEFT-CENTER ARM */
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.00, 0.18);
glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
+ mi->polygon_count++;
glEnd();
/* LEFT-BACK ARM */
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, -0.05, 0.18);
glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
+ mi->polygon_count++;
glEnd();
/* RIGHT-FRONT ARM */
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.05, -0.18);
glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
+ mi->polygon_count++;
glEnd();
/* RIGHT-CENTER ARM */
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.00, -0.18);
glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
+ mi->polygon_count++;
glEnd();
/* RIGHT-BACK ARM */
glColor3fv(mono ? MaterialGray5 : Material);
glVertex3f(0.00, -0.05, -0.18);
glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
+ mi->polygon_count++;
glColor3fv(MaterialGray);
glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
+ mi->polygon_count++;
glEnd();
if(!shadow) {
glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
+ mi->polygon_count += 6;
glEnd();
}
glEnable(GL_TEXTURE_2D);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
- draw_board(mp);
+ draw_board(mi, mp);
glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
glDisable(GL_TEXTURE_2D);
}
/* slow down first ant */
if(i == 0 && mp->part[i] == mp->antpathlength[i])
- draw_ant(mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
+ draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
else
- draw_ant(mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
+ draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
glPopMatrix();
if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
- draw_ant(mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
+ draw_ant(mi, mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
}
else {
/* glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
- draw_ant(mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
+ draw_ant(mi, mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
glDisable(GL_TEXTURE_2D);
}
-/* draw_ant(antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
+/* draw_ant(mi, antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
/* glDisable(GL_TEXTURE_2D); */
glPopMatrix();
}
/* glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
/* glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
/* glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
+/* mi->polygon_count++; */
/* } */
/* } */
/* glEnd(); */
/* glPushMatrix(); */
/* glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0, */
/* -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
-/* draw_board(); */
+/* draw_board(mi, mp); */
/* glPopMatrix(); */
/* glDisable(GL_TEXTURE_2D); */
/* } */
static void pinit(antmazestruct *mp)
{
glClearDepth(1.0);
- glClearColor(0.0, 0.0, 0.0, 1.0);
-
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
/* glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
}
-ENTRYPOINT void release_antmaze(ModeInfo * mi)
-{
- if(antmaze) {
- free((void *) antmaze);
- antmaze = (antmazestruct *) NULL;
- }
- FreeAllGL(mi);
-}
-
#define MAX_MAGNIFICATION 10
#define max(a, b) a < b ? b : a
#define min(a, b) a < b ? a : b
{
antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
- switch(event->xany.type) {
- case ButtonPress:
+ if (gltrackball_event_handler (event, mp->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &mp->button_down_p))
+ return True;
- switch(event->xbutton.button) {
+ if (event->xany.type == ButtonPress)
+ {
+ switch(event->xbutton.button) {
- case Button1:
- mp->button_down_p = True;
- gltrackball_start(mp->trackball,
- event->xbutton.x, event->xbutton.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- break;
-
- case Button3:
- mp->focus = (mp->focus + 1) % ANTCOUNT;
- break;
+ case Button3:
+ mp->focus = (mp->focus + 1) % ANTCOUNT;
+ return True;
- case Button4:
- mp->mag = max(mp->mag-1, 1);
- break;
-
- case Button5:
- mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
- break;
- }
+ case Button4:
+ mp->mag = max(mp->mag-1, 1);
+ return True;
- break;
-
- case ButtonRelease:
-
- switch(event->xbutton.button) {
- case Button1:
- mp->button_down_p = False;
- break;
+ case Button5:
+ mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
+ return True;
+ }
}
- break;
-
- case MotionNotify:
- if(mp->button_down_p)
- gltrackball_track(mp->trackball,
- event->xmotion.x, event->xmotion.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- break;
-
- default:
- return False;
- }
-
- return True;
+ return False;
}
ENTRYPOINT void init_antmaze(ModeInfo * mi)
antmazestruct *mp;
- if (antmaze == NULL) {
- if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
- sizeof (antmazestruct))) == NULL)
- return;
- }
+ MI_INIT(mi, antmaze, NULL);
mp = &antmaze[MI_SCREEN(mi)];
mp->step = NRAND(90);
mp->ant_position = NRAND(90);
mp->mag = 4.0;
mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
- mp->trackball = gltrackball_init ();
+ mp->trackball = gltrackball_init (False);
if ((mp->glx_context = init_GL(mi)) != NULL) {
reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
MI_CLEARWINDOW(mi);
}
+static void
+device_rotate(ModeInfo *mi)
+{
+#if 0
+ GLfloat rot = current_device_rotation();
+ glRotatef(rot, 0, 0, 1);
+ if ((rot > 45 && rot < 135) ||
+ (rot < -45 && rot > -135))
+ {
+ GLfloat s = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+ glScalef (1/s, s, 1);
+ }
+#endif
+}
+
+
ENTRYPOINT void draw_antmaze(ModeInfo * mi)
{
double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
if(!mp->glx_context)
return;
+ mi->polygon_count = 0;
glXMakeCurrent(display, window, *(mp->glx_context));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+ device_rotate(mi);
glPushMatrix();
/* sync */
if(!draw_antmaze_strip(mi)) {
- release_antmaze(mi);
+ MI_ABORT(mi);
return;
}
glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
+ device_rotate(mi);
gluPerspective(45, 1/h, 1, 25.0);
glMatrixMode(GL_MODELVIEW);
/* sync */
if(!draw_antmaze_strip(mi)) {
- release_antmaze(mi);
+ MI_ABORT(mi);
return;
}
glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
+ device_rotate(mi);
gluPerspective(45, 1/h, 1, 25.0);
glMatrixMode(GL_MODELVIEW);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
- draw_ant(mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
+ draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
/* glVertex3f(2.0, 3.0, 0.0); */
/* glVertex3f(2.0, -3.0, 0.0); */
/* glVertex3f(4.0, -3.0, 0.0); */
+/* mi->polygon_count++; */
/* glEnd(); */
/* glEnable(GL_LIGHTING); */
/* glPopMatrix(); */
/* glPopMatrix(); */
- if (MI_IS_FPS(mi)) do_fps (mi);
+ if (MI_IS_FPS(mi)) {
+ glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
+ do_fps (mi);
+ }
glFlush();
glXSwapBuffers(display, window);