Below is the full program code, however since everything works when I take away the code from the Man class to create a custom Body through BodyDefs and attach a Shape via ShapeDef, and just use createRect(), I suspect that it is either in CrazyMan or Man, or possibly in the way that the Physics class is initialized behind the scenes or the World class. To make the body non-rotational I looked at the createRect() code in the source for BoxWrap2d and tried to mimic it, and just add the fixedRotation field.
The CrazyMan2 class:
class Man{
BodyDef manDef;
PolygonDef manShapeDef;
Body crazyMan;
ForceUtils futil = new ForceUtils();
Vec2 pointLeft;
Vec2 pointRight;
Vec2 pointDown;
Vec2 pointUp;
Boolean isJumping;
Man(float mWidth, float mHeight, float x, float y, Physics physics){
physics.setDensity(1.0);
physics.setFriction(0.5);
manDef = new BodyDef();
manDef.fixedRotation = true;
crazyMan = physics.getWorld().createBody(manDef);
PolygonDef pDef = new PolygonDef();
pDef.setAsBox(mWidth, mHeight, new Vec2(x,y), 0.0);
crazyMan.createShape(pDef);
//crazyMan = physics.createRect(x1, y1, x2, y2);
pointLeft = new Vec2(-width,0);
pointRight = new Vec2(width,0);
pointUp = new Vec2(0, height);
pointDown = new Vec2(0,-height);
}
float getMass(){
return crazyMan.m_mass;
}
void moveLeft(){
futil.push(crazyMan, pointLeft, 3000.0);
}
void moveRight(){
futil.push(crazyMan, pointRight, 3000.0);
}
void moveDown(){
futil.push(crazyMan, pointDown, 3000.0);
}
void moveUp(){
futil.push(crazyMan, pointUp, 3000.0);
}
}
The Man class:
class Man{
BodyDef manDef;
PolygonDef manShapeDef;
Body crazyMan;
ForceUtils futil = new ForceUtils();
Vec2 pointLeft;
Vec2 pointRight;
Vec2 pointDown;
Vec2 pointUp;
Boolean isJumping;
Man(float mWidth, float mHeight, float x, float y, Physics physics){
physics.setDensity(1.0);
physics.setFriction(0.5);
manDef = new BodyDef();
manDef.fixedRotation = true;
crazyMan = physics.getWorld().createBody(manDef);
PolygonDef pDef = new PolygonDef();
pDef.setAsBox(mWidth, mHeight, new Vec2(x,y), 0.0);
crazyMan.createShape(pDef);
//crazyMan = physics.createRect(x1, y1, x2, y2);
pointLeft = new Vec2(-width,0);
pointRight = new Vec2(width,0);
pointUp = new Vec2(0, height);
pointDown = new Vec2(0,-height);
}
float getMass(){
return crazyMan.m_mass;
}
void moveLeft(){
futil.push(crazyMan, pointLeft, 3000.0);
}
void moveRight(){
futil.push(crazyMan, pointRight, 3000.0);
}
void moveDown(){
futil.push(crazyMan, pointDown, 3000.0);
}
void moveUp(){
futil.push(crazyMan, pointUp, 3000.0);
}
}
The Joints class:
class Joints{
private LinkedList<Joint> jointList;
Boolean hasFirstEnd;
Body firstEnd;
Physics physics;
Joints(Physics p){
physics = p;
hasFirstEnd = false;
jointList = new LinkedList<Joint>();
}
void createNew(Body attachment){
if(attachment == null) return;
if(hasFirstEnd){
physics.setRestitution(1.0);
jointList.add(JointUtils.createDistanceJoint(attachment, firstEnd));
hasFirstEnd = false;
} else {
hasFirstEnd = true;
firstEnd = attachment;
}
}
}
The Circles class:
class Circles{
private LinkedList<Body> circleList;
Physics physics;
Circles(Physics p){
circleList = new LinkedList<Body>();
this.physics = p;
}
void createNew(int x, int y, float r){
physics.setDensity(0.0);
circleList.add(physics.createCircle((float) x,(float) y,r));
}
void createNewDynamic(int x, int y, float r){
physics.setDensity(1.0);
circleList.add(physics.createCircle((float) x,(float) y,r));
}
}