Rotate an image in a scaled context

Posted by nathan on Game Development See other posts from Game Development or by nathan
Published on 2012-10-07T09:41:31Z Indexed on 2012/10/07 9:52 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

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).

© Game Development or respective owner

Related posts about opengl

Related posts about java