is this a bug?

Monkey Forums/Monkey Programming/is this a bug?

slenkar(Posted 2011) [#1]


if you press the arrow keys you move the limbs and the line will be drawn between the two legs

in this next version the line is being drawn in between the push and popmatrix and is drawn off the screen (ie the wrong place)


if I understand correctly arent the push and pop matrix commands supposed to push an identity stack onto the matrix and then pop it off?
the line is being drawn as if I never used push and pop at all (in the second example)


AdamRedwoods(Posted 2011) [#2]
PushMatrix() PopMatrix()
Push and pop the currently used matrix on/off the stack, not necessarily the identity matrix.

The identity matrix is:
SetMatrix(1,0,0,1,0,0)


slenkar(Posted 2011) [#3]
im a little confused now about the matrix stack
thanks for the identity matrix idea


Goodlookinguy(Posted 2011) [#4]
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



slenkar(Posted 2011) [#5]
ah ok, I was thinking that the top of the stack was used, but its actually something seperate that gets rendered, i fixed the problem now thanks