perfectly Rotating obejcts 2D

Assuming I have a method for rotating my object/picture thing
rotate(int rotation); // 0 - 360… 0 = looks down, 90 = looks left, 180 = looks up, 270 = looks right

now the image is for example in the center of the screen and on mouse click or move, whatever, should the image rotate so that it look towards the cursor (mouse position)
you sure understand what i mean.

now… I just cannot comeup with a algorithm to do that, someone got an idea ? =)

You only need java.awt.geom.AffineTransform and Math.atan2.

atan2 gives you the angle and AffineTransform allows you to rotate/translate the image.

ya, like i said i already got the rotating method, and i managed to do it with atan2, thanks a lot =D

You write weird, I can’t understand a word you’re saying, sorry! Please rephrase it so that it makes more sense :slight_smile:

Hm, my first post ?
because you cannot mean the second now oO

Well I got a rotating Image Method using java.awt.geom.AffineTransform
and wanted to know, how to rotate an image in the very direction of the mouse cursor, example: you move the cursor around and the image, a space ship rotates looking in the direction of the mouse cursor.

however using Math.atan2 and thanks to oNyx that succeeded.

Oh right, yes Atan2 will do that. But dude, your first pose was weird ;D