- /* Move in the direction we had been moving in. */
- gp->xpos += gp->dx;
- gp->ypos += gp->dy;
- gp->zpos += gp->dz;
-
- /* Bounce. */
- if (gp->xpos > gp->box_depth)
- gp->xpos = gp->box_depth, gp->dx = -gp->dx;
- else if (gp->xpos < 0)
- gp->xpos = 0, gp->dx = -gp->dx;
-
- if (gp->ypos > gp->box_width/2)
- gp->ypos = gp->box_width/2, gp->dy = -gp->dy;
- else if (gp->ypos < -gp->box_width/2)
- gp->ypos = -gp->box_width/2, gp->dy = -gp->dy;
-
- if (gp->zpos > gp->box_height/2)
- gp->zpos = gp->box_height/2, gp->dz = -gp->dz;
- else if (gp->zpos < -gp->box_height/2)
- gp->zpos = -gp->box_height/2, gp->dz = -gp->dz;
+ 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++;