[SDL] Scaling Images

Gabriel mystml at adinet.com.uy
Tue Nov 15 10:59:16 PST 2005


El lun, 14-11-2005 a las 11:20 -0800, Bill Kendrick escribió:
> > I'm currently using the SDL GFX library which works
> > fine for the rectangular scaling but can't do the
> > perspective scaling as far as I know. I've also heard
> > SDL_SoftStretch mentioned but haven't found much
> > written about it.
> 
> So in other words you want to take something like this:
> 
>   +--+
>   |  |
>   +--+
> 
> and turn it into:
> 
>   |\
>   | \
>   | /
>   |/
> 
> In a sense, it's simply slicing the rectangle into long, vertical slices,
> and scaling each one differently.  In the example above, the leftmost 'slice'
> (be it one pixel wide, or more... up to you) is kept at 100% height.
> 
> The middle slice is at 50%.  The rightmost slice diminishes to nothing. :)

This works, but the effect is NOT perspective. The middle slice is half
the size of the original slice but you need to apply a nonlinear
scaling, because distance (Z) is not linear respect to screen x (x') and
screen y (y'). In other words, a 1-pixel increment at the left part of
the polygon doesn't mean the same Z increment that a 1-pixel increment
at the right side. This is essentially the problem which "perspective
correct texture mapping" solves, which involves interpolating u/z, v/z
and 1/z which are linear in x' and y', unlike z (I'll clarify this when
I get to texture mapping in my blog, see signature)

Since in this case he doesn't have z values (I believe), the correct way
to simulate a perspective mapping knowing only the starting and ending
shapes is to calculate a planar homography between the two shapes.

	--Gabriel

-- 
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com





More information about the SDL mailing list