I am trying to implement zoom using Slick2D library.
As I understand, to zoom something on non (0,0) coordinates, we need:
- translate so the target point is in (0,0)
- apply scale factor
- translate the target point back from (0,0)
Code example :
aGraphics.translate(-width/2, -height/2); aGraphics.scale(2,2); aGraphics.translate(width/2, height/2);
The issue is, as far I understand, that the scale factor is applied to the translation too. To compensate this, I have use the next code :
aGraphics.translate(-width/2, -height/2); aGraphics.scale(2,2); aGraphics.translate(width/4, height/4);
Is this expected behaviour for graphics ? Can I workaround the above effect using push/pop matrix ?
EDIT : Seems that slick 2d doesn't consider the center coordinates when scaling. It just multiplies any coordinates using current scale.