Rotate an image in a scaled context
- by nathan
Here is my working piece of code to rotate an image toward a point (in my case, the mouse cursor).
float dx = newx - ploc.x;
float dy = newy - ploc.y;
float angle = (float) Math.toDegrees(Math.atan2(dy, dx));
Where ploc is the location of the image i'm rotating.
And here is the rendering code:
g.rotate(loc.x + width / 2, loc.y + height / 2, angle);
g.drawImage(frame, loc.x, loc.y);
Where loc is the location of the image and "width" and "height" are respectively the width and height of the image.
What changes are needed to make it works on a scaled context? e.g make it works with something like g.scale(sx, sy).