Example of b2EdgeChainDef

400 views
Skip to first unread message

e.smol...@gmail.com

unread,
Jul 21, 2012, 7:38:02 PM7/21/12
to box2...@googlegroups.com
Hi,

I'm fairly new to Box2dWeb, but have been really enjoying learning and playing around with it.

In my "game" I want to construct the ground using an edge chain. Looking through the source, the only object that references chains is the b2EdgeChainDef, however, I don't know its correct usage and Google didn't turn up anything useful.

I've tried something like the following, but it doesn't work because b2EdgeChainDef is not a descendant of b2Shape:

fixDef.shape = new b2EdgeChainDef;
fixDef.shape.isALoop = false;
fixDef.shape.vertexCount = 6;
fixDef.shape.vertices = [
        new b2Vec2(-CAR_WIDTH/SCALE,0),
        new b2Vec2(180/SCALE,0),
        new b2Vec2(220/SCALE,50/SCALE),
        new b2Vec2(420/SCALE,50/SCALE),
        new b2Vec2(460/SCALE,0),
        new b2Vec2((canvWidth + CAR_WIDTH / SCALE),0)
    ];
gWorld.CreateBody(bodyDef).CreateFixture(fixDef);

I've also had a look at the DrawDebugData, and I'm not sure I see support for edge chains in there (but maybe I just missed something).

Any help would be appreciated.

Thanks,
Eugene

cwb...@googlemail.com

unread,
Jul 24, 2012, 8:27:08 AM7/24/12
to box2...@googlegroups.com, e.smol...@gmail.com
Hello Eugene,

I have been looking at the code and found the b2EdgeChainDef yet pretty much unimplemented. And even the yet simplier b2EdgeShape (only from one point to another) is still not yet fully working.

I just posted a patch, but with that edge shapes can yet only be created. However, any collision will cause an error.

cwb...@googlemail.com

unread,
Jul 24, 2012, 9:33:18 AM7/24/12
to box2...@googlegroups.com, e.smol...@gmail.com, cwb...@googlemail.com
Until a solution has been found you can use the b2PolygonShape. It features a setAsEdge() function, which can result in similar output as the b2EdgeShape. However, in order to get a chain you must sequentially call it, connecting the edges manually by overlapping (vector 1 becomes vector 2 for each next call)
Reply all
Reply to author
Forward
0 new messages