- /* return to original PROJECT and MODELVIEW */
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
-
-
- glEndList();
-
-}
-
-/* Set up lighting */
-static void
-init_sun (ModeInfo * mi)
-{
- GLfloat light[4];
- light[0] = frand(2.0) - 1.0;
- light[1] = frand(2.0) - 1.0;
- light[2] = 1.0;
- light[3] = 0;
-
- glLightfv(GL_LIGHT0, GL_POSITION, light);
-}
-
-
-/* Initialization function for screen saver */
-static void
-pinit(ModeInfo * mi)
-{
- Bool wire = MI_IS_WIREFRAME(mi);
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- if (wire) {
- glEnable(GL_LINE_SMOOTH);
- do_texture = False;
- }
-
- /* turn on various options we like */
- if (do_texture)
- setup_texture(mi);
- if (do_light)
- setup_light();
-
- setup_face();
-
- if (do_stars) {
- glEnable(GL_POINT_SMOOTH);
- generate_stars(MI_WIDTH(mi), MI_HEIGHT(mi));
- }
-
- gp->platelist=glGenLists(1);
- glNewList(gp->platelist, GL_COMPILE);
- glPushMatrix ();
- glScalef (RADIUS, RADIUS, RADIUS);
- unit_sphere (STACKS, SLICES, wire);
- glPopMatrix ();
- glEndList();
-
- init_sun (mi);
-}
-
-static void
-draw_sphere(ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- glEnable(GL_DEPTH_TEST);
-
- /* turn on the various attributes for making the sphere look nice */
- if (do_texture)
- glEnable(GL_TEXTURE_2D);
-
- if (do_light)
- {
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- }
-
- glCallList(gp->platelist);
-
-}
-
-
-#define RANDSIGN() ((random() & 1) ? 1 : -1)
-
-static void
-pick_velocity (ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- gp->box_width = 15.0;
- gp->box_height = 15.0;
- gp->box_depth = 5.0;
-
- gp->tx = 0.0;
- gp->ty = 0.0;
- gp->tz = frand(360);
-
- gp->dtx = (frand(0.4) + frand(0.3)) * RANDSIGN();
- gp->dty = (frand(0.4) + frand(0.3)) * RANDSIGN();
- gp->dtz = (frand(5.0) + frand(5.0)); /* the sun sets in the west */
-
- gp->dx = (frand(0.2) + frand(0.2)) * RANDSIGN();
- gp->dy = (frand(0.2) + frand(0.2)) * RANDSIGN();
- gp->dz = (frand(0.2) + frand(0.2)) * RANDSIGN();
-}
-
-
-static void
-rotate_and_move (ModeInfo * mi)
-{
- planetstruct *gp = &planets[MI_SCREEN(mi)];
-
- if (do_roll)
- {
- gp->tx += gp->dtx;
- while (gp->tx < 0) gp->tx += 360;
- while (gp->tx > 360) gp->tx -= 360;
-
- gp->ty += gp->dty;
- while (gp->ty < 0) gp->ty += 360;
- while (gp->ty > 360) gp->ty -= 360;
- }
-
- if (do_rotate)
- {
- gp->tz += gp->dtz;
- while (gp->tz < 0) gp->tz += 360;
- while (gp->tz > 360) gp->tz -= 360;
- }
-
- if (do_bounce)
- {
- static int frame = 0;
-# define SINOID(SCALE,SIZE) \
- ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)
- gp->xpos = SINOID(0.031, gp->box_width);
- gp->ypos = SINOID(0.023, gp->box_height);
- gp->zpos = SINOID(0.017, gp->box_depth);
- frame++;
- }