+/* Originally, this program achieved the "accumulating cubes" effect by
+ simply not clearing the depth or color buffers between frames. That
+ doesn't work on modern systems, particularly mobile: you can no longer
+ rely on your buffers being unmolested once you have yielded. So now we
+ must save and re-render every polygon. Noof has the same problem and
+ solves it by taking a screenshot of the frame buffer into a texture, but
+ cubestorm needs to restore the depth buffer as well as the color buffer.
+ */
+static void
+push_hist (ModeInfo *mi)
+{
+ cube_configuration *bp = &bps[MI_SCREEN(mi)];
+ double px, py, pz;
+ double rx = 0, ry = 0, rz = 0;
+ int i;
+
+ if (bp->hist_count > max_length &&
+ bp->hist_count > MI_COUNT(mi) &&
+ !bp->button_down_p)
+ {
+ /* Drop history off of the end. */
+ memmove (bp->hist,
+ bp->hist + MI_COUNT(mi),
+ (bp->hist_count - MI_COUNT(mi)) * sizeof(*bp->hist));
+ bp->hist_count -= MI_COUNT(mi);
+ }
+
+ if (bp->hist_count + MI_COUNT(mi) >= bp->hist_size)
+ {
+ bp->hist_size = bp->hist_count + MI_COUNT(mi) + 100;
+ bp->hist = (histcube *)
+ realloc (bp->hist, bp->hist_size * sizeof(*bp->hist));
+ }
+
+ get_position (bp->subcubes[0].rot, &px, &py, &pz, !bp->button_down_p);
+
+ for (i = 0; i < MI_COUNT(mi); i++)
+ {
+ subcube *sc = &bp->subcubes[i];
+ histcube *hc = &bp->hist[bp->hist_count];
+ double rx2, ry2, rz2;
+
+ get_rotation (sc->rot, &rx2, &ry2, &rz2, !bp->button_down_p);
+
+ if (i == 0) /* N+1 cubes rotate relative to cube 0 */
+ rx = rx2, ry = ry2, rz = rz2;
+ else
+ rx2 += rx, ry2 += ry, rz2 += rz;
+
+ hc->px = px;
+ hc->py = py;
+ hc->pz = pz;
+ hc->rx = rx2;
+ hc->ry = ry2;
+ hc->rz = rz2;
+ hc->ccolor = sc->ccolor;
+ sc->ccolor++;
+ if (sc->ccolor >= bp->ncolors)
+ sc->ccolor = 0;
+ bp->hist_count++;
+ }
+}
+
+