Dynamic tree fat aabb bug

If you construct a body far away from the origin fat aabbs start behaving very weirdly.
The further away it is, the bigger the aabb gets, and the direction in which it is expanded depends on the rotation.
Here is an extreme example.

Image

These pictures are taken of the same body in short time intervals. The body is positioned at about (-700, -700), rotating ccw and falling down.
How far away from the origin is it? This could likely be the natural effect of floating point precision (numbers have less precision the further you get from zero).
How far away from the origin is it? This could likely be the natural effect of floating point precision (numbers have less precision the further you get from zero).

It says in the original post:
The body is positioned at about (-700, -700), rotating ccw and falling down.

That surely isn't a floating point precision issue, and we have a temporary fix.
We commented out b2Fixture.cpp line 170

Code: Select all

//b2Vec2 displacement = transform2.p - transform1.p;

and replaced it with

Code: Select all

m_sweep.c - m_sweep.c0

Transform's position was dependeant on rotation of the fixture and localCenter:

Code: Select all

    b2Transform xf1;
   xf1.q.Set(m_sweep.a0);
   xf1.p = m_sweep.c0 - b2Mul(xf1.q, m_sweep.localCenter);


Wich doesn't make much sense, now its only dependeant on movement direction.
Sorry, I missed that last line of yours underneath the images. Yes, 700 is not far enough to be a precision problem.

Could you give a little code to show how you created this body? I tried creating some bodies at (-1000,-1000) and didn't see this problem (using v2.3.0).
We dont have the code anymore, sorry.

But basically we just offsetted all boxes in the pyramid test.

Note that you should use b2PolygonFixture::Set() to create the first box far away from the origin. Using SetAsBox sets the local center to (0,0) so the effect wont be achieved.
Maybe you did that?

The AABBs for the boxes should become huge and act wierdly, and because of that the preformance should decrease.
I modified the "continous" test of the testbed to do this immediately before each body was created:

bodyDef.position += b2Vec2( -1000, -1000 );

This was what I thought you meant by "construct a body far away from the origin" in your first post.

What it sounds like you're saying now though, is it's the fixture which is far away from the origin in body local coordinates? If so, yes, that could cause some problems. Usually fixtures are made closer to the body origin, which improves precision and also keeps the center of mass closer to the origin. Body rotation is measured as being around its origin, and when the center of mass is also near the origin nothing strange happens. When the center of mass is far from the origin though, this assumption breaks down because a small rotation (as measured about the origin) would mean that the fixture is moving very fast, while what's really happening is the rotation is around the center of mass.

I don't know if your fix is ok for all cases since I haven't tried it (commenting out that line as you mention and replacing it etc would cause a compile error), but if you can run all the tests in the testbed etc and all seems to be good, you could make a bug report here: http://code.google.com/p/box2d/issues/list

Original thread: https://box2d.org/forum/viewtopic.php?t=9922