ofxBox2D fixed rotation

I’m trying to prevent my polygons from rotating, but this has no effect. Any ideas?

ofxBox2dPolygon p;

p.bodyDef.fixedRotation=true;

currently have it working properly, but i had to hack the lib :stuck_out_tongue_winking_eye:

In b2Body.cpp, I’ve disabled the following lines 308 - 313, around where e_fixedRotationFlag is used in a conditional:

/* REMOVE TO DISABLE INERTIA
// Center the inertia about the center of mass.
m_I -= m_mass * b2Dot(center, center);
b2Assert(m_I > 0.0f);
m_invI = 1.0f / m_I;
*/

bodyDef seems not to update correctly in ofxBox2d or something. Your first code sample should work, it’s even an example in the box2d documentation on how to prevent a game character from rotating upon collisions.

you can un-comment 308-313
check out the header file of ofxBox2dBaseShape, and you could call the function setFixedRotation( true );

Thanks! The approach you suggested also worked to fix the rotation, but I’m noticing that there seems to be an issue when many shapes are push_backed at in the same area at the same time that causes the shapes to become very scattered at birth. Eventually the program gets hung up and freezes.

I may need to dig into the the library a bit more to see if there’s an additional setting I need to make besides setFixedRotation( true ), so that shapes will not only not rotate but congregate around the their point of origin in the way that I’m envisioning.

For now, commenting out the inertia code solves my problem, though I know that this is not the intended way to use a library. I’ll keep exploring, and see if I can find a way to disable the reseting of m_I, b2Assert() and m_invI by not actually commenting out chunks of the library.

I found the docs good, and also I just went through most of the ofxBox2d repo on github.
picking up stuf here and there.

I remembered one thing, I found it from the docs.


Caution
Do not create a body at the origin and then move it. If you create several bodies at
the origin, then performance will suffer.

so your findings are correct, creating many objects at same origin will slow down performance even halt the app.