b2EdgeShape

I am attempting to build a Platform Game Engine and im using Box2D for physics. So far everything is good, its been hard work due to the lack of quality documentation, however its free so you get what you pay for. The problem I'm having an occurance of bodies been in contact and not in contact intermittently.

I beleive I've narrowed down the problem and I beleive its been caused due to my using lots of EdgeShapes in 1 body without them been 'linked' together. Searching the Box2D source code under the b2EdgeCollide code I did find that a check is done against m_vertex0 and 3 to see if the edge shape is connected to adjacent edge shapes. In the header of b2EdgeShape.h it also states EdgeShapes can be linked together, however there is no documentation on how to do this. Do I simply set m_vertex0 and 3 to the adjacent vertices of my Edgeshape when I create it? or is there a function that will do this for me because I doubt its been done automatically?

If I do have to connect them myself, I am assuming by 'adjacent vertex' it means the 1st vertex from the previous edgeshape? In ascii terms:

edge 1 edge 2
v1----v2v3----v4

Say I had edge 2 with vertices v3 and v4 I am assuming I would have to link m_vertex0 to v1 and not v2?

Thanks for any helpful replies.

Edit: Further research reveals that maybe this occurance is in b2CollideEdge.cpp where my Circle collides with the Edge but is in Region AB of the previous or next Edge and then when that next/previous edge is tested, the same conclusion is reached. example, Circle collides with Edge, is in Region AB of next Edge, next Edge is tested, Circle collides with Edge, is in Region AB of previous Edge? I beleive pointcount = 0 during this occurance which means isTouching = false. I might make modifications to Box2D to see if this is the case, but would prefer and answer here if possible.
Roswell_r wrote:
So far everything is good, its been hard work due to the lack of quality documentation, however its free so you get what you pay for.


You think the manual, testbed, and code comments are of low quality? How do you think they should be improved?
I'm not complaining as such, I mean why would I complain and then ask for help lol!

Well as an example I had no idea how to use EdgeShapes plus how to link them, I couldn't find this in the documentation, there are no examples of code in there or explanations of how to use any of the classes either. Admittedly it is just a generated reference but I had to go dig through source code of the test bed to find an example of how to use it. I've answered my question from before and already solved my problem too but I could have saved that time had it of been in the documentation.
This issue has come up several times lately so I added it to the FAQ.

http://code.google.com/p/box2d/wiki/FAQ

Quote:
Why isn't feature foo documented?
If you grab the latest code from the SVN trunk you will likely find features that are not documented in the manual. New features are added to the manual after they are mature and a new point release is imminent. However, all major features added to Box2D are accompanied by example code in the testbed to test the feature and show the intended usage.


I assume you are using the latest SVN version.

If so, you should look at EdgeTest.h for an example of how to use b2EdgeShape. You may also want to look at CharacterCollision for an example of how to use b2LoopShape.

b2EdgeShape requires a lot of manual hook-up, but it is versatile. b2LoopShape handles all the adjacency information for you and uses much less memory.
Speaking of the differences between b2EdgeShape and b2LoopShape, I wonder why b2LoopShape has to be a circular list.

Would it be complicated or less efficient to create a shape that :
- handles the adjacency information
- uses as much memory as b2LoopShape
- has not the constraint to be a circular list.

Adding a flag like "isLoop" to b2LoopShape ?

By no mean I beleive it should replace b2EdgeShape. I actualy like the versatility of b2EdgeShape because you can add edges at any time.
I use that to fix the issue described here : viewtopic.php?f=3&t=5567
Adding b2EdgeShape is very CPU efficient.
Yeah, one possibility is to have a chain shape that is optionally closed. However, it seems like people typically build loops.

However, I'd like to see you flesh out your idea a bit more. What would this new shape be like? What data does it hold? How is adjacency established?
Edge chain is actually a good name.
Here is an image showing when the opened edge chain could be used :
Image

One could argue that b2LoopShape could be used to create the ground shape.
But what happend if your game world is big ?
You won't be able to create just one big loop with 10000 edges.
A better approach is to split the ground shape into smaller pieces, and stream them.
One could argue you could still use b2LoopShape for the smaller pieces.
But it would be a waste of edges and you would loose adjacency bewteen two pieces.

the b2EdgeChainShape would be :

Code:

/// A chain shape is a free form sequence of line segments that form a linear or a circular list
class b2EdgeChainShape : public b2Shape
{
public:
   b2EdgeChainShape();
       
   /// ...

   /// The vertices. These are not owned/freed by the loop shape.
   b2Vec2* m_vertices;

   /// The vertex count.
   int32 m_count;
   
   /// Does the shape loop
   bool m_isClosed;

   /// Optional adjacent vertices at the begining and the end of the shape.
   /// These are used only when the shape is opened for smooth collision,
   /// generaly to connect edge chains together.
   b2Vec2 m_vertexStart, m_vertexEnd;
   bool m_hasVertexStart, m_hasVertexEnd;
};



I repeat myslef, but by no mean I beleive this should replace b2EdgeShape.
b2EdgeShape are really easy to setup since you don't need to do any allocation.
Yeah, I like that idea. I'll convert b2LoopShape to b2ChainShape (I prefer short names).
I'm using edgeshapes in my iphone game to create to define my terrain (typically around 1000 per level). It is a big bottleneck which is causing some performance issues. What sort of optimisations are there when using edge shapes? What are the best practices?
If they are static it should not cause much of a performance hit. If you load them all at once, there may be some slow down at the dynamic tree re-balances.

Let me know if you get more details, like a testbed example or a performance profile.

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