Thanks for the correction bro. You're right, I tested it and if you do not set the translate part (the x,y) of the transform, it causes the image to snap its ox,oy point to the top-left corner of the screen.
I also tried using a point other than the center of the image to zoom (scale) from, and it adds a bunch of complexity: if the image is already drawn on screen in a transformed way (like positioned, scaled and rotated to some extent), then the screen ox,oy needs to be found within the image.
That is, you can't just use the screen point that you want the image to transform from: the ox,oy point should be relative to top-left corner of the image, not the screen. It's like an internal pixel coordinate within the image.
So if you find the screen point that you want the image to transform from (say, from a mouse click etc), you need to map that point to be internal to the already transformed image, and use that internal point as the ox,oy of the :setTransformation() call and so on.
Luckily this conversion is easily done like this:
Code: Select all
local screen_ox, screen_oy -- From a mouse click or some other screen-relative point.
-- Find the internal image point to use as the transform origin.
local image_ox, image_oy = zoomTF:inverseTransformPoint(screen_ox, screen_oy)
-- Position the image back where it was being drawn, but scaled from the specific transform origin.
zoomTF:setTransformation(screen_ox, screen_oy, 0, zoom, zoom, image_ox, image_oy)