Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Sprite scaling

This thread is locked; no one can reply to it. rss feed Print
Sprite scaling
Neil Black
Member #7,867
October 2006
avatar

I'm trying to learn how to make a raycaster, for which I have some good tutorials and example source. But none of them explain how to scale sprites! The closest they come is outlining the amount of scaling to do, but they don't explain the how. Can anyone point me to a good tutorial on how to scale prites in allegro?

Audric
Member #907
January 2001

You mean, sprites like in the older Doom-likes? (Duke Nukem 3D etc.)

Intuitively, I'd say sprites are flat rectangles that are always parallel to "the surface of the screen". Their bottom-center is perfectly positioned at the x/y coords of the object (in "world" coordinates)
You'll have to make your rays detect when they cross a sprite's rectangle, then the distance will give you the right scaling to apply. Compute which "column" of the sprite it is, and draw this column (scaled to the right size) to the screen.

If more than one sprite is crossed by the ray, you'll need to sort them before drawing.

Ceagon Xylas
Member #5,495
February 2005
avatar

Andrei Ellman
Member #3,434
April 2003

In Allegro, there's the stretch_sprite() function.

If you want to write your own scaling code, you just need to work out the corresponding spurce-bitmap-pixel for each possible deastination-bitmap-pixel. To do this, you must write a point-sampling function which is a function that samples a point in the source-sprite for a given destination-pixel to work out the pixel-value of the pixel in the destination image. To work out the corresponding pixel, just divide the destination-pixel (relative to the top-left of the sprite's destination in screen-space) by the scaling-factor (or multiply by 1/scaling factor for added speed). This gives you the corresponding position in the space of the source-bitmap. Then, you can use the point sampling-function to determine the value. The simplest point-sampling function is to just get the value of the pixel in the source image by rounding the co-ordinates down to the nearest whole-number. This is the fastest method for zooming in by arbitary factors, but has the dis-advantage of the zoomed image looking pixelated. Other point sampling methods include bilinear interpolation which treats the space between pixels like a smooth transition between the pixel values at whole-number co-ordinates.

Unfortunately, you would still have to make sure that only those parts of the sprite that are not obscured by the raycasted scenery are displayed. One such method is to use z-buffered sprites which is something that Allegro does not natively support. Other methods include working out which area is visible at the depth of your aprite and using that as a mask on the stretched sprite.

AE.

--
Don't let the illegitimates turn you into carbon.

axilmar
Member #1,204
April 2001

Sprite scaling is a different thing from ray-casting.

Sprite scaling means to scale a whole sprite.

Ray-casting means to project a ray so as that to map a sprite in the 3d space.

Totally different things.

Hard Rock
Member #1,547
September 2001
avatar

Perhaps he wants to implement a raycaster, and used scaled sprites to draw characters such as was done in doom, wold 3d and countless other shooters?

_________________________________________________
Hard Rock
[ Stars Dev Company ][ Twitter ][Global Warming: ARA My TINS 07 Entry][Pong Ultra Website][GifAllegS Ver 1.07]
"Well there's also coolwebsearch but we'll let that be an IE exclusive feature" - arielb on the New Browser Plugins "What's better, HTML or Variables?"

Go to: