my guess is you're doing something like an L-System, right? if so, the trick is to implement a deep stack in your
logic rather than your
drawing. that is, the renderer doesn't really need to keep track of that much stack, but your "generator" perhaps does. so each "state" of your generator could have it's own instance of a PMatrix, for example, based on the parent state, giving you an arbitrarily deep stack, but you'd only need to apply and unapply any one matrix at a time as far as the renderer is concerned.
or if that's just too confusing a description :D... just implement your own deeper stack, for example:
- void setup() {
size(400,400,P3D);
// test that our stack is deeper than 32
for (int i=0; i<64; i++) pushMatrix();
for (int i=0; i<64; i++) popMatrix();
}
- int MY_MATRIX_STACK_DEPTH = 64;
int myMatrixStackDepth = 0;
float[][] myMatrixStack = new float[MY_MATRIX_STACK_DEPTH][16];
float[][] myMatrixInvStack = new float[MY_MATRIX_STACK_DEPTH][16];
// unfortunately, this hack only works in modelview mode, since
// we can't query for the current matrix mode (it has default
// access), so the projection mode/matrix maniupation is NOT supported...
//float[][] myPmatrixStack = new float[MY_MATRIX_STACK_DEPTH][16];
- void pushMatrix() {
if (myMatrixStackDepth == MY_MATRIX_STACK_DEPTH) {
throw new RuntimeException(ERROR_PUSHMATRIX_OVERFLOW);
}
PGraphics3D p3d = (PGraphics3D)g;
p3d.modelview.get(myMatrixStack[myMatrixStackDepth]);
p3d.modelviewInv.get(myMatrixInvStack[myMatrixStackDepth]);
myMatrixStackDepth++;
}
- void popMatrix() {
if (myMatrixStackDepth == 0) {
throw new RuntimeException(ERROR_PUSHMATRIX_UNDERFLOW);
}
myMatrixStackDepth--;
PGraphics3D p3d = (PGraphics3D)g;
p3d.modelview.set(myMatrixStack[myMatrixStackDepth]);
p3d.modelviewInv.set(myMatrixInvStack[myMatrixStackDepth]);
}