Physics are a complicated subject, and there are several existing libraries available for free that do advanced collisions in 2D and 3D.
At the basics, what you need to know to test for is how objects collide. For two rectangles, you could use something like the following:
- Code: Select all
RECT r1 = ...;
RECT r2 = ...;
if (r1.top < r2.bottom && r2.top < r1.bottom && r1.right > r2.left && r2.right > r1.left)
// objects overlap
6 lines; 1 keywds; 0 nums; 32 ops; 0 strs; 1 coms Syntactic Coloring v0.4 - Dan East