I have following code to calculate rotation (theta) based on the mouse position and player position (player pos is always the same):
private void calculatePlayerRotation(int x, int y) {
double xd = x - this.x;
double yd = y - this.y;
if(xd == 0)
xd = -90;
if(yd==0)
yd = 90;
theta = atan2(yd,xd);
theta = toDegrees(theta);
theta+=180.0; //This is because of the orientation of what is on the image.
}
It seems, however, that when xd is negative, the image rotation is slightly off from where the mouse is.
There also seems to every now and then be some odd stuttering of the image while it rotates.
Does anyone have and idea of what might be causing this or how to improve it?
Oh and if it helps, theta is just passed to an AffineTransform which is used to draw the image.