Sign in to follow this  
LorinAtzberger

Rotated and scaled pixel perfect collision

Recommended Posts

Hey guys. I'm trying to add 2D graphics to my engine and I've reached the part with checking if 2 images collide. I need this to be pixel perfect. I know how I'd normally do it (simple bitmask) but what if I want a image to be rotated about a pivot and scaled? When I draw images I just say: H3DSetScale(1.5,0.2);// X,Y scale; H3DSetRotation(75.0f);// Degrees not radians H3DDrawImage(image,45,23,0);// image to draw, x pos, y pos, and frame Now I'd like to make a function with a prototype like this: bool H3DImagesCollide(image1,x1,y1,frame1,sx1,sy1,rot1,image2,x2,y2,frame2,sx2,sy2,rot2); Yeah there are a quite a lot of parameters but it's for a good flexibility. So going back to my question. How should I approach this rotated and scaled bitmask thing? (note that the rotation is done about a user set handle and so does the scale work). I've been looking at the blitzmax code on how they did it but I've very confused. They work with some kind of functions named RenderPolys and CollideSpans to check if 2 quads are colliding. Since I don't want to just steal the code I'd like to understand it and write my own. Any tips or links? (googleing didn't really help me at all)

Share this post


Link to post
Share on other sites
Google for "polygon scan conversion" to find out how you draw a polygon using a software renderer - the most common method being to trace around the edges of the polygon and make horizontal endpoints, it being fast/easy to draw a line at a time between them.

Do this to both polygons and the full test degenerates into a clipping algorithm one line at a time. Iteratively around the smallest polygon, you end up asking a load of simple questions and return when getting a TRUE:

Do these endpoints on line x overlap the endpoints on line x-ydiff on the other line?TRUE:FALSE

For the case of a texture polygon (which includes a quad), you obviously need to look at whether the pixels are actually set where the overlap is.

This is not trivial stuff, but it does break down into easier steps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this