Also, there are a few slots available for CS graphics students interested in seeing a small talk given here at NYU by Jeffrey Katzenberg on Oct 30 at 8:30am. Please send me an email if you would like to attend this event.
int topPointer = 0; Matrix matrixStack[] = new Matrix[STACK_SIZE_LIMIT];The
push
and pop
methods are easy to implement:
void push() { matrixStack[topPointer+1].copy(matriStack[topPointer]); topPointer++; // YOU SHOULD DO ERROR CHECKING HERE FOR STACK OVERFLOW } void pop() { topPointer--; // YOU SHOULD DO ERROR CHECKING HERE FOR STACK UNDERFLOW }You probably also want an access routine to make it easy to refer to the matrix that is currently on top of the stack:
// MATRIX STACK ACCESS ROUTINE FOR USE WITH translate(), rotateX(), .... Matrix m() { return matrixStack[topPointer]; }At every animation frame you'll want to reset your matrix stack to a clean state:
void initializeMatrixStackForAnimationFrame() { topPointer = 0; m().identity(); }
x → (-f / z) x
y → (-f / z) y
z → (-f / z)
We know that this is a linear transformation (ie: it preserves straight lines) because this perspective transformation can be effected by a 4×4 linear transformation matrix:
This is because
P =
1 0 0 0 0 1 0 0 0 0 0 1 0 0 -1/f 0
P [x,y,z,1]T (where the 'T' superscript denotes transpose, because this is a column vector)
[x,y,1,-z/f]T.Dividing through by the homogeneous coordinate (-z/f) gives
[(-f/z)x,(-f/z)y,(-f/z),1]T.