EdgeShapes (aka Thin Line Segments)

Quote:
But you are saying that the static edges could just as well be part of a normal static body? With a slightly different constructor?
Mostly.

One reason why I created the world.CreateGroundShape() function for static edges was so that people wouldn't accidentally try to add static edges to a dynamic body. Another reason is that, unlike other shapes, b2StaticEdges are not offset by the position of their parent body. That is, the position of the vertices is always in world coordinates, even if the origin of the parent body is far away from the origin of the world. As long as you keep that in mind, though, there's nothing stopping you from moving the origin of the parent body anyway.
I have modified the b2StaticEdgeChain object a little, as you instructed, I'm passing a body into the contstructor, and I've replaced all instances of m_groundBody, with the body I'm passing in the constructor..

Now I'm using this to create a number of terrain sections, with the following code for each terrain:
Code:
//points is an array of points, defining the top of the terrain.
var bd:b2BodyDef = new b2BodyDef();
bd.userData = this;
bd.position.Set(worldX,worldY);
body = phys.CreateBody(bd);
            
var chain:b2StaticEdgeChainDef = new b2StaticEdgeChainDef();
chain.vertexCount = points.length;
chain.isALoop = false;         
for each(var point:b2Vec2 in points){
   chain.vertices.push(new b2Vec2(point.x + worldX, point.y + worldY));
}
edgeChain = new b2StaticEdgeChain(chain, phys, body);


Good news is: much better performance! The timestep now only takes an average of 1/200s to compute, in stead of 1/140s with tessellated polygons!

The bad news is that I'm getting some very anomalous behavior near the end of each chain.. As illustrated in the image below. What could be the cause for this? Am I creating the chains in a wrong way? Should they always loop?
I admit I hadn't really tested non-looping chains much. You are my guinea pig. 😛 I'll check it out when I get home tonight.

Are you saying that the problem is that shapes will fall through near the boundaries between one chain and the next, even if there is not supposed to be a gap between them? Does it matter whether they are touching the middle of a static edge or the end? Does it matter whether the corner between the chains is convex or concave?

Glad to hear the performance is better. 🙂
Hey, there is no gap at all, the first vertex of the next chain is on the last vertex of the first chain, I just drew them apart.

When objects are in the general area, usually touching the very tip of one of the edges, they start hopping up and down really fast, and jumping all around, though some smaller objects also seem attracted to the edges. (The tank-tracks get pulled off of my tank, the tank starts dancing). I could create a demo, to demonstrate what goes wrong.. I could also send you the modified b2StaticEdgeChain, tell me if you want me to do either or both of those.

[EDIT] I have attached the modified static edge chain. [/EDIT]

[EDIT] Actually, I should revise my image, the anomalous region starts to the right of where the gap is! The object starts tripping up as soon as it touches the gap, but it continues even when it's not touching the gap anymore, but only to the right. I'll see about making a demo, because the behavior seems to be pretty inconsistent.[/EDIT]

[EDIT] @ post below: ok, I'll try to make a demo with the problem isolated, a.s.a.p. [/EDIT]
A demo, I think, would be the most helpful.
android: have you tried overlapping a segment (i.e. two vertices) instead of single vertex. That way, the ground is seamless.
You are great! Any tips on translating this to c++? Which files?
android: No demo is necessary, I am able to reproduce the behavior you described with the b2StaticEdgeChain.as file you provided. I'm checking it out now.

mm2d: Hold on a sec, I'm gonna upload a slightly cleaner AS3 version soon.
android: Here's a special version of Box2D_staticEdges just for you! Everybody else should use the version my first post in this topic. (which is also updated now!)
Attachment:
Box2DAS3_android.zip [218.5 KiB]
Downloaded 83 times


mm2d: I'll look into the possibility of a C++ port more tonight.
shaktool wrote:
android: Here's a special version of Box2D_staticEdges just for you! Everybody else should use the version my first post in this topic. (which is also updated now!)
Attachment:
Box2DAS3_android.zip


This is like christmas! 😀 I'm going to try it right away!

[EDIT] Problem solved! And it's fast! (I'm talking about lightning fast... 3ms/timestep compared to 5-6ms/timestep for tesselated poly's (with +/- 20 boxes/circles).

So what had to be changed? And why isn't it a default part of the package? [/EDIT]

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