The TRANSFORM command

Monkey Forums/Monkey Programming/The TRANSFORM command

AdamRedwoods(Posted 2011) [#1]
The documentation for this command is terrible, so I thought I'd post it here:

Function Transform( ix#, iy#, jx#, jy#, tx#, ty# )

ix = scale * rotation cos(a)
iy = rotation -sin(a) (* scale)
jx = rotation sin(a) (* scale)
jy = scale * rotation cos(a)
tx = translate x
ty = translate y


Why is this useful? It allows you to do a scale and translate at once (so you don't have to to a costly x/Scale, y/Scale after your Scale command to get "nice" placement). I find it useful when displaying text with AngelFont.

So to combine a scale and normal x,y placement (without rotation):
PushMatrix()
Transform(scalex,0,0,scaley,placex,placey)
DrawImage img,1,1
..etc more drawing commands..
PopMatrix()


Remember to keep scale = 1.0 if you only want to do rotation.

If you're into performance, you could try the SetMatrix commands if you wish to overwrite any previous operations. The values are the same for Transform, but it removes multiplying the current matrix. Make sure to use PushMatrix and PopMatrix before and after.
Function SetMatrix( ix#, iy#, jx#, jy#, tx#, ty# )



wiebow(Posted 2011) [#2]
Thanks Adam!


Shinkiro1(Posted 2011) [#3]
It took me some time to figure this out myself.
In my current framework I do 1 transform command to translate, scale and rotate the sprite that's rendered next.

Transform camera.zoom * sprite.scaling.X * Cos(sprite.rotation), -Sin(sprite.rotation) * camera.zoom, Sin(sprite.rotation) * camera.zoom, camera.zoom * sprite.scaling.Y * Cos(sprite.rotation), ((sprite.position.X * camera.zoom) - (camera.position.X * camera.zoom) + camera.screenCenterX) / SCREENX_RATIO, ((sprite.position.Y * camera.zoom) - (camera.position.Y * camera.zoom) + camera.screenCenterY) / SCREENY_RATIO
DrawImage sprite.image, 0, 0, sprite.frame


If you don't want camera zooming or virtual resolution just remove camera.zoom and SCREEN_RATION variables.

And if you want fullscreen-rotation just put a Rotate command before the Transform:
Rotate camera.rotation


EDIT: Is there a reason why you draw the image at 1,1. Because of padding?