[SDL] Sprite Origin positions

Justin Skiles justin.d.skiles at gmail.com
Fri Sep 19 08:48:35 PDT 2014


Hi,

Look in to using SDL_RenderCopyEx. One of the parameters is described as
such:

" 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 :
>
>
>
> Code:
>
>
> 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
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140919/1b65c4c3/attachment-0002.htm>


More information about the SDL mailing list