Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

box2D + SVG : close poly shapes

$
0
0

@Gallo wrote:

hello,

i wonder how i can correctly grab the shapes from an SVG file and import it into a box2D world.

For now i can import it but i have problems with shapes linked together...

Is it a problem while converting the svg to polyline ? or a problem while creating the svg (i used Illustrator and Inkscape) ?

my SVG file :

Result :

void ofApp::setup() {

    ofSetVerticalSync(true);
    ofBackgroundHex(0x0);
    ofSetLogLevel(OF_LOG_NOTICE);

    box2d.init();
    box2d.setGravity(0, 10);
    box2d.createBounds();
    box2d.setFPS(60.0);
    box2d.registerGrabbing();

    svg.load("contour.svg");
    for (int i = 0; i < svg.getNumPath(); i++){
        ofPath p = svg.getPathAt(i);

        vector<ofPolyline> outline = p.getOutline();
        // convert to polyline for further processing
        for (int i = 0; i < outline.size(); i++) {
            contour.addVertices(outline[i].getVertices());
        }

        if (contour.isClosed()) {
            p.close();
            p.setFilled(false);
        }
     }

    for (int i = 0; i < 300; i++) {
        boxes.push_back(shared_ptr<ofxBox2dRect>(new ofxBox2dRect));
        boxes.back().get()->setPhysics(3.0, 0.53, 0.1);
        boxes.back().get()->setup(box2d.getWorld(), 512, 100, 6, 6);
    }

    obstacle.addVertexes(contour);
    obstacle.create(box2d.getWorld());
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles