hi
so i’m trying to just create a triangle in box2d (using the latest version on github) and ofw 008, but im having issues
my code looks like this
void testApp::setup(){
box2d.init();
box2d.setGravity(0, 20);
box2d.setFPS(30.0);
box2d.createGround();
}
void testApp::update(){
box2d.update();
}
void testApp::draw(){
box2d.draw();
for(int i=0; i<triangles.size(); i++){
triangles[i].draw();
}
}
void testApp::mouseReleased(int x, int y, int button){
// make a triangle
ofxBox2dPolygon t;
ofVec2f a = ofVec2f(100,0);
ofVec2f b = ofVec2f(0,200);
ofVec2f c = ofVec2f(200,200);
t.addTriangle(a, b, c);
t.setPhysics(0.3, 1.0, 0.1);
t.setAsEdge(false);
t.create(box2d.getWorld());
triangles.push_back(t);
// print some debug
vector <ofPoint>&pts = t.getVertices();
printf("size=%i\n", (int)pts.size());
for(int i=0; i<pts.size(); i++){
printf("%i %f %f\n", i, pts[i].x, pts[i].y);
}
printf("closed=%i\n", (int)t.isClosed());
// move to mouse pos
t.setPosition(x,y);
}
as you can see, in terms of box2d shape, there are only two sides. so instead of doing addTriangle() i also tried
t.addVertex(a.x, a.y);
t.addVertex(b.x, b.y);
t.addVertex(c.x, c.y);
t.addVertex(a.x, a.y);
nothing, same problem. I also tried t.close() (supposed to close the polyline) but nothing.
when i draw the triangle i see two sides, but when i print the vertices (as shown in screenshot in console), if i do t.setAsEdge(false); i see 3 points listed, when i do t.setAsEdge(true) i see only two points listed. either way its not a closed triangle shape in box2d, so something is going wrong.
any thoughts greatly appreciated,
thanks