I'm trying to create a b2Body, but when I call world->CreateBody, the body is always created at (0,1), even though I have the b2BodyDef's position member set to (10,10). This same code used to work fine. How can I make box2D recognize the specified position? I'm using box2D version 2.0.1
Here's the body creation code:
EDIT: Never mind, I found the problem. The box2D framework got corrupted somehow.
Here's the body creation code:
Code:
PhysicsObject::PhysicsObject(PHYS_OBJDECL type, int x, int y, float friction, float bounciness, int angle, bool fixangle, bool fixed, float density) {
fixang = fixangle;
float w, h, a;
w = PX_2_B2D(type.w);
h = PX_2_B2D(type.h);
a = DEG_2_RAD(angle);
gfx = NULL;
ix = x;
iy = y;
ia = angle;
b2BodyDef shDef;
shDef.position = PXVEC_2_B2DVEC(b2Vec2(x,y));
shDef.angle = a;
shDef.userData = this;
shDef.fixedRotation = fixangle;
if(fixed) {
representedBody = PhysicsManager::getInstance()->world->GetGroundBody();
} else {
representedBody = PhysicsManager::getInstance()->world->CreateBody(&shDef);
}
if(type.type == BOX) {
b2PolygonDef shapeDef;
if(!fixed) {
shapeDef.SetAsBox(((float32)w)/2.0f, ((float32)h)/2.0f, b2Vec2(0, 0), a);
} else {
shapeDef.SetAsBox(((float32)w)/2.0f, ((float32)h)/2.0f, representedBody->GetLocalPoint(b2Vec2(PX_2_B2D(x), PX_2_B2D(y))), a);
}
shapeDef.friction = friction;
shapeDef.density = density;
shapeDef.restitution = bounciness;
shapeDef.userData = this;
representedShape = representedBody->CreateShape(&shapeDef);
} else {
b2CircleDef shapeDef;
shapeDef.radius = w;
if(fixed) shapeDef.localPosition = representedBody->GetLocalPoint(b2Vec2(PX_2_B2D(x), PX_2_B2D(y))); else shapeDef.localPosition = b2Vec2(0.0, 0.0);
shapeDef.friction = friction;
shapeDef.density = density;
shapeDef.restitution = bounciness;
shapeDef.userData = this;
representedShape = representedBody->CreateShape(&shapeDef);
}
if(!fixed) representedBody->SetMassFromShapes();
PhysicsManager::getInstance()->objects.push_back(this);
initialized = true;
}
fixang = fixangle;
float w, h, a;
w = PX_2_B2D(type.w);
h = PX_2_B2D(type.h);
a = DEG_2_RAD(angle);
gfx = NULL;
ix = x;
iy = y;
ia = angle;
b2BodyDef shDef;
shDef.position = PXVEC_2_B2DVEC(b2Vec2(x,y));
shDef.angle = a;
shDef.userData = this;
shDef.fixedRotation = fixangle;
if(fixed) {
representedBody = PhysicsManager::getInstance()->world->GetGroundBody();
} else {
representedBody = PhysicsManager::getInstance()->world->CreateBody(&shDef);
}
if(type.type == BOX) {
b2PolygonDef shapeDef;
if(!fixed) {
shapeDef.SetAsBox(((float32)w)/2.0f, ((float32)h)/2.0f, b2Vec2(0, 0), a);
} else {
shapeDef.SetAsBox(((float32)w)/2.0f, ((float32)h)/2.0f, representedBody->GetLocalPoint(b2Vec2(PX_2_B2D(x), PX_2_B2D(y))), a);
}
shapeDef.friction = friction;
shapeDef.density = density;
shapeDef.restitution = bounciness;
shapeDef.userData = this;
representedShape = representedBody->CreateShape(&shapeDef);
} else {
b2CircleDef shapeDef;
shapeDef.radius = w;
if(fixed) shapeDef.localPosition = representedBody->GetLocalPoint(b2Vec2(PX_2_B2D(x), PX_2_B2D(y))); else shapeDef.localPosition = b2Vec2(0.0, 0.0);
shapeDef.friction = friction;
shapeDef.density = density;
shapeDef.restitution = bounciness;
shapeDef.userData = this;
representedShape = representedBody->CreateShape(&shapeDef);
}
if(!fixed) representedBody->SetMassFromShapes();
PhysicsManager::getInstance()->objects.push_back(this);
initialized = true;
}
EDIT: Never mind, I found the problem. The box2D framework got corrupted somehow.