Hi, What would be the best way to handle collisions between circular images i.e when the images are actually rectangular .png. I am looking at angular deflections based on the point of contact.
thanks
Hi, What would be the best way to handle collisions between circular images i.e when the images are actually rectangular .png. I am looking at angular deflections based on the point of contact.
thanks
Thanks. I have actually worked out the physics mainly. I was wondering how to get the pixel coordinates on the circle for collision detection.
if geometrically calculating the collision how do you deal with the transparent region of the image.
one traditional way to do this is with shadow masks.
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…
If these are perfect circles then a simple test of the square distance between the center of the circles is enough.
(dxdx + dydy) <= (r1r1 + r2r2)
something like this? :-
http://www.pkl.net/~rsc/downloads/Balls2.jar
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().
my reference for some of the code was here :-
[quote]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.
(dxdx + dydy) <= (r1r1 + r2r2)
[/quote]
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 (r1r1 + 2r1r2 + r2r2).
Minor point… unless your objects are penetrating each other and making your application look bad…
you’re right, primary school math