vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

In GJK sometimes support(shape_a, shape_b, 1, 0) is 0,0 which breaks circle:support #25

Closed Ragzouken closed 11 years ago

Ragzouken commented 11 years ago

Sometimes in GJK ax,ay will be 0,0

local ax,ay = support(shape_a, shape_b, 1,0)

These are later passed directly to circle:support which breaks when given 0,0. Not sure if this is an edge case of circle:support or if ax,ay should never be 0,0 in the first place.

vrld commented 11 years ago

I have a vague idea where this issue might be rooted. Do you have a test case at hand so I can verify it?

Ragzouken commented 11 years ago

It was kinda difficult to recreate, but I have a grid randomly filled with 32*16 rects colliding with a a 8 radius circle on the mouse. Sometimes it quickly breaks, sometimes it takes a while. Also I noticed (probably unrelatedly) that sometimes the circle will get stuck on the corners of the rects for a while - perhaps it's taking a long time to work out the collisions?

http://you.mongle.me/love/collider-bug.love

I tracked it back to the problem being that support(shape_a, shape_b, 1, 0) returns 0,0 - I guess because the two shapes happen to have the same support? Passing that 0,0 into support for the circle causes a division by zero which propagates up until the loop to find vmax which is never set away from nil because the divide by zero result is larger than the huge number.

vrld commented 11 years ago

Both issues are fixed with the last two commits. Thanks for reporting!