Create a b2LoopShape - Great for ground

Here is code to create a b2LoopShape. It's incredibly useful for making ground in a level. Allows you to connect many points using lines to form a seamless piece of ground. b2LoopShape is never dynamic, meant for making ground in levels.

Code:
b2BodyDef bodyDef;
bodyDef.position.Set(0, 0);
      
// Tell the physics world to create the body
body = world->CreateBody(&bodyDef);
      
b2LoopShape shape;
//Make a list of points for the ground.
b2Vec2 list[] = {b2Vec2(0,100), b2Vec2(100,100)};
shape.Create(list, 2);
      
b2FixtureDef loopShapeDef;
loopShapeDef.shape = &shape;
body->CreateFixture(&loopShapeDef);


Example Image:
Image
The lines and curves in that level were made with b2LoopShape.
I'd remove the PTM_RATIO stuff from the sample just so it's a bit easier to understand (not to mention a lot of compilers will actually crash/throw exceptions on 0 / 120).

Other than that, great! I actually hadn't looked into the loop shape yet since I'm still stuck in 2.1.2 :p

-P
Good call, thanks. 🙂

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