cocos2d-iphonebox2dbox2d-iphone

Creating a simple hollow rect with vectors


Using box2d (+cocos2d iPhone) , i have to create a simple rect , that will be hollow- that means having a square , that i can put bodies into it (like a cage ) . I need to create that body with 4 B2VEC vectors . How do i code that ?

The box2D says that :

Polygons are solid and never hollow
  1. how can i create a hollow square
  2. how do you code that with 4 b2vec2

Thanks .


Solution

  • ok , you can do it with a chain shape for example(docs) :

    b2Vec2 vs[4];
    
    vs[0].Set(1.7f, 0.0f);
    
    vs[1].Set(1.0f, 0.25f);
    
    vs[2].Set(0.0f, 0.0f);
    
    vs[3].(-1.7f, 0.4f);
    
    
    
    b2ChainShape chain;
    
    chain.CreateChain(vs, 4);
    
    //than construct a body with this fixture