Hi everyone,
We are using Box2D in a project here and recently, because we need to port the code to a platform with no floating point processor, we switched box2d to fixed point.
That was causing objects to go through each other, so we increased the number of iterations and it worked. Well, kind of. Objects don't go through each other but they don't bounce either.
As I implemented some physics engines in the past, I tracked the calculations of restitution and found an overflow problem in
b2ContactSolver.cpp: 119:
float32 lambda = -ccp->normalMass * (vn - ccp->velocityBias);
in that line, the multiplication is involving two huge negative numbers and the overflow is making the result look like a negative number (instead of a huge positive one).
So in the next line of code,
float32 newImpulse = b2Max(ccp->normalImpulse + lambda, 0.0f);
we select 0.0f as the new impulse, instead of the correct one.
I can try to fix this locally but I worry about seeing other unforeseen problems later. Is there a parameter somewhere to avoid this problems altogether?
Thanks!
Cesar Castro
We are using Box2D in a project here and recently, because we need to port the code to a platform with no floating point processor, we switched box2d to fixed point.
That was causing objects to go through each other, so we increased the number of iterations and it worked. Well, kind of. Objects don't go through each other but they don't bounce either.
As I implemented some physics engines in the past, I tracked the calculations of restitution and found an overflow problem in
b2ContactSolver.cpp: 119:
float32 lambda = -ccp->normalMass * (vn - ccp->velocityBias);
in that line, the multiplication is involving two huge negative numbers and the overflow is making the result look like a negative number (instead of a huge positive one).
So in the next line of code,
float32 newImpulse = b2Max(ccp->normalImpulse + lambda, 0.0f);
we select 0.0f as the new impulse, instead of the correct one.
I can try to fix this locally but I worry about seeing other unforeseen problems later. Is there a parameter somewhere to avoid this problems altogether?
Thanks!
Cesar Castro