SDL_Gfx circle surface rotate

sorry this is a bit of a sunday afternoon question,

in most rotation of images its a square area that gets rotated resulting in
a returned surface bigger than the original to contain the extra space by
the corners of the square

i would like to be able to rotate a circular area of a surface, returning a
rotated circular section of a surface in a masked square surface.

triangles and stuff might be nice as well.

are there any support libraies might be capable of this?

my grip on maths, C and SDL_surface is minimal

sorry this is a bit of a sunday afternoon question,

in most rotation of images its a square area that gets rotated resulting in
a returned surface bigger than the original to contain the extra space by
the corners of the square

i would like to be able to rotate a circular area of a surface, returning a
rotated circular section of a surface in a masked square surface.

triangles and stuff might be nice as well.

are there any support libraies might be capable of this?

my grip on maths, C and SDL_surface is minimal

I think i figured out a way to do this now, but i’m sure some of you lot
will say i’m crazy… using a large b&w circle outline, scale it down to the
size of the area i want to rotate, get area i want to rotate in new surface,
rotate it , then use circle mask to create new surface with masked circle
outline.

or some combination of the above…

If your goal is to optimize your application (rotating a smaller area,
not having to crop the resulting surface) then as you may already
suspect, your new approach is a little long-winded.

If you look into the SDL_Gfx source code and find the rotation
function, it may not be difficult (even for a novice) to rewrite it
into a new function which has the following characteristics:

A) Returns a surface with the same dimensions as the source

B) Simply throws away information that would end up outside the
boundaries of the destination surface

On the other hand, if your goal is merely to cut out a circular area
of an image you also want rotated, your way seems reasonable.

If you’re feeling more daring, you can try to add this characteristic
to your new rotation function:

C) Only process pixels a certain distance from the center

Also, IIRC, SDL_Gfx comes with a function to draw a filled circle, can
that be used to generate your mask? It’s probably faster than scaling
an existing image of a circle.

Also also, some day you may want to try programming with OpenGL.
Rotation is a rather trivial operation for modern GPUs.On Sat, Dec 13, 2008 at 1:14 PM, Neil White wrote:

i would like to be able to rotate a circular area of a surface, returning
a rotated circular section of a surface in a masked square surface.

I think i figured out a way to do this now, but i’m sure some of you lot
will say i’m crazy… using a large b&w circle outline, scale it down to the
size of the area i want to rotate, get area i want to rotate in new surface,
rotate it , then use circle mask to create new surface with masked circle
outline.


http://codebad.com/

Neil,

SDL_gfx expands the output surface during the rotation because the
rotation code is implemented as a backwards-mapping (output pixels are
looked up in the input surface) to allow for linear interpolation on
RGBA surfaces. Therefore the rotated surface is generally bigger or of
different dimensions as the source surface (i.e. a square of size L
rotated by 45 degrees would end up mapping to a square of size L*sqrt(2)
for example).

[target surface] = new_surface(dimensions_needed_to_cover_rotated_source)
[source surface] <----lookup of pixels— [rotated surface]

For centered source images, it is quite trivial to re-center the output
surface back to the original square size. First you calculate an offset
from the top right corner of the rotated surface to the place where the
original size would be if the enlargement hadn’t happend:

{offset} = {(rotate.width - source.width)/2, (rotated.height -
source.height)/2}

You will now need either another surface-to-surface blit to generate a
surface of the source size:

[new rotated surface]=new_surface(dimensions_of_source)
[rotated surface] ----recenter blit from {offset} to {0,0}----> [new
rotated surface]

or you can blit directly to the screen using a clip-mask and applying
the offset:

set_clip([display], target_position+offset, dimensions_of_source)
blit([rotated surface] to target_position+offset)

Hope that helps,
Andreas

Neil White wrote:

sorry this is a bit of a sunday afternoon question,

in most rotation of images its a square area that gets rotated
resulting in a returned surface bigger than the original to
contain the extra space by the corners of the square

i would like to be able to rotate a circular area of a surface,
returning a rotated circular section of a surface in a masked
square surface.

triangles and stuff might be nice as well.

are there any support libraies might be capable of this?

my grip on maths, C and SDL_surface is minimal

I think i figured out a way to do this now, but i’m sure some of you
lot will say i’m crazy… using a large b&w circle outline, scale it
down to the size of the area i want to rotate, get area i want to
rotate in new surface, rotate it , then use circle mask to create new
surface with masked circle outline.

or some combination of the above…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: aschiffler.vcf
Type: text/x-vcard
Size: 135 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20081219/44314c10/attachment.vcf

Correction to my previous email.

Andreas Schiffler wrote:

or you can blit directly to the screen using a clip-mask and applying
the offset:

set_clip_rect([display], target_position of dimensions_of_source)
blit([rotated surface], null, [display], target_position-offset)

-------------- next part --------------
A non-text attachment was scrubbed…
Name: aschiffler.vcf
Type: text/x-vcard
Size: 135 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20081219/eb67576e/attachment.vcf