static void move_squid (ModeInfo *mi, squid *sq) { hydrostat_configuration *bp = &bps[MI_SCREEN(mi)]; GLfloat step = M_PI * 2 / sq->ntentacles; int i; GLfloat radius = head_radius_arg; GLfloat r; /* Move to a new position */ if (! bp->button_down_p) { sq->ratio += speed_arg * 0.01; if (sq->ratio >= 1) { sq->ratio = -(frand(2.0) + frand(2.0) + frand(2.0)); sq->from.x = sq->to.x; sq->from.y = sq->to.y; sq->from.z = sq->to.z; sq->to.x = 250 - frand(500); sq->to.y = 250 - frand(500); sq->to.z = 250 - frand(500); } r = sq->ratio > 0 ? ease_ratio (sq->ratio) : 0; sq->pos.x = sq->from.x + r * (sq->to.x - sq->from.x); sq->pos.y = sq->from.y + r * (sq->to.y - sq->from.y); sq->pos.z = sq->from.z + r * (sq->to.z - sq->from.z); } if (do_pulse) { GLfloat p = pow (sin (sq->pulse * M_PI), 18); sq->head_radius = (head_radius_arg * 0.7 + head_radius_arg * 0.3 * p); radius = sq->head_radius * 0.25; sq->pulse += sq->rate * speed_arg * 0.02; if (sq->pulse > 1) sq->pulse = 0; } for (i = 0; i < sq->ntentacles; i++) { tentacle *tt = &sq->tentacles[i]; GLfloat th = i * step; GLfloat px = cos (th) * radius; GLfloat py = sin (th) * radius; tt->th = th; tt->nodes[0].pos.x = sq->pos.x + px; tt->nodes[0].pos.y = sq->pos.y + py; tt->nodes[0].pos.z = sq->pos.z; move_tentacle (sq, tt); } }
static void tick_oscillators (ModeInfo *mi) { cube_configuration *bp = &bps[MI_SCREEN(mi)]; oscillator *prev = 0; oscillator *a = bp->oscillators; GLfloat tick = 0.1 / speed; while (a) { oscillator *next = a->next; a->ratio += tick * a->speed; if (a->ratio > 1) a->ratio = 1; *a->var = a->from + (a->to - a->from) * ease_ratio (a->ratio); if (a->ratio < 1) /* mid cycle */ prev = a; else if (--a->remaining <= 0) /* ended, and expired */ { if (prev) prev->next = next; else bp->oscillators = next; free (a); } else /* keep going the other way */ { GLfloat swap = a->from; a->from = a->to; a->to = swap; a->ratio = 0; prev = a; } a = next; } }
ENTRYPOINT void draw_planet (ModeInfo * mi) { planetstruct *gp = &planets[MI_SCREEN(mi)]; int wire = MI_IS_WIREFRAME(mi); Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); double x, y, z; if (!gp->glx_context) return; glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glXMakeCurrent (dpy, window, *(gp->glx_context)); mi->polygon_count = 0; if (! gp->button_down_p) switch (gp->state) { case STARTUP: gp->ratio += speed * 0.01; break; case FLAT: gp->ratio += speed * 0.005; break; case FOLD: gp->ratio += speed * 0.01; break; case ICO: gp->ratio += speed * 0.01; break; case STEL_IN: gp->ratio += speed * 0.05; break; case STEL: gp->ratio += speed * 0.01; break; case STEL_OUT: gp->ratio += speed * 0.07; break; case ICO2: gp->ratio += speed * 0.07; break; case AXIS: gp->ratio += speed * 0.02; break; case SPIN: gp->ratio += speed * 0.005; break; case UNFOLD: gp->ratio += speed * 0.01; break; default: abort(); } if (gp->ratio > 1.0) { gp->ratio = 0; switch (gp->state) { case STARTUP: gp->state = FLAT; break; case FLAT: gp->state = FOLD; break; case FOLD: gp->state = ICO; break; case ICO: gp->state = STEL_IN; break; case STEL_IN: gp->state = STEL; break; case STEL: { int i = (random() << 9) % 7; gp->state = (i < 3 ? STEL_OUT : i < 6 ? SPIN : AXIS); } break; case AXIS: gp->state = STEL_OUT; break; case SPIN: gp->state = STEL_OUT; break; case STEL_OUT: gp->state = ICO2; break; case ICO2: gp->state = UNFOLD; break; case UNFOLD: gp->state = FLAT; break; default: abort(); } } glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glPushMatrix(); gltrackball_rotate (gp->trackball); glRotatef (current_device_rotation(), 0, 0, 1); if (gp->state != STARTUP) { get_position (gp->rot, &x, &y, &z, !gp->button_down_p); x = (x - 0.5) * 3; y = (y - 0.5) * 3; z = 0; glTranslatef(x, y, z); } if (do_roll && gp->state != STARTUP) { get_rotation (gp->rot, &x, &y, 0, !gp->button_down_p); glRotatef (x * 360, 1.0, 0.0, 0.0); glRotatef (y * 360, 0.0, 1.0, 0.0); } if (do_stars) { glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glPushMatrix(); glScalef (60, 60, 60); glRotatef (90, 1, 0, 0); glRotatef (35, 1, 0, 0); glCallList (gp->starlist); mi->polygon_count += gp->starcount; glPopMatrix(); glClear(GL_DEPTH_BUFFER_BIT); } if (! wire) glEnable (GL_LIGHTING); if (do_texture) glEnable(GL_TEXTURE_2D); glScalef (2.6, 2.6, 2.6); { GLfloat fold_ratio = 0; GLfloat stel_ratio = 0; switch (gp->state) { case FOLD: fold_ratio = gp->ratio; break; case UNFOLD: fold_ratio = 1 - gp->ratio; break; case ICO: case ICO2: fold_ratio = 1; break; case STEL: case AXIS: case SPIN: fold_ratio = 1; stel_ratio = 1; break; case STEL_IN: fold_ratio = 1; stel_ratio = gp->ratio; break; case STEL_OUT: fold_ratio = 1; stel_ratio = 1 - gp->ratio; break; case STARTUP: /* Tilt in from flat */ glRotatef (-90 * ease_ratio (1 - gp->ratio), 1, 0, 0); break; default: break; } # ifdef HAVE_MOBILE /* Enlarge the icosahedron a bit to make it more visible */ { GLfloat s = 1 + 1.3 * ease_ratio (fold_ratio); glScalef (s, s, s); } # endif if (gp->state == SPIN) { align_axis (mi, 0); glRotatef (ease_ratio (gp->ratio) * 360 * 3, 0, 0, 1); align_axis (mi, 1); } draw_triangles (mi, ease_ratio (fold_ratio), ease_ratio (stel_ratio)); if (gp->state == AXIS) draw_axis(mi); } glPopMatrix(); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }