Page 1 of 1

b2_linearslop problem

Posted: Mon Feb 24, 2014 10:10 am
by Astridax
Hey guys, I've come unstuck with regards to a problem with love's box2d physics module.

It is complaining about an assert that the distance squared between any two vertices is greater than b2_linearslop * b2_linearslop.

Now I have checked the source code for box2d and the box2d classes within lua and b2_linearslop is defined as the standard 0.005 (I'm assuming this is in standard box2d coordinates, i.e metres and not how love does it with pixels).

However I just can't seem to get a deterministic behaviour from my code. Or rather not one that I can work out :crazy:.

I go through all my raw vertices and do a distance squared check between each pair (this includes wrapping back round to the first one since I'm making a ChainShape with loop set to true). My code for the check looks as follows:

Code: Select all

dist = math.dist(self.physicsVertices[#self.physicsVertices-1], self.physicsVertices[#self.physicsVertices],x1,y1)
const= dist * dist
if(const> 0.000025)then --0.25 --0.05782757075
print(const)
table.insert(self.physicsVertices, x1)
table.insert(self.physicsVertices, y1)
end
This basically checks if the distance squared between the last inserted physics vertex and the next one to be added is greater than b2_linearslop ^2 and if it is, it adds it. x1 and y1 are wrap around array values, hence when it gets to the final x,y pair, x1, y1 are actually the coordinates of the first raw vertex.

As you can see I have a commented out value. 0.25 is a high one which works, and the closest value that I could get to work for a range of svg files was that second one.

0.05782757075

However this was by trial and improvement; manually and I have absolutely no idea why it is so.

I have even tried taking into account the physics world to pixels factor of 50 pixels per meter. I have tried dividing the distance by 50, dividing the x,y coords by 50, multiplying 0.5^2 by 50 to get 0.00125. But none of these work.

I know that box2D's distance squared function does this:
src: https://bitbucket.org/rude/love/src/c44 ... at=default

c = a - b

Where a,b,c are vector3s with the last coord set to 0 (I assume, being x,y,z).
It then does a dot product on c with itself.

I have calculated this to be the same value as my linear distance function.

The only things that are popping into my head about what may be the problem are these:
When is love2d doing the scaling and is it doing it before these are calculated?
Box2D does these assert checks after I have translated the physics points to reflect the change in the coordinate system i.e -w/2 -h/2, do negative values (which some of these will be after this) change the box2d distance squared function?
Is there some problem with floating point precision between lua and C++ box2d?

Thanks for all your help!

Re: b2_linearslop problem

Posted: Wed Feb 26, 2014 9:45 am
by Azhukar
If you're using the vertices to produce a chainshape, you must make sure it's not set to loop if your vertices end where they start.