Does anyone have a way of positioning a sprite based on a defined origin for the graphic, so that if the origin is set to the middle (for example), x and y coordinates would position the sprite so that the centre of the sprite would be at the coordinates.
The main problem is that whilst SDL can rotate an object around defined coordinates, positioning is still based on the top-left coordinate, causing the usual way of calculating the position :
cosp = COS(angle);
sinp = SIN(angle);
sx = sourceRect.w / 2.0;
sy = sourceRect.h / 2.0;
px = point.x - sx; py = point.y - sy; rx = ((px*cosp + py*sinp) * scaleX)+sx; ry = ((py*cosp - px*sinp) * scaleY)+sy; destRect.x = (int) (x - rx); destRect.y = (int) (y - ry);
to fail to give the correct positions - calculating the correct origin position needs to take into account the sprites angle and scale.