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 .
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
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!