#ifdef STANDALONE
#define DEFAULTS "*delay: 30000 \n" \
"*showFPS: False \n" \
- "*titleFont: -*-times-bold-r-normal-*-180-*\n" \
+ "*titleFont: -*-helvetica-medium-r-normal-*-180-*\n" \
# define refresh_engine 0
# include "xlockmore.h" /* from the xscreensaver distribution */
#define DEF_ENGINE "(none)"
#define DEF_TITLES "False"
#define DEF_SPIN "True"
-#define DEF_WANDER "True"
+#define DEF_MOVE "True"
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
static argtype vars[] = {
{&which_engine, "engine", "Engine", DEF_ENGINE, t_String},
- {&move, "move", "Move", DEF_WANDER, t_Bool},
+ {&move, "move", "Move", DEF_MOVE, t_Bool},
{&spin, "spin", "Spin", DEF_SPIN, t_Bool},
{&do_titles, "titles", "Titles", DEF_TITLES, t_Bool},
};
rotator *rot;
trackball_state *trackball;
Bool button_down_p;
+# ifdef HAVE_GLBITMAP
XFontStruct *xfont;
GLuint font_dlist;
+# else
+ texture_font_data *font_data;
+# endif
char *engine_name;
int engineType;
int movepaused;
int ln_init;
int lastPlug;
+ GLuint shaft_list, piston_list;
+ int shaft_polys, piston_polys;
+
} Engine;
static Engine *engine = NULL;
/* for a tube, endcaps is 0 (none), 1 (left), 2 (right) or 3(both) */
/* angle is how far around the axis to go (up to 360) */
-static void cylinder (Engine *e, GLfloat x, GLfloat y, GLfloat z,
+static int cylinder (Engine *e, GLfloat x, GLfloat y, GLfloat z,
float length, float outer, float inner, int endcaps, int sang, int eang)
{
+ int polys = 0;
int a; /* current angle around cylinder */
int b = 0; /* previous */
int angle, norm, step, sangle;
float z1, y1, z2, y2, ex=0;
- float y3, z3;
- float Z1, Y1, Z2, Y2, xl, Y3, Z3;
+ float Z1, Y1, Z2, Y2, xl;
GLfloat y2c[TWOREV], z2c[TWOREV];
- GLfloat ony, onz; /* previous normals */
int nsegs, tube = 0;
glPushMatrix();
nsegs += 1;
sangle = sang;
angle = eang;
- ony = onz = 0;
z1 = e->cos_table[sangle]*outer+z; y1 = e->sin_table[sangle] * outer+y;
Z1 = e->cos_table[sangle] * inner+z; Y1 = e->sin_table[sangle]*inner+y ;
Z2 = z;
for (a = sangle ; a <= angle || b <= angle ; a+= step) {
y2=outer*(float)e->sin_table[a]+y;
z2=outer*(float)e->cos_table[a]+z;
- y3=outer*(float)e->sin_table[a+step]+y;
- z3=outer*(float)e->cos_table[a+step]+z;
if (endcaps)
y2c[a] = y2; z2c[a] = z2; /* cache for later */
if (tube) {
Y2=inner*(float)e->sin_table[a]+y;
Z2=inner*(float)e->cos_table[a]+z;
- Y3=inner*(float)e->sin_table[a+step]+y;
- Z3=inner*(float)e->cos_table[a+step]+z;
}
glNormal3f(0, y1, z1);
glVertex3f(x,y1,z1);
glNormal3f(0, y2, z2);
glVertex3f(xl,y2,z2);
glVertex3f(x,y2,z2);
+ polys++;
if (a == sangle && angle - sangle < ONEREV) {
if (tube)
glVertex3f(x, Y1, Z1);
glVertex3f(xl, Z1, Z1);
else
glVertex3f(xl, y, z);
+ polys++;
}
if (tube) {
if (endcaps != 1) {
glVertex3f(x, y2, z2);
glVertex3f(x, Y2, Z2);
glVertex3f(x, Y1, Z1);
+ polys++;
}
glNormal3f(0, -Y1, -Z1); /* inner surface */
glNormal3f(0, -Y2, -Z2);
glVertex3f(xl, Y2, Z2);
glVertex3f(x, Y2, Z2);
+ polys++;
if (endcaps != 2) {
glNormal3f(1, 0, 0); /* right end */
glVertex3f(xl, y2, z2);
glVertex3f(xl, Y2, Z2);
glVertex3f(xl, Y1, Z1);
+ polys++;
}
}
glVertex3f(x, y1, z1);
glVertex3f(xl, y1, z1);
glVertex3f(xl, y, z);
+ polys++;
glEnd();
}
if (endcaps) {
glVertex3f(x+ex,y, z);
glVertex3f(x+ex,y1,z1);
glVertex3f(x+ex,y2c[a],z2c[a]);
+ polys++;
y1 = y2c[a]; z1 = z2c[a];
b = a;
}
}
}
glPopMatrix();
+ return polys;
}
/* this is just a convenience function to make a solid rod */
-static void rod (Engine *e, GLfloat x, GLfloat y, GLfloat z, float length, float diameter)
+static int rod (Engine *e, GLfloat x, GLfloat y, GLfloat z, float length, float diameter)
{
- cylinder(e, x, y, z, length, diameter, diameter, 3, 0, ONEREV);
+ return cylinder(e, x, y, z, length, diameter, diameter, 3, 0, ONEREV);
}
static GLvoid normal(GLfloat v1[], GLfloat v2[], GLfloat v3[],
-static void Rect(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h,
+static int Rect(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h,
GLfloat t)
{
+ int polys = 0;
GLfloat yh;
GLfloat xw;
GLfloat zt;
glVertex3f(x, yh, z);
glVertex3f(xw, yh, z);
glVertex3f(xw, y, z);
+ polys++;
/* back */
glNormal3f(0, 0, -1);
glVertex3f(x, y, zt);
glVertex3f(x, yh, zt);
glVertex3f(xw, yh, zt);
glVertex3f(xw, y, zt);
+ polys++;
/* top */
glNormal3f(0, 1, 0);
glVertex3f(x, yh, z);
glVertex3f(x, yh, zt);
glVertex3f(xw, yh, zt);
glVertex3f(xw, yh, z);
+ polys++;
/* bottom */
glNormal3f(0, -1, 0);
glVertex3f(x, y, z);
glVertex3f(x, y, zt);
glVertex3f(xw, y, zt);
glVertex3f(xw, y, z);
+ polys++;
/* left */
glNormal3f(-1, 0, 0);
glVertex3f(x, y, z);
glVertex3f(x, y, zt);
glVertex3f(x, yh, zt);
glVertex3f(x, yh, z);
+ polys++;
/* right */
glNormal3f(1, 0, 0);
glVertex3f(xw, y, z);
glVertex3f(xw, y, zt);
glVertex3f(xw, yh, zt);
glVertex3f(xw, yh, z);
+ polys++;
glEnd();
+ return polys;
}
-static void makepiston(Engine *e)
+static int makepiston(Engine *e)
{
+ int polys = 0;
GLfloat colour[] = {0.6, 0.6, 0.6, 1.0};
- int i;
- i = glGenLists(1);
- glNewList(i, GL_COMPILE);
+ e->piston_list = glGenLists(1);
+ glNewList(e->piston_list, GL_COMPILE);
glRotatef(90, 0, 0, 1);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colour);
glMaterialfv(GL_FRONT, GL_SPECULAR, colour);
glMateriali(GL_FRONT, GL_SHININESS, 20);
- cylinder(e, 0, 0, 0, 2, 1, 0.7, 2, 0, ONEREV); /* body */
+ polys += cylinder(e, 0, 0, 0, 2, 1, 0.7, 2, 0, ONEREV); /* body */
colour[0] = colour[1] = colour[2] = 0.2;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colour);
- cylinder(e, 1.6, 0, 0, 0.1, 1.05, 1.05, 0, 0, ONEREV); /* ring */
- cylinder(e, 1.8, 0, 0, 0.1, 1.05, 1.05, 0, 0, ONEREV); /* ring */
+ polys += cylinder(e, 1.6, 0, 0, 0.1, 1.05, 1.05, 0, 0, ONEREV); /* ring */
+ polys += cylinder(e, 1.8, 0, 0, 0.1, 1.05, 1.05, 0, 0, ONEREV); /* ring */
glEndList();
+ return polys;
}
-static void CrankBit(Engine *e, GLfloat x)
+static int CrankBit(Engine *e, GLfloat x)
{
- Rect(x, -1.4, 0.5, 0.2, 1.8, 1);
- cylinder(e, x, -0.5, 0, 0.2, 2, 2, 1, 60, 120);
+ int polys = 0;
+ polys += Rect(x, -1.4, 0.5, 0.2, 1.8, 1);
+ polys += cylinder(e, x, -0.5, 0, 0.2, 2, 2, 1, 60, 120);
+ return polys;
}
-static void boom(Engine *e, GLfloat x, GLfloat y, int s)
+static int boom(Engine *e, GLfloat x, GLfloat y, int s)
{
+ int polys = 0;
int flameOut = 720/ENG.speed/ENG.cylinders;
if (e->boom_time == 0 && s) {
e->boom_time++;
glEnable(GL_LIGHT1);
} else if (e->boom_time == 0 && !s) {
- return;
+ return polys;
} else if (e->boom_time >= 8 && e->boom_time < flameOut && !s) {
e->boom_time++;
e->boom_red[0] -= 0.2; e->boom_red[1] -= 0.1;
} else if (e->boom_time >= flameOut) {
e->boom_time = 0;
glDisable(GL_LIGHT1);
- return;
+ return polys;
} else {
e->boom_red[0] += 0.2; e->boom_red[1] += 0.1;
e->boom_d += 0.04;
glLightfv(GL_LIGHT1, GL_POSITION, e->boom_lpos);
glLightfv(GL_LIGHT1, GL_DIFFUSE, e->boom_red);
glLightfv(GL_LIGHT1, GL_SPECULAR, e->boom_red);
- glLighti(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.3);
+ glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.3);
glLighti(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, e->boom_red);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- rod(e, x, y, 0, e->boom_d, e->boom_wd);
+ polys += rod(e, x, y, 0, e->boom_d, e->boom_wd);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
+ return polys;
}
-static void display(Engine *e)
+static int display(Engine *e)
{
+ int polys = 0;
GLfloat zb, yb;
float rightSide;
int half;
e->lookat[0], e->lookat[1], e->lookat[2],
0.0, 1.0, 0.0);
glPushMatrix();
+
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_sp);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_sp);
get_position (e->rot, &x, &y, &z, !e->button_down_p);
glTranslatef(x*16-9, y*14-7, z*16-10);
}
+
if (spin) {
double x, y, z;
+
+ /* Do it twice because we don't track the device's orientation. */
+ glRotatef( current_device_rotation(), 0, 0, 1);
gltrackball_rotate (e->trackball);
+ glRotatef(-current_device_rotation(), 0, 0, 1);
+
get_rotation(e->rot, &x, &y, &z, !e->button_down_p);
glRotatef(x*ONEREV, 1.0, 0.0, 0.0);
glRotatef(y*ONEREV, 0.0, 1.0, 0.0);
/* crankshaft */
glPushMatrix();
glRotatef(e->display_a, 1, 0, 0);
- glCallList(1);
+ glCallList(e->shaft_list);
+ polys += e->shaft_polys;
glPopMatrix();
/* init the ln[] matrix for speed */
b = (e->display_a + ENG.pistonAngle[j+half]) % ONEREV;
glPushMatrix();
glTranslatef(e->crankWidth/2 + e->crankOffset*(j+half), e->yp[b]-0.3, 0);
- glCallList(2);
+ glCallList(e->piston_list);
+ polys += e->piston_polys;
glPopMatrix();
}
/* spark plugs */
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
for (j = 0; j < ENG.cylinders; j += sides)
{
- cylinder(e, 8.5, -e->crankWidth/2-e->crankOffset*(j+half), 0,
+ polys += cylinder(e, 8.5, -e->crankWidth/2-e->crankOffset*(j+half), 0,
0.5, 0.4, 0.3, 1, 0, ONEREV);
}
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
for (j = 0; j < ENG.cylinders; j += sides)
{
- rod(e, 8, -e->crankWidth/2-e->crankOffset*(j+half), 0, 0.5, 0.2);
- rod(e, 9, -e->crankWidth/2-e->crankOffset*(j+half), 0, 1, 0.15);
+ polys += rod(e, 8, -e->crankWidth/2-e->crankOffset*(j+half), 0, 0.5, 0.2);
+ polys += rod(e, 9, -e->crankWidth/2-e->crankOffset*(j+half), 0, 1, 0.15);
}
/* rod */
b = (e->display_a+HALFREV+ENG.pistonAngle[j+half]) % TWOREV;
glPushMatrix();
glRotatef(e->ang[b], 0, 1, 0);
- rod(e,
+ polys += rod(e,
-e->cos_table[b],
-e->crankWidth/2-e->crankOffset*(j+half),
-e->sin_table[b],
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
rightSide = (sides > 1) ? 0 : 1.6;
/* left plate */
- Rect(-e->crankWidth/2, -0.5, 1, 0.2, 9, 2);
+ polys += Rect(-e->crankWidth/2, -0.5, 1, 0.2, 9, 2);
/* right plate */
- Rect(0.3+e->crankOffset*ENG.cylinders-rightSide, -0.5, 1, 0.2, 9, 2);
+ polys += Rect(0.3+e->crankOffset*ENG.cylinders-rightSide, -0.5, 1, 0.2, 9, 2);
/* head plate */
- Rect(-e->crankWidth/2+0.2, 8.3, 1,
+ polys += Rect(-e->crankWidth/2+0.2, 8.3, 1,
e->crankWidth/2+0.1+e->crankOffset*ENG.cylinders-rightSide, 0.2, 2);
/* front rail */
- Rect(-e->crankWidth/2+0.2, 3, 1,
+ polys += Rect(-e->crankWidth/2+0.2, 3, 1,
e->crankWidth/2+0.1+e->crankOffset*ENG.cylinders-rightSide, 0.2, 0.2);
/* back rail */
- Rect(-e->crankWidth/2+0.2, 3, -1+0.2,
+ polys += Rect(-e->crankWidth/2+0.2, 3, -1+0.2,
e->crankWidth/2+0.1+e->crankOffset*ENG.cylinders-rightSide, 0.2, 0.2);
/* plates between cylinders */
for (j=0; j < ENG.cylinders - (sides == 1); j += sides)
- Rect(0.4+e->crankWidth+e->crankOffset*(j-half), 3, 1, 1, 5.3, 2);
+ polys += Rect(0.4+e->crankWidth+e->crankOffset*(j-half), 3, 1, 1, 5.3, 2);
glDepthMask(GL_TRUE);
}
glPopMatrix();
if (j & 1)
glRotatef(ENG.includedAngle,1,0,0);
glRotatef(90, 0, 0, 1);
- boom(e, 8, -e->crankWidth/2-e->crankOffset*j, 1);
+ polys += boom(e, 8, -e->crankWidth/2-e->crankOffset*j, 1);
e->lastPlug = j;
glPopMatrix();
}
if (e->lastPlug & 1)
glRotatef(ENG.includedAngle, 1, 0, 0);
glRotatef(90, 0, 0, 1);
- boom(e, 8, -e->crankWidth/2-e->crankOffset*e->lastPlug, 0);
+ polys += boom(e, 8, -e->crankWidth/2-e->crankOffset*e->lastPlug, 0);
}
glDisable(GL_BLEND);
e->display_a = 0;
glPopMatrix();
glFlush();
+ return polys;
}
-static void makeshaft (Engine *e)
+static int makeshaft (Engine *e)
{
- int i;
+ int polys = 0;
int j;
float crankThick = 0.2;
float crankDiam = 0.3;
- i = glGenLists(1);
- glNewList(i, GL_COMPILE);
+ e->shaft_list = glGenLists(1);
+ glNewList(e->shaft_list, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
/* draw the flywheel */
- cylinder(e, -2.5, 0, 0, 1, 3, 2.5, 0, 0, ONEREV);
- Rect(-2, -0.3, 2.8, 0.5, 0.6, 5.6);
- Rect(-2, -2.8, 0.3, 0.5, 5.6, 0.6);
+ polys += cylinder(e, -2.5, 0, 0, 1, 3, 2.5, 0, 0, ONEREV);
+ polys += Rect(-2, -0.3, 2.8, 0.5, 0.6, 5.6);
+ polys += Rect(-2, -2.8, 0.3, 0.5, 5.6, 0.6);
/* now make each of the shaft bits between the cranks,
* starting from the flywheel end which is at X-coord 0.
* the first cranskhaft bit is always 2 units long
*/
- rod(e, -2, 0, 0, 2, crankDiam);
+ polys += rod(e, -2, 0, 0, 2, crankDiam);
/* Each crank is crankWidth units wide and the total width of a
* cylinder assembly is 3.3 units. For inline engines, there is just
if (ENG.includedAngle != 0)
e->crankOffset /= 2;
for (j = 0; j < ENG.cylinders - 1; j++)
- rod(e,
+ polys += rod(e,
e->crankWidth - crankThick + e->crankOffset*j, 0, 0,
e->crankOffset - e->crankWidth + 2 * crankThick, crankDiam);
/* the last bit connects to the engine wall on the non-flywheel end */
- rod(e, e->crankWidth - crankThick + e->crankOffset*j, 0, 0, 0.9, crankDiam);
+ polys += rod(e, e->crankWidth - crankThick + e->crankOffset*j, 0, 0, 0.9, crankDiam);
for (j = 0; j < ENG.cylinders; j++)
glRotatef(HALFREV+ENG.pistonAngle[j],1,0,0);
/* draw wrist pin */
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
- rod(e, e->crankOffset*j, -1.0, 0.0, e->crankWidth, crankDiam);
+ polys += rod(e, e->crankOffset*j, -1.0, 0.0, e->crankWidth, crankDiam);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
/* draw right part of crank */
- CrankBit(e, e->crankOffset*j);
+ polys += CrankBit(e, e->crankOffset*j);
/* draw left part of crank */
- CrankBit(e, e->crankWidth-crankThick+e->crankOffset*j);
+ polys += CrankBit(e, e->crankWidth-crankThick+e->crankOffset*j);
glPopMatrix();
}
glEndList();
+ return polys;
}
} else {
MI_CLEARWINDOW(mi);
}
- glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable(GL_DEPTH_TEST);
(engines[e->engineType].includedAngle == 0 ? " Cylinder" : "")
);
- makeshaft(e);
- makepiston(e);
+ e->shaft_polys = makeshaft(e);
+ e->piston_polys = makepiston(e);
+
+#ifdef HAVE_GLBITMAP
load_font (mi->dpy, "titleFont", &e->xfont, &e->font_dlist);
+#else
+ e->font_data = load_texture_font (mi->dpy, "Font");
+#endif
}
ENTRYPOINT Bool
}
else if (event->xany.type == ButtonPress &&
(event->xbutton.button == Button4 ||
- event->xbutton.button == Button5))
+ event->xbutton.button == Button5 ||
+ event->xbutton.button == Button6 ||
+ event->xbutton.button == Button7))
{
gltrackball_mousewheel (e->trackball, event->xbutton.button, 10,
!!event->xbutton.state);
glXMakeCurrent(disp, w, *(e->glx_context));
- display(e);
+ mi->polygon_count = display(e);
+ glColor3f (1, 1, 0);
if (do_titles)
- print_gl_string (mi->dpy, e->xfont, e->font_dlist,
+ print_gl_string (mi->dpy,
+# ifdef HAVE_GLBITMAP
+ e->xfont, e->font_dlist,
+# else
+ e->font_data,
+# endif
mi->xgwa.width, mi->xgwa.height,
10, mi->xgwa.height - 10,
- e->engine_name);
+ e->engine_name, False);
if(mi->fps_p) do_fps(mi);
glFinish();