bjg0726 / box2d

Automatically exported from code.google.com/p/box2d
0 stars 0 forks source link

b2ChainShape::CreateLoop causes odd behavior when first and last vertice are the same #340

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Make a static body with chain fixture box built with CreateChain starting at 
top left and going clockwise (should require 5 verts)
2. Try changing the fixture to use CreateLoop with the same verts
3. Put a dynamic body on top of the body

What is the expected output? What do you see instead?

Objects fall into the inside of the chain shape / have unpredictable collision 
with the object.

Please provide any additional information below.

This is happening because b2ChainShape::CreateLoop is trying to add the last 
vertex itself, and in doing so is actually causing the same vertex to be 
repeated twice which invalidates the b2_linearSlop assert which I am sure is 
there for good reason.

My suggested fix would be to only add the new vertex if...

b2DistanceSquared(vertices[0], vertices[count-1]) > b2_linearSlop * 
b2_linearSlop

...so that the same vert list would be compatible with both CreateLoop and 
CreateChain without change. In the case where the first and last vertex are the 
same, or very close, the function should operate the same as CreateChain while 
also setting up prevVertex/nextVertex appropriately.

Original issue reported on code.google.com by scl...@freolic.com on 29 Oct 2014 at 6:50

GoogleCodeExporter commented 8 years ago
Adding patch file which probably better demonstrates what I mean.

This is based off box2d-2.3.0

Original comment by scl...@freolic.com on 29 Oct 2014 at 7:00

Attachments: