3D Demo Player
3D Demo Player
During my studies at HAW-Hamburg I became a fan of the demoscene. Those are really impressive programming skills and stunning graphics that those guys are showing. So at a very long weekend Paul Litzbarski, Sven Tennstedt and I sat together to develop the tooling to create those stunnig demos ourselves. Paul was working on the Audio and Sven on the 3D rendering. I started to work on a GUI that would allow us to visually click together demos as Farbrausch is doing it with their “.werkzeug” aka “.theprodukkt”. So what I came up with was a GEF editor labeled “diePerspective”. But the intriguing part however was the player to play the generated trees. What you would usually come up with would be a recursion, but for performance reasons this was not an option here. So I came up with an algorithm to flatten the tree and run it iteratively.
public static void play(ModsJumps modsJumps, int frame) throws Exception {
final int[] jump = modsJumps.jump;
final IModule[] mod = modsJumps.mod;
final IModulator[][] modulator = modsJumps.modulator;
int pos = 0;
do {
int res = 0;
if (jump[pos] > 0) {
for (int i = 0; i < modulator[pos].length; i++) {
modulator[pos][i].updateModule(frame);
}
res = mod[pos].pre();
} else {
res = mod[pos].post();
}
if (res >= 0) {
pos++;
} else {
pos += jump[pos];
}
} while (jump[pos] != 0);
}
An IModule is a rendering Node. For example a translation (move of a 3D object) or a rotation. An IModulator can alter parameters of an IModule depending on the current frame. The jump table is the magic that enables an IModule to run as often as it wants, or skip itself entirely.