You create one mask that is the projection of the pixels down to a line and do a shifted bitwise comapre aganst the other obejcts mask. if it collids you then either use masks for each line or go straight to pixel comparison.

Most games however don't bother as collision within a few pixels is often good enough...

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

This isn't a perfect solution (infact, a perfect solution is damn near impossible to obtain)It isn't particularly performance optimised either.All the source is in there though - the bit you will prolly be interested in is the Particle.checkCollisions().

Posted by: swpalmer Posted on: Feb 5th, 2004, 1:20am If these are perfect circles then a simple test of the square distance between the center of the circles is enough. (dx*dx + dy*dy) <= (r1*r1 + r2*r2)

Actually I think this may be off by a bit. You want to check if the distance between the centers is less than the sum of the radii, and do so by comparing their squares to avoid taking roots for efficiency. The left side is the square of the distance, but the right side is the sum of the squares of the radii -- not the square of the sum of the radii.Somebody correct me if I'm wrong, but I think the RHS should be (r1*r1 + 2*r1*r2 + r2*r2).

Minor point... unless your objects are penetrating each other and making your application look bad....

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org