static void tick_floater (ModeInfo *mi, floater *f) { cow_configuration *bp = &bps[MI_SCREEN(mi)]; if (bp->button_down_p) return; f->dx += f->ddx; f->dy += f->ddy; f->dz += f->ddz; f->x += f->dx * speed; f->y += f->dy * speed; f->z += f->dz * speed; if (f->y < -BOTTOM || f->x < -BOTTOM*8 || f->x > BOTTOM*8 || f->z < -BOTTOM*8 || f->z > BOTTOM*8) reset_floater (mi, f); }
static void tick_floater (ModeInfo *mi, floater *f) { toaster_configuration *bp = &bps[MI_SCREEN(mi)]; GLfloat n1 = GRID_DEPTH/2.0; GLfloat n2 = GRID_SIZE*4; if (bp->button_down_p) return; f->x += f->dx; f->y += f->dy; f->z += f->dz; if (! (random() % 50000)) /* sudden gust of gravity */ f->dy -= 2.8; if (f->x < -n2 || f->x > n2 || f->y < -n2 || f->y > n2 || f->z > n1) reset_floater (mi, f); }
static void tick_floater (ModeInfo *mi, floater *f) { cube_configuration *bp = &bps[MI_SCREEN(mi)]; if (bp->button_down_p) return; if (do_spin || do_wander) return; f->dx += f->ddx; f->dy += f->ddy; f->dz += f->ddz; f->x += f->dx * speed * SPEED_SCALE; f->y += f->dy * speed * SPEED_SCALE; f->z += f->dz * speed * SPEED_SCALE; if (f->y < -BOTTOM || f->x < -BOTTOM*8 || f->x > BOTTOM*8 || f->z < -BOTTOM*8 || f->z > BOTTOM*8) reset_floater (mi, f); }
ENTRYPOINT void init_toasters (ModeInfo *mi) { toaster_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { bps = (toaster_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (toaster_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_toasters (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } if (!wire && do_texture) load_textures (mi); bp->user_trackball = gltrackball_init (); auto_track_init (mi); bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef (-90, 1, 0, 0); glRotatef (180, 0, 0, 1); glScalef (6, 6, 6); glBindTexture (GL_TEXTURE_2D, 0); if (i == BASE_TOASTER) { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); if (do_texture) glBindTexture (GL_TEXTURE_2D, bp->chrome_texture); # ifndef HAVE_JWZGLES glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); # endif } else if (i == TOAST || i == TOAST_BITTEN) { GLfloat color[4] = {0.80, 0.80, 0.00, 1.0}; GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0}; GLfloat shiny = 0.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); if (do_texture) glBindTexture (GL_TEXTURE_2D, bp->toast_texture); # ifndef HAVE_JWZGLES glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); # endif glMatrixMode(GL_TEXTURE); glTranslatef(0.5, 0.5, 0); glMatrixMode(GL_MODELVIEW); } else if (i == SLOTS || i == HANDLE_SLOT) { GLfloat color[4] = {0.30, 0.30, 0.40, 1.0}; GLfloat spec[4] = {0.40, 0.40, 0.70, 1.0}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == HANDLE) { GLfloat color[4] = {0.80, 0.10, 0.10, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == KNOB) { GLfloat color[4] = {0.80, 0.10, 0.10, 1.0}; GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0}; GLfloat shiny = 0.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == JET || i == JET_WING) { GLfloat color[4] = {0.70, 0.70, 0.70, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == BASE) { GLfloat color[4] = {0.50, 0.50, 0.50, 1.0}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 20.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } renderList (gll, wire); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEndList (); } bp->nfloaters = ntoasters + nslices; bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; /* arrange the list so that half the toasters are in front of bread, and half are behind. */ f->toaster_p = ((i < ntoasters / 2) || (i >= (nslices + (ntoasters / 2)))); reset_floater (mi, f); /* Position the first generation randomly, but make sure they aren't on screen yet (until we rotate the view into position.) */ { GLfloat min = -GRID_DEPTH/2; GLfloat max = GRID_DEPTH/3.5; f->z = frand (max - min) + min; } } }
ENTRYPOINT void init_cube (ModeInfo *mi) { cube_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { bps = (cube_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (cube_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_cube (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.7, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } bp->trackball = gltrackball_init (); bp->dlists = (GLuint *) calloc (countof(all_objs)+2, sizeof(GLuint)); for (i = 0; i < countof(all_objs)+1; i++) bp->dlists[i] = glGenLists (1); for (i = 0; i < countof(all_objs); i++) { const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); renderList (gll, wire); glEndList (); } glNewList (bp->dlists[i], GL_COMPILE); bp->cube_polys = build_cube (mi); glEndList (); bp->nfloaters = MI_COUNT (mi); bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; double spin_speed = do_spin ? 0.7 : 10; double wander_speed = do_wander ? 0.02 : 0.05 * speed * SPEED_SCALE; double spin_accel = 0.5; f->rot = make_rotator (spin_speed, spin_speed, spin_speed, spin_accel, wander_speed, True); if (bp->nfloaters == 2) { f->x = (i ? 2 : -2); } else if (i != 0) { double th = (i - 1) * M_PI*2 / (bp->nfloaters-1); double r = 3; f->x = r * cos(th); f->z = r * sin(th); } f->ix = f->x; f->iy = f->y; f->iz = f->z; reset_floater (mi, f); } }
ENTRYPOINT void init_cow (ModeInfo *mi) { cow_configuration *bp; int wire = MI_IS_WIREFRAME(mi); int i; Bool tex_p = False; MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_cow (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); if (!wire) { GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/ GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } bp->trackball = gltrackball_init (False); bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint)); for (i = 0; i < countof(all_objs); i++) bp->dlists[i] = glGenLists (1); tex_p = load_texture (mi, do_texture); if (tex_p) glBindTexture (GL_TEXTURE_2D, bp->texture); for (i = 0; i < countof(all_objs); i++) { GLfloat black[4] = {0, 0, 0, 1}; const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); glDisable (GL_TEXTURE_2D); if (i == HIDE) { GLfloat color[4] = {0.63, 0.43, 0.36, 1.00}; if (tex_p) { /* if we have a texture, make the base color be white. */ color[0] = color[1] = color[2] = 1.0; glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); /* approximately line it up with ../images/earth.png */ glMatrixMode (GL_TEXTURE); glLoadIdentity(); glTranslatef (0.45, 0.58, 0); glScalef (0.08, 0.16, 1); glRotatef (-5, 0, 0, 1); glMatrixMode (GL_MODELVIEW); } glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == TAIL) { GLfloat color[4] = {0.63, 0.43, 0.36, 1.00}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == UDDER) { GLfloat color[4] = {1.00, 0.53, 0.53, 1.00}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128); } else if (i == HOOFS || i == HORNS) { GLfloat color[4] = {0.20, 0.20, 0.20, 1.00}; GLfloat spec[4] = {0.30, 0.30, 0.30, 1.00}; GLfloat shiny = 8.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else if (i == FACE) { GLfloat color[4] = {0.10, 0.10, 0.10, 1.00}; GLfloat spec[4] = {0.10, 0.10, 0.10, 1.00}; GLfloat shiny = 8.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } else { GLfloat color[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat spec[4] = {1.00, 1.00, 1.00, 1.00}; GLfloat shiny = 128.0; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } renderList (gll, wire); glEndList (); } bp->nfloaters = MI_COUNT (mi); bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater)); for (i = 0; i < bp->nfloaters; i++) { floater *f = &bp->floaters[i]; f->rot = make_rotator (10.0, 0, 0, 4, 0.05 * speed, True); if (bp->nfloaters == 2) { f->x = (i ? 6 : -6); } else if (i != 0) { double th = (i - 1) * M_PI*2 / (bp->nfloaters-1); double r = 10; f->x = r * cos(th); f->z = r * sin(th); } f->ix = f->x; f->iy = f->y; f->iz = f->z; reset_floater (mi, f); } }