Clipping a sprite diagonally

Hi all,

I've been wondering how I could go about clipping a sprite diagonally, for instance if I wanted to tear a piece of scenery in half at the point that a laser passes through it.

All I would know to start out with would be a sprite (its dimensions and position) and a starting point plus direction(vector) of a laser. This presents me with two problems, firstly my maths skills aren't that great, not terrible, but I don't know how to approach figuring out which half of the newly split object a certain pixel in the original sprite would be. Secondly I don't know how I would blit the two new areas as my graphics component (in SDL) uses a rectangle to blit from, I may need to store two new sprites copied from the original and filled with alpha for the empty parts, but I don't know how to access the pixel data in an SDL_Surface directly.

I know I'm asking a lot here given no code or anything but it's just an idea at the moment, all I want really is a vague description of how the maths would work and how I would go about blitting it in two parts in different positions.
Last edited on
Doing this with a blitting surface (SDL) would be ridiculous.

For this you'd be better off getting into a 3D API. A 3D API can render any kind of polygon you throw at it, so if you want to tear an image diagonally, all you have to do is create two polygons. It's as simple as finding the polygons' "corner points" and drawing them. You don't have to manipulate any pixel data.

To do this with SDL blitting surfaces, you'll probably have to create a whole separate surface and erase large portions of each surface. Since you can only blit rectangles, anything that isn't perfectly rectangular is non-trivial to draw.
Oh wait I remember plotting individual triangles with directx9, not sure how easy mapping them onto a texture will be but thanks disch that'll get me started. Figuring out whether a point is left or right of the line is easy too I dunno why I didn't figure that out sooner.

I love this forum <3
Last edited on
Topic archived. No new replies allowed.