The matrix stack is really pretty simple. Mojo draws objects based on the values ix, iy, jx, jy, tx, and ty, stored in the global context variable. When you push the stack, it takes those variables and stores them in the matrix, but continues using them to draw objects to a position. So when you Translate, Rotate, or Scale, all it does is add to those variables values. When it "Pops", it takes the matrix saved during the push and puts them in the ix, iy, jx, jy, tx, and ty variables.
From mojo.graphics
Function SetMatrix( ix#,iy#,jx#,jy#,tx#,ty# )
context.ix=ix
context.iy=iy
context.jx=jx
context.jy=jy
context.tx=tx
context.ty=ty
context.tformed=(ix<>1 Or iy<>0 Or jx<>0 Or jy<>1 Or tx<>0 Or ty<>0)
context.matDirty=1
End
Function GetMatrix#[]()
Return [context.ix,context.iy,context.jx,context.jy,context.tx,context.ty]
End
Function PushMatrix()
Local sp=context.matrixSp
context.matrixStack[sp+0]=context.ix
context.matrixStack[sp+1]=context.iy
context.matrixStack[sp+2]=context.jx
context.matrixStack[sp+3]=context.jy
context.matrixStack[sp+4]=context.tx
context.matrixStack[sp+5]=context.ty
context.matrixSp=sp+6
End
Function PopMatrix()
Local sp=context.matrixSp-6
SetMatrix context.matrixStack[sp+0],context.matrixStack[sp+1],
context.matrixStack[sp+2],context.matrixStack[sp+3],
context.matrixStack[sp+4],context.matrixStack[sp+5]
context.matrixSp=sp
End
Function Transform( ix#,iy#,jx#,jy#,tx#,ty# )
Local ix2#=ix*context.ix+iy*context.jx
Local iy2#=ix*context.iy+iy*context.jy
Local jx2#=jx*context.ix+jy*context.jx
Local jy2#=jx*context.iy+jy*context.jy
Local tx2#=tx*context.ix+ty*context.jx+context.tx
Local ty2#=tx*context.iy+ty*context.jy+context.ty
SetMatrix ix2,iy2,jx2,jy2,tx2,ty2
End
|