[SDL] Sprite Origin positions
justin.d.skiles at gmail.com
Fri Sep 19 08:48:35 PDT 2014
Look in to using SDL_RenderCopyEx. One of the parameters is described as
" a pointer to a point indicating the point around which dstrect will be
rotated (if NULL, rotation will be done aroud dstrect.w/2, dstrect.h/2)"
On Sep 18, 2014 7:09 PM, "MrTAToad" <mrtatoad at mrtatoad.plus.com> wrote:
> 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.
> SDL mailing list
> SDL at lists.libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL