RandyGaul / cute_headers

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
4.29k stars 267 forks source link

Fix contact points on c2AABBtoAABBManifold #390

Open lmbarros opened 3 months ago

lmbarros commented 3 months ago

Another attempt at fixing a little issue I found in cute_c2. This is working fine in my test cases, though I believe there must be a smarter way of implementing this. :sweat_smile:


Previously, we would in some cases return contact points that were not within the intersection of the two AABBs. For example,

c2AABB a = {{-3.0, 2.0}, {1.001, 4.001}};
c2AABB b = {{1.0, 4.0}, {2.0, 6.0}};
c2Manifold m;
c2AABBtoAABBManifold(a, b, &m);
printf("p=(%f, %f)\n", m.contact_points[0].x, m.contact_points[0].y);

would print p=(-0.999500, 4.001000).

This commit offsets the "other" coordinate of the contact points so that it lies within the intersection of the two AABBs. With the example above, it now prints p=(1.001000, 4.001000).

RandyGaul commented 3 months ago

Is it possible to add a screenshot showing before/after difference? The change looks innocuous enough, but I'd like to see it visually first if possible