[SDL] Sprite Origin positions
mrtatoad at mrtatoad.plus.com
Fri Sep 19 11:02:04 PDT 2014
Dont forget that is the point for which rotation is performed around, not the origin for plotting the sprite.
> 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 (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 (SDL at lists.libsdl.org)
> > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL