[SDL] RotoZoom is great, but...

Torsten Giebl wizard at syntheticsw.com
Sat Sep 2 02:47:48 PDT 2006


Hello !


> What point does RotoZoom rotate around?  Do you have the graphic
> centered on that point before you rotate it?  I don't know how you can
> expect it to be centered after a scale.  The center point changes while
> the origin in the upper left corner almost certainly stays the same.


But the center point should be the center point
before scaling and rotating and afterwards.
Instead of using the upper left corner
before blitting save the coords of the center point.

I use something like this. When you call this routine
with center = true it not uses the upper left corner as x and
y, but it centers the surface so that x and y are the center points.


void Screen::Blit (Bitmap *bitmap, Sint16 x, Sint16 y,
			    bool x_flip, bool y_flip, bool center)
{
    if ( use_video == false ) return;

    if (center == false)
    {
	rect.x = x;
	rect.y = y;
    }
    else
    {
	rect.x = x - ( (bitmap -> w) / 2 );
	rect.y = y - ( (bitmap -> h) / 2 );
    }

    rect.w = bitmap -> w;
    rect.h = bitmap -> h;

    if (    (x_flip == false) &&
	    (y_flip == false)	    )
    {
	SDL_BlitSurface (bitmap, NULL, screen, & rect);
    }
    else

    if (    (x_flip && y_flip) == false	)
    {
	SDL_Rect from_rect, to_rect;

	/* --- flip horizontally if requested --- */

	if (x_flip == true) {
	    from_rect.h = to_rect.h = bitmap->h;
	    from_rect.w = to_rect.w = 1;
	    from_rect.y = 0;
	    to_rect.y = rect.y;
	    from_rect.x = 0;
	    to_rect.x = rect.x + bitmap->w - 1;

	    do {
		SDL_BlitSurface(bitmap, &from_rect, screen, &to_rect);
		from_rect.x++;
		to_rect.x--;
	    } while (to_rect.x >= 0);
	}
	else

	/* --- flip vertically if requested --- */

	if (y_flip == true) {
	    from_rect.h = to_rect.h = 1;
	    from_rect.w = to_rect.w = bitmap->w;
	    from_rect.x = 0;
	    to_rect.x = rect.x;
	    from_rect.y = 0;
	    to_rect.y = rect.y + bitmap->h - 1;

	    do {
		SDL_BlitSurface(bitmap, &from_rect, screen, &to_rect);
		from_rect.y++;
		to_rect.y--;
	    } while (to_rect.y >= 0);
	}
    }
    else

    {
	SDL_Rect from_rect, to_rect;
	Sint16 index_x = 0, index_y = 0;

	for (index_y = 0; index_y < bitmap -> h; index_y ++)
	{
	    for (index_x = 0; index_x < bitmap -> w; index_x ++)
	    {
		from_rect.w = 1;
		from_rect.h = 1;
		from_rect.x = index_x;
		from_rect.y = index_y;

		to_rect.w = 1;
		to_rect.h = 1;
		to_rect.x = x + bitmap -> w - index_x - 1;
		to_rect.y = y + bitmap -> h - index_y - 1;

		SDL_BlitSurface (bitmap, & from_rect, screen, & to_rect);
	    }
	}
    }
}



CU





More information about the SDL mailing list