Hi Everybody!
I am integrating Box2D with my engine and I am impressed with it's features.
I am making static walls using b2LoopShape and steer dynamic box/b2PolygonShape using velocities.
Very seldom my body behaves like it's sucked inside wall instead of being pushed away (even when there is no
velocity or force applied).
Please have a look at following images, one before simulation:

and one after:

I prepared test case, just copy a code to MyTest.h and include in test suite.
(pause, restart and step thru simulation).
I work with latest Box2D svn code.
I tried to debug it myself but I lacks understanding of Box2D internals 🙁.
Please help,
Cheers
Tristan
#ifndef MYTEST_H
#define MYTEST_H
class MyTest : public Test
{
b2Body* ground, *stickBody;
public:
MyTest()
{
m_world->SetGravity(b2Vec2(0.0f, 0.0f));
b2BodyDef groundDef;
ground = m_world->CreateBody(&groundDef);
b2Vec2 verts[12] = {
b2Vec2(3.250000f, 1.827835f),
b2Vec2(2.225373f, 2.750000f),
b2Vec2(3.250000f, 2.750000f),
b2Vec2(3.250000f, 1.827835f),
b2Vec2(3.375000f, 1.827835f),
b2Vec2(3.375000f, 2.812500f),
b2Vec2(3.312500f, 2.875000f),
b2Vec2(2.062500f, 2.875000f),
b2Vec2(2.020690f, 2.766044f),
b2Vec2(3.270690f, 1.641044f),
b2Vec2(3.375000f, 1.687500f),
b2Vec2(3.375000f, 1.827835f),
};
float scale = 4;
for ( int i=0; i<12; ++i )
verts[i] *= scale;
b2LoopShape groundShape;
groundShape.Create(verts, 12);
b2FixtureDef groundFixtureDef;
groundFixtureDef.shape = &groundShape;
ground->CreateFixture(&groundFixtureDef);
b2BodyDef stickDef;
stickDef.type = b2_dynamicBody;
stickBody = m_world->CreateBody(&stickDef);
b2PolygonShape stickShape;
stickShape.SetAsBox(scale*0.51562500f, scale*0.093750000f);
b2FixtureDef stickFixtureDef;
stickFixtureDef.shape = &stickShape;
stickFixtureDef.density = 1;
stickBody->CreateFixture(&stickFixtureDef);
stickBody->SetTransform(scale*b2Vec2(3.4060252f,1.4993361f), 2.892967f);
}
static Test* Create()
{
return new MyTest;
}
};
#endif
I am integrating Box2D with my engine and I am impressed with it's features.
I am making static walls using b2LoopShape and steer dynamic box/b2PolygonShape using velocities.
Very seldom my body behaves like it's sucked inside wall instead of being pushed away (even when there is no
velocity or force applied).
Please have a look at following images, one before simulation:

and one after:

I prepared test case, just copy a code to MyTest.h and include in test suite.
(pause, restart and step thru simulation).
I work with latest Box2D svn code.
I tried to debug it myself but I lacks understanding of Box2D internals 🙁.
Please help,
Cheers
Tristan
Code:
#ifndef MYTEST_H
#define MYTEST_H
class MyTest : public Test
{
b2Body* ground, *stickBody;
public:
MyTest()
{
m_world->SetGravity(b2Vec2(0.0f, 0.0f));
b2BodyDef groundDef;
ground = m_world->CreateBody(&groundDef);
b2Vec2 verts[12] = {
b2Vec2(3.250000f, 1.827835f),
b2Vec2(2.225373f, 2.750000f),
b2Vec2(3.250000f, 2.750000f),
b2Vec2(3.250000f, 1.827835f),
b2Vec2(3.375000f, 1.827835f),
b2Vec2(3.375000f, 2.812500f),
b2Vec2(3.312500f, 2.875000f),
b2Vec2(2.062500f, 2.875000f),
b2Vec2(2.020690f, 2.766044f),
b2Vec2(3.270690f, 1.641044f),
b2Vec2(3.375000f, 1.687500f),
b2Vec2(3.375000f, 1.827835f),
};
float scale = 4;
for ( int i=0; i<12; ++i )
verts[i] *= scale;
b2LoopShape groundShape;
groundShape.Create(verts, 12);
b2FixtureDef groundFixtureDef;
groundFixtureDef.shape = &groundShape;
ground->CreateFixture(&groundFixtureDef);
b2BodyDef stickDef;
stickDef.type = b2_dynamicBody;
stickBody = m_world->CreateBody(&stickDef);
b2PolygonShape stickShape;
stickShape.SetAsBox(scale*0.51562500f, scale*0.093750000f);
b2FixtureDef stickFixtureDef;
stickFixtureDef.shape = &stickShape;
stickFixtureDef.density = 1;
stickBody->CreateFixture(&stickFixtureDef);
stickBody->SetTransform(scale*b2Vec2(3.4060252f,1.4993361f), 2.892967f);
}
static Test* Create()
{
return new MyTest;
}
};
#endif