Matrix help please

Monkey Forums/Monkey Programming/Matrix help please

slenkar(Posted 2011) [#1]
Im trying to change the bouncyaliens demo so that all the aliens are simply rotated 90 degrees to the right, but are in the same position on the screen as they are supposed to be

this is my rendering code:
PushMatrix 
				
		Scale DeviceWidth/WIDTH,DeviceHeight/HEIGHT
		
		For Local sprite:=Eachin sprites
		Translate sprite.x,sprite.y
		 Rotate(90)
			DrawImage image,0,0,sprite.f
		Next
		
		PopMatrix


but the aliens dont behave as they did before my changes


Warpy(Posted 2011) [#2]
You need to do a PushMatrix/PopMatrix around each sprite.
PushMatrix 
	Scale DeviceWidth/WIDTH,DeviceHeight/HEIGHT
		
	For Local sprite:=Eachin sprites
		PushMatrix
		Translate sprite.x,sprite.y
		Rotate(90)
		DrawImage image,0,0,sprite.f
		PopMatrix
	Next		
PopMatrix



Canardian(Posted 2011) [#3]
In addition to Warpy, use also Rotate before Translate.


Warpy(Posted 2011) [#4]
no, that isn't what he wants to do


slenkar(Posted 2011) [#5]
thanks

BTW the matrix thingy is a bit confusing,

Im used to OpenGL where you do the identity matrix to reset everything

is this right?

-There is a stack of matrices

-The one on the top is used to affect drawing of images

-when you pop a matrix off you get a blank matrix (identity) if there are no other matrices on the stack,

-if you pushed one on the stack you get the next matrix when you pop
one off

please tell me which ones are wrong


Warpy(Posted 2011) [#6]
That's right.


slenkar(Posted 2011) [#7]
wha? that was a just guess - lol


Also it seems you have to push a matrix onto an empty stack or you get a crash when you try to draw something
(at least with HTML5)


Warpy(Posted 2011) [#8]
That shouldn't happen. Do you mean, if you pop the first matrix off the stack?


slenkar(Posted 2011) [#9]
yes

EDIT - Hmm I think the crash may have occured when I used pop on an empty stack

I like to test the limits of things before I use them properly