Matrix clarification?
Monkey Forums/Monkey Programming/Matrix clarification?
| ||
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 |
| ||
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) |
| ||
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 :)) |
| ||
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 ;) |
| ||
try translating to DeviceWidth/2,DeviceHeight/2 then rotating then doing 'drawimage(img,0,0)' |
| ||
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. |
| ||
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) |
| ||
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 ;) ) |
| ||
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. |
| ||
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 |