03-05-2002, 02:50 AM
i was wondering if it would be fast using regions for collision detection? eg createpolygonrgn and Ptinregion
or would it be better if found the distances of each object and if the object is within a circle, which the circle is around the region
if the distance is within the circle then run the collision detection code
eg say you have a square that can spin in circles and place a circle around the edges
03-05-2002, 05:16 AM
If you use the second method, using circles as your boundries, then you have to calculate your circle every frame, or each time your object moves. And since your circle will almost certainly NOT be the shape of your object, your calculation will be inaccurate.
On the other hand, if you use point-to-point collision detection, then you'd have a much more accurate form of detection.
Either can be fast, it just depends on your implementation. If you choose to do region-based collision detection, I would suggest that you cache your trancendental functions on a table for faster access. There's nothing slower than the VB sin() and cos() functions, so keep this in mind.
03-05-2002, 08:36 AM
Yes, using regions would be very fast providing the shape of the region didnt alter much, and this includes rotation.
However, if you do decide to use the Regions method, I would suggest than instead of using PtInRegion you do something like this:
Lets say we have 2 objects defined by Region A and Region B
Use GetRgnBox to grab RECTs for each region
IntersectRect the 2 rectangles.
If they dont intersect then finish, they do not collide
If they do intersect then:
Use CombineRgn on A and B with the XOR flag, and store it (call it Region Z for now)
Use CombineRgn on A and B with the OR flag, and store it (call it Region X)
Use EqualRgn on Regions X and Z to see if they are identical. If they are identical, then the regions are not touching. However, if they prove to be different, then a collision has occured
Whether or not this would work in practice I dont know, Im just making it up as I go along. But it sounds like it would work, and should be pretty fast.