Sharp Angles - Bug?

Hi, I'm new to Box2d(Flash), and was just playing around to find out it's capabilities, and ease of extension. But with my very simple test world, I keep on getting broken behaviour: sharp corners of static polygons (<50 degrees) can stab into other polygon edges.
It seems from a bit of testing, that it is behaving as if there is no vertex there at all, the only collisions dealt with are where it is definitively hitting one edge.

Here is some sample code to reproduce. Simply replace the function TestBridge in the demo program for v1.4.3 with this to observe the behaviour. I have positioned a free floating square inside a sharp static angle, but it is not kicked out. The positioning is merely for convenience, you can get such bugs while continuously moving the square from outside. Giving pd a positive density, or picking a larger angle resolves the problem.

Code: Select all

public function TestBridge(){
   
   Main.m_aboutText.text = "Custom";
   
   m_world.m_gravity.SetZero();
   

   var bd:b2BodyDef;
   
   var sd:b2BoxDef = new b2BoxDef();
   sd.extents.Set(20, 20);
   sd.density=0.4;
   
   bd = new b2BodyDef();
   bd.AddShape(sd);
   
   bd.position.Set(210, 110);
   m_world.CreateBody(bd);

   var pd:b2PolyDef = new b2PolyDef();
   pd.vertexCount=3;
   pd.vertices[0].Set(100,0);
   pd.vertices[1].Set(0,100);
   pd.vertices[2].Set(0,0);
   pd.density=0.0;
   
   
   bd = new b2BodyDef();
   bd.AddShape(pd);
   bd.position.Set(100, 100);
   m_world.CreateBody(bd);         
}


Am I missing something or it this just plain wrong?
I tried this on the C++ SVN version and it works fine (I reduced all sizes by a factor of 10). Maybe skatehead can try this on the Flash version.
Just tried it and I get the same problem, but not in the c++ version, I'll see what I can do.
The problem isn't the sharp angles, it's the AABB being placed incorrectly in the constructor of a b2PolyShape, so that if a poly shape is within a static body, the AABB will be offset slightly, depending on the shape.

Thanks for pointing this out, it turned out to be a simple 'm_position' I had written instead of 'position'

You can update from SVN, or download the modified file here:
http://skatehed.ho8.com/flash9/143/Box2DFlashAS3_1.4.3_Fix.zip

See fixed swf here:
http://skatehed.ho8.com/flash9/143/PhysTestBug1.html

Cheers,
-Matt
Cheers, that works great.

Oh, and almost forgot the obligatory thank you to both Erin and you for providing a great engine, and such prompt and patient support on the forum.
Great news, i had the same problem with poly's, i thought that i was doing something wrong, since some poly's worked fine. 🙂

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