vanderlin / ofxBox2d

Openframework wrapper for box2d
zlib License
320 stars 122 forks source link

Request example-SimplePolygon #117

Closed AnasGhrab closed 5 years ago

AnasGhrab commented 7 years ago

Hi,

Is it possible to add an example for a simple Polygon so to better understand how to construct objects other than circle and rects ? Maybe using an ofPath ?

Many thanks.

-- Anas

vanderlin commented 5 years ago

here is a very simple example to make a triangle.

// in .h
// shared_ptr<ofxBox2dPolygon> poly;

// on click
poly = make_shared<ofxBox2dPolygon>();

poly->setPhysics(1, 0.5, 0.5);

// make a triangle
poly->addVertex(-100, 100);
poly->addVertex(0, -100);
poly->addVertex(100, 100);

// now create the b2d shape
poly->create(box2d.getWorld());

// now move to center of screen
poly->setPosition(ofGetWidth()/2, ofGetHeight()/2);