Skip to content

delorenj/b2Separator-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Create non-convex, complex shapes with Box2D. Ported from Antoan Angelov's b2Separator class.

Example Use

    b2Body *body;
    b2BodyDef *bodyDef = new b2BodyDef();
    b2FixtureDef *fixtureDef = new b2FixtureDef();
    b2Separator* sep = new b2Separator();

    bodyDef->type = b2_dynamicBody;
    bodyDef->position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
    body = getWorld()->CreateBody(bodyDef);
    fixtureDef->restitution = 0.4f;
    fixtureDef->friction = 0.2f;
    fixtureDef->density = 4;
    
    vector<b2Vec2>* vec = new vector<b2Vec2>();
    vec->push_back(b2Vec2(-3, -3));
    vec->push_back(b2Vec2(3, -3));
    vec->push_back(b2Vec2(3, 0));
    vec->push_back(b2Vec2(0, 0));
    vec->push_back(b2Vec2(-3, 3));

    if(sep->Validate(*vec)==0)
    {
        CCLog("Yay! Those vertices are good to go!");
    }
    else
    {
        CCLog("Oh, I guess you effed something up :(");
    }

    sep->Separate(body, fixtureDef, vec, PTM_RATIO);

About

Create non-convex, complex shapes with Box2D. Ported from Antoan Angelov's b2Separator class.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages