I am using the code below to try and generate a polygon shape sprite. I am running into problems with the code, can anyone spot anything wrong with it?
b2BodyDef woodBodyDef;
woodBodyDef.position.Set(400/PTM_RATIO,100/PTM_RATIO);
woodBodyDef.type = b2_dynamicBody;
woodBodyDef.userData = _wood;
_body = _world->CreateBody(&woodBodyDef);
b2PolygonShape woodShape;
int num = 4;
b2Vec2 vertices[] = {
b2Vec2(-137.0f/PTM_RATIO,-32.5f/PTM_RATIO),
b2Vec2(-137.0f /PTM_RATIO,36.5f/PTM_RATIO),
b2Vec2(137.0f /PTM_RATIO,36.5f/PTM_RATIO),
b2Vec2(136.0f /PTM_RATIO, -32.5f/PTM_RATIO)
};
woodShape.Set(vertices, num);
b2FixtureDef woodShapeDef;
woodShapeDef.shape = &woodShape;
woodShapeDef.density = 1.0f;
woodShapeDef.friction = 1.0f;
woodShapeDef.restitution = 0.5f;
woodBodyDef.userData = _wood;
_body = _world->CreateBody(&woodBodyDef);
My best guess is that the order of vertices matters. You define them in clockwise order, Box2D might expect them to be in counter-clockwise order. It’s easy to verify so just give it a try and see if that fixes the assert (which btw says that the polygon area is <= 0).