I have an object with an x,y,width,height, centre of rotation for X and Y (originX, originY) and have successfully calculated the angle between this centre point and the touch point using
touchAngle = Math.toDegrees(Math.atan2(deltaY, deltaX));
and this works very well.
I am now trying to rotate the object towards this touch point by simply checking if the angle is larger than its current angle, add some rotation and if it's smaller then remove some rotation. I know that this is wrong as when the touch point crosses the 0/360 border the object begins to rotate the wrong way, even if it means doing a very large rotation.
What would be an elegant solution to make it rotate the shortest distance to the touch point?
(Using Java, specifically Libgdx)
Thanks