How to create a static body with b2PolygonShape vertices

I cannot create b2PolygonShape with vertices in my Box2D Cocos2D project. I get no errors, but nothing appears on the screen.

How to get a static body with b2PolygonShape vertices to work?

I would like to use it with a list configured as follows:

b2Vec2 verts[] = {
        b2Vec2(-194.5f / PTM_RATIO, 83.0f / PTM_RATIO),
        b2Vec2(-118.5f / PTM_RATIO, 65.0f / PTM_RATIO),
        b2Vec2(-77.5f / PTM_RATIO, 2.0f / PTM_RATIO),
        b2Vec2(3.5f / PTM_RATIO, -59.0f / PTM_RATIO),
        b2Vec2(62.5f / PTM_RATIO, -61.0f / PTM_RATIO),
        b2Vec2(108.5f / PTM_RATIO, -63.0f / PTM_RATIO),
        b2Vec2(138.5f / PTM_RATIO, -41.0f / PTM_RATIO),
        b2Vec2(169.5f / PTM_RATIO, 11.0f / PTM_RATIO),
        b2Vec2(184.5f / PTM_RATIO, 49.0f / PTM_RATIO),
        b2Vec2(218.5f / PTM_RATIO, 51.0f / PTM_RATIO),
        b2Vec2(219.5f / PTM_RATIO, -89.0f / PTM_RATIO),
        b2Vec2(-174.5f / PTM_RATIO, -88.0f / PTM_RATIO)
};
+3
source share
1 answer

The next step will determine the vertices to form.

     b2PolygonShape shape;
        int num = 4;
        b2Vec2 vertices [] = {
                    b2Vec2 (10.5f / PTM_RATIO, 10.6f / PTM_RATIO),
                    b2Vec2 (11.8f / PTM_RATIO, 18.1f / PTM_RATIO),
                    b2Vec2(-11.9f / PTM_RATIO, 18.3f / PTM_RATIO),
                    b2Vec2(-10.5f / PTM_RATIO, 10.8f / PTM_RATIO)
                };
        shape.Set(vertices, num);

    b2FixtureDef fixtureDef;
    fixtureDef.shape = &shape;

+5

Source: https://habr.com/ru/post/1778629/


All Articles