ofxBox2d and custom polygons

hello, just a quick question with ofxBox2d… I am attempting to create a triangle polygon, which I got working, problem is that it doesn’t move around when objects collide with it. I also can’t drag it with the mouse.

I’ve checked its bIsFixed value, but it is not set to fixed.

I’ve tried it as both ofxBox2dLine and as ofxBox2dPolygon, but neither seem to move.

Wondering if anyone knows how I can make them move around?


just tried manually setting the velocity, and also applying an impulse force, but still no movement!

Have you called setPhysics(float m, float bnc, float frc) on your triangle?

I have the same problem - set physics also doesn’t seem to work.

I also noticed that the position isn’t set properly unless you add call for update() into the create shape method.

I found I had to set the density from 0.0 to 1.0.
In the init method of ofxBox2dPolygon.h there is a b2PolygonDef instance called “poly” and this is where the density is set.

class ofxBox2dPolygon : public ofxBox2dBaseShape {  
   void init(b2World * b2dworld, float x, float y) {  
      //poly.density	  = 0.0;  
      poly.density	    = 1.0;  

If you set this to 1.0 and compile, the poly should come to life. However a better approach is to extent this class and override this method. You probably need to do this anyway in order to extend the draw method.