"*showFPS: False \n" \
"*useSHM: True \n"
-# define refresh_antspotlight 0
+# define free_antspotlight 0
+# define release_antspotlight 0
#include "xlockmore.h"
#else
#include "xlock.h"
#endif
+#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 */
+
+#include "sphere.h"
+#include "tube.h"
#include "rotator.h"
#include "gltrackball.h"
#ifdef USE_MODULES
ModStruct antspotlight_description = {
"antspotlight", "init_antspotlight", "draw_antspotlight",
- "release_antspotlight", "draw_antspotlight", "change_antspotlight",
+ (char *) NULL, "draw_antspotlight", "change_antspotlight",
(char *) NULL, &antspotlight_opts, 1000, 1, 1, 1, 4, 1.0, "",
"draws an ant scoping the screen", 0, NULL
};
#define NUM_SCENES 2
/* draw method for ant */
-static Bool draw_ant(antspotlightstruct *mp,
+static Bool draw_ant(ModeInfo *mi, antspotlightstruct *mp,
const GLfloat *Material, int mono, int shadow,
float ant_step, Bool (*sphere)(float), Bool (*cone)(float))
{
float sin2 = sin(ant_step + 2 * Pi / 3);
float sin3 = sin(ant_step + 4 * Pi / 3);
+/* Apparently this is a performance killer on many systems...
+ glEnable(GL_POLYGON_SMOOTH);
+ */
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mp->mono ? MaterialGray5 : Material);
glEnable(GL_CULL_FACE);
glPushMatrix();
glDisable(GL_LIGHTING);
/* ANTENNAS */
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
glBegin(GL_LINES);
glColor3fv(mp->mono ? MaterialGray5 : Material);
glVertex3f(0.00, 0.30, 0.00);
glColor3fv(MaterialGray);
glVertex3f(0.40, 0.70, 0.40);
+ mi->polygon_count++;
glColor3fv(mp->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(mp->mono ? MaterialGray6 : MaterialGray5);
glVertex3f(0.40, 0.70, 0.40);
+ mi->polygon_count++;
glVertex3f(0.40, 0.70, -0.40);
+ mi->polygon_count++;
glEnd();
}
glColor3fv(mp->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(mp->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(mp->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(mp->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(mp->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(mp->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();
}
/* 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;
}
/* silhouette sphere */
static Bool mySphere2(float radius)
{
+#if 0
GLUquadricObj *quadObj;
if((quadObj = gluNewQuadric()) == 0)
gluQuadricDrawStyle(quadObj, (GLenum) GLU_LINE);
gluSphere(quadObj, radius, 16, 8);
gluDeleteQuadric(quadObj);
-
+#else
+ /* #### no GLU_LINE */
+ glPushMatrix();
+ glScalef (radius, radius, radius);
+ glRotatef (90, 1, 0, 0);
+ unit_sphere (16, 16, True);
+ glPopMatrix();
+#endif
return True;
}
/* no cone */
static Bool myCone2(float radius) { return True; }
-static void draw_board(antspotlightstruct *mp)
+static void draw_board(ModeInfo *mi, antspotlightstruct *mp)
{
int i, j;
double cutoff = Pi/3.0;
i should be finding the intersection of the cone of light and
the board-plane.
*/
- for(i = -8; i < 8; ++i) {
+ for(i = -12; i < 12; ++i) {
double theta1, theta2;
theta1 = mp->ant->direction + i*(cutoff/8);
theta2 = mp->ant->direction + (i+1)*(cutoff/8);
- for(j = 1; j <= 40; ++j) {
+ for(j = 1; j <= 64; ++j) {
double point[3], tex[2];
/* double fj = pow(1.05, j) - 1.0;*/
double fj = j / 6.0;
glTexCoord2f(tex[0], tex[1]);
glVertex3f(point[0], point[1], point[2]);
+ mi->polygon_count++;
}
glEnd();
}
/* draw ant composed of skeleton and glass */
-static void show_ant(antspotlightstruct *mp)
+static void show_ant(ModeInfo *mi, antspotlightstruct *mp)
{
glPushMatrix();
glRotatef(90.0, 0.0, 0.0, 1.0);
/* draw skeleton */
- draw_ant(mp, mp->ant->material, mp->mono, 0, mp->ant->step, mySphere2, myCone2);
+ draw_ant(mi, mp, mp->ant->material, mp->mono, 0, mp->ant->step, mySphere2, myCone2);
/* draw glass */
if(!mp->wire && !mp->mono) {
glEnable(GL_BLEND);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB);
glColor4fv(MaterialGrayB);
- draw_ant(mp, MaterialGrayB, mp->mono, 0, mp->ant->step, mySphere, myCone2);
+ draw_ant(mi, mp, MaterialGrayB, mp->mono, 0, mp->ant->step, mySphere, myCone2);
glDisable(GL_BLEND);
}
if(mp->wire)
;
else
- draw_board(mp);
+ draw_board(mi, mp);
glDisable(GL_LIGHT2);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
/* now modify ant */
- show_ant(mp);
+ show_ant(mi, mp);
/* near goal, bend path towards next step */
if(distance(mp->ant->position, mp->ant->goal) < 0.2) {
reset_ant(mp);
}
+ if(random()%100 == 0) {
+ reset_ant(mp);
+ }
+
+
/* move toward goal, correct ant direction if required */
else {
ENTRYPOINT void reshape_antspotlight(ModeInfo * mi, int width, int height)
{
double h = (GLfloat) height / (GLfloat) width;
+ int y = 0;
int size = 2;
- glViewport(0, 0, width, height);
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width * 9/16;
+ y = -height/2;
+ h = height / (GLfloat) width;
+ }
+
+ glViewport(0, y, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
static void pinit(void)
{
glClearDepth(1.0);
- glClearColor(0.0, 0.0, 0.0, 1.0);
-
+
/* setup twoside lighting */
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
-/* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
+
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, spotlight_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
-/* cleanup routine */
-ENTRYPOINT void release_antspotlight(ModeInfo * mi)
-{
-
- if(antspotlight) {
- free((void *) antspotlight);
- antspotlight = (antspotlightstruct *) NULL;
- }
-
- FreeAllGL(mi);
-}
-
#define MAX_MAGNIFICATION 10
#define max(a, b) a < b ? b : a
#define min(a, b) a < b ? a : b
{
antspotlightstruct *mp = &antspotlight[MI_SCREEN(mi)];
- switch(event->xany.type) {
- case 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;
+ if (gltrackball_event_handler (event, mp->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &mp->button_down_p))
+ return True;
+
+ 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));
+ return True;
- case Button4:
- mp->mag = max(mp->mag-1, 1);
- break;
-
- case Button5:
- mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
- break;
- }
-
- break;
-
- case ButtonRelease:
-
- switch(event->xbutton.button) {
- case Button1:
- mp->button_down_p = False;
- break;
+ case Button4:
+ mp->mag = max(mp->mag-1, 1);
+ return True;
+
+ 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;
}
static void
antspotlightstruct *mp;
- if(!antspotlight) {
- if((antspotlight = (antspotlightstruct *)
- calloc(MI_NUM_SCREENS(mi), sizeof (antspotlightstruct))) == NULL)
- return;
- }
+ MI_INIT(mi, antspotlight);
mp = &antspotlight[MI_SCREEN(mi)];
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_antspotlight(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
if(!mp->glx_context)
return;
+ mi->polygon_count = 0;
+
/* Just keep running before the texture has come in. */
/* if (mp->waiting_for_image_p) return; */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
+ glRotatef(current_device_rotation(), 0, 0, 1);
/* position camera */