Matrix clarification?

Monkey Forums/Monkey Programming/Matrix clarification?

trinode(Posted 2011) [#1]
Now I thought the centre for rotation would be at 0,0, so to rotate my 128x128 image around it's centre I'd need to transform it so it was centred on 0,0 then rotate, then draw it so I wrote the following:-

PushMatrix()
SetMatrix(1,0,0,1,0,0)
Translate(-64,-64)
Rotate(angle)

DrawImage(img,0,0)

PopMatrix()

Can someone explain what I'm doing wrong? it's not rotating around it's centre :/ I would have expected it to be spinning half off the top left corner, but it's spinning of then back on to the screen.

Thanks,

- Anthony


slenkar(Posted 2011) [#2]
you have to set the handle to the center after you load the image

e.g.
local img:Image=LoadImage("img.png")
img.SetHandle(64,64)

and you could have a look at my matrix tutorial (in the tutorials section)


trinode(Posted 2011) [#3]
Thanks for the info, fyi the tutorial doesn't use sethandle, there's just a quick mention that you need to set the image handle (which I missed :))


trinode(Posted 2011) [#4]
ok, I broke it again...

loaded it like this:-
img=LoadImage("Ship.png")
img.SetHandle(64,64)

and drawing like this:-
angle+=1
PushMatrix()
SetMatrix(1,0,0,1,0,0)
Rotate(angle)
DrawImage(img,DeviceWidth/2,DeviceHeight/2)
PopMatrix()

I'm getting confused again ;)


slenkar(Posted 2011) [#5]
try translating to DeviceWidth/2,DeviceHeight/2
then rotating
then doing 'drawimage(img,0,0)'


trinode(Posted 2011) [#6]
That did it, it's like if you draw with a translation, the handle doesn't take that into account :/

so the handle was near the top left, the image in the middle, doing a big circle around the top left of the screen.


Jesse(Posted 2011) [#7]
you can simplify all that by doing it like this:

img=LoadImage("Ship.png")
img.SetHandle(64,64)

angle+=1
DrawImage(img,100,100,angle,1,1)


trinode(Posted 2011) [#8]
thanks jesse, that version of drawimage is not showing in jungleide, do you happen to know if that's normal? (I've been spoiled by visual studio at work ;) )


Jesse(Posted 2011) [#9]
I'm on a Mac so unfortunatelly I don't know much about jungleIDE. I figure it's a jungleIDE inconsistency . you might wan't to post your concer in the JungleIDE forum website.


DruggedBunny(Posted 2011) [#10]
Just to add, you don't have to hard-code the middle-point of the image like that: pass Image.MidHandle as a flag in LoadImage, eg.

LoadImage ("image.png", 1, Image.MidHandle)


See also the Matrix Rocks sample in MonkeyPro/bananas/hitoro/...

Regarding the alternative DrawImage (or other functions') forms, open this with your web browser:

MonkeyPro/docs/index.htm