Tunnel issues with resizing a box...Am i missing something?

Greetings,

I wanted to resize a box, so I did a little searching and saw this post:
http://www.box2d.org/forum/viewtopic.php?f=3&t=5138&p=24251&hilit=resizing#wrapheader

The issue I seem to run into is that if I create the box2d body and then resize it to be larger than it's original size, other bodies can tunnel through the edges of the new larger area. The center (the size of the original box) seems to be solid and I have no tunneling. Also worth mentioning: the issue does not occur if I create a large box first and then resize it to be smaller.

This is a rough visual of what I am creating that has an issue...the center box is the orginal shape and the outer box is the newly set size:

Code: Select all

|----------------|
|................|
|...|--------|...|
|...|        |...|
|...|        |...|
|...|--------|...|
|................|
|----------------|


Other bodies will not tunnel through the inner box, but will tunnel through the edges ('.' area) of the outer box.

The basic code I am using is (slightly adapted from the post previously mentioned):

Code: Select all

      b2PolygonShape* shape =  (b2PolygonShape*)body->GetFixtureList()->GetShape();
      shape->m_vertices[0].Set(-newSize.x/2, -newSize.y/2);
      shape->m_vertices[1].Set( newSize.x/2, -newSize.y/2);
      shape->m_vertices[2].Set( newSize.x/2,  newSize.y/2);
      shape->m_vertices[3].Set(-newSize.x/2,  newSize.y/2);

Where newSize is a b2Vec2 of the new width(x) and height(y).

My question is: I am supposed to be doing something after the above to notify box2d that the size of the body has changed? (The debugDraw is showing the new larger box, but collisions only seem to be happening to the smaller original box). Also, I tried calling body->ResetMassData() after the Set calls above, but it did not seem to have any effect.

Any help would be appreciated.
Regards,
Q
PS(I am not changing the number of vertices (or the number of fixtures)...vertices are always 4 and it is a single fixture body)
Just wanted to post an update. I have narrowed the problem down. It appears the issue only exists for static bodies, which explains why ResetMassData() of course had no effect on the issue 😳 🙄

Anyway, I still think there is an issue to be resolved here, but I am not 100% sure if it is a bug or simply a limitation of box2d.

Any help or info would be appreciated.

Regards,
Q

UPDATE: I may have spoke a tad too soon. The issue appears to happen with kinematic bodies as well (but to a lesser extent), however, switching the body type temporarily to dynamic before the resize and then back to kinematic after the resize seems to resolve/workaround the issue for kinematic bodies. However, this does not fix the issue for static bodies... Also, for static bodies, I even tried adding some density and doing a ResetMassData() after the resize (while the body was still temporarily dynamic) and it did not help for bodies that were originally static.
Yeah, Box2D does not know the shape got resized, so the AABB in the broad-phase is not adjusted.

Try this:

Code: Select all

body->SetTransform(body->GetPosition(), body->GetAngle());


This will cause the AABB to be recomputed.
Erin,

Thanks for the info. Much appreciated.

Regards,
Q

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