Hi Erin.
Before anything thanks for box2d. It's great.
Im using 2.2.1 version (the latest on download page). [Box2D_v2.2.1.zip]
The issue: Body stood over the ground. I apply LinearImpulse to make him jump, then world->step. After this world->step I get a contact with IsTouching=true. Then render with DebugDraw and I see the body separated from the ground.
My code:
Code:
void Phy2DSystem::Update(float _ftime)
{
for (int i = 0; i < num_scenes; i++)
{
Phy2DScene* _s = scene[i];
// Update world
_s->GetB2World()->Step(time_step, 10, 8);
// Genera los contactos actuales
for (int j = 0; j < _s->CheckCol_GetListSize(); j++)
{
// Here I Get pointer to the box which I applied LinearImpulse to make it jump
Phy2DBody* _phy2dbody = _s->CheckCol_GetBody(j);
for (b2ContactEdge *ce = _phy2dbody->GetB2Body()->GetContactList(); ce; ce = ce->next)
{
// Phy2DContact inherit from b2Contact
Phy2DContact *_phy2dcontact = (Phy2DContact *)ce->contact;
if (_phy2dcontact->IsTouching())
{
if (_s->debug)
{
// I get inside this line after apply LinearImpulse and the world->step above. Then render and box is separated from ground. Using DebugDraw.
_s->GetB2World()->Dump();
}
}
}
}
}
}
Dump info:
Quote:
b2Vec2 g(0.000000000000000e+000f, 1.100000000000000e+001f);
m_world->SetGravity(g);
b2Body** bodies = (b2Body**)b2Alloc(2 * sizeof(b2Body*));
b2Joint** joints = (b2Joint**)b2Alloc(0 * sizeof(b2Joint*));
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(3.000000000000000e+001f, 6.909857940673828e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, -8.618643951416016e+001f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(16);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[0] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 6.000000238418579e-001f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 5.000000000000000e-001f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(2);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-1.950000047683716e+000f, -4.750000000000000e+000f);
vs[1].Set(1.950000047683716e+000f, -4.750000000000000e+000f);
vs[2].Set(1.950000047683716e+000f, 4.750000000000000e+000f);
vs[3].Set(-1.950000047683716e+000f, 4.750000000000000e+000f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[0]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(0);
bd.position.Set(5.120000457763672e+001f, 7.580000305175781e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, 0.000000000000000e+000f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[1] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 0.000000000000000e+000f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 1.000000000000000e+000f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(2);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-5.120000076293945e+001f, -5.000000000000000e-001f);
vs[1].Set(5.120000076293945e+001f, -5.000000000000000e-001f);
vs[2].Set(5.120000076293945e+001f, 5.000000000000000e-001f);
vs[3].Set(-5.120000076293945e+001f, 5.000000000000000e-001f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[1]->CreateFixture(&fd);
}
}
b2Free(joints);
b2Free(bodies);
joints = NULL;
bodies = NULL;
I hope it helps!!
Thanks!