there is testbed code:
[code]
class MySimpleTest : public Test
{
public:
MySimpleTest()
{
// ground
b2BodyDef groundDef;
groundDef.type = b2_staticBody;
groundDef.position = b2Vec2(0.0f, 0.0f);
b2Body* groundBody = m_world->CreateBody(&groundDef);
b2PolygonShape groundShap;
groundShap.SetAsBox(100.0f, 2.0f);
groundBody->CreateFixture(&groundShap, 0.0f);
groundDef.position = b2Vec2(-99.0f, 20.0f);
groundShap.SetAsBox(1.0f, 18.0f);
b2Body* breakBodyLeft = m_world->CreateBody(&groundDef);
breakBodyLeft->CreateFixture(&groundShap, 0.0f);
groundDef.position = b2Vec2(99.0f, 20.0f);
groundShap.SetAsBox(1.0f, 18.0f);
b2Body* breakBodyRight = m_world->CreateBody(&groundDef);
breakBodyRight->CreateFixture(&groundShap, 0.0f);
// slope
groundDef.position.Set(0.0f, 20.0f);
groundDef.angle = -0.3f;
groundShap.SetAsBox(20.0f,0.2f);
b2Body* slope = m_world->CreateBody(&groundDef);
slope->CreateFixture(&groundShap, 0.0f);
// wheel
b2BodyDef wheelDef;
wheelDef.type = b2_dynamicBody;
wheelDef.position = b2Vec2(-5.0f, 32.0f);
b2CircleShape wheelShap;
wheelShap.m_p.SetZero();
wheelShap.m_radius = 3.0f;
b2FixtureDef wheelFixture;
wheelFixture.shape = &wheelShap;
wheelFixture.density = 3.0f;
wheelFixture.friction = 5.5f;
wheelFixture.restitution = 0.3f;
b2Body* wheelBody1 = m_world->CreateBody(&wheelDef);
wheelBody1->CreateFixture(&wheelFixture);
wheelDef.position.x += 10.0f;
b2Body* wheelBody2 = m_world->CreateBody(&wheelDef);
wheelBody2->CreateFixture(&wheelFixture);
// join the two wheels
b2DistanceJointDef wjion;
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition(), wheelBody2->GetPosition());
m_world->CreateJoint(&wjion);
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition()+b2Vec2(0, 1), wheelBody2->GetPosition()+b2Vec2(0, 1));
m_world->CreateJoint(&wjion);
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition()+b2Vec2(1, 0), wheelBody2->GetPosition()+b2Vec2(1, 0));
m_world->CreateJoint(&wjion);
/*
// box
b2BodyDef boxDef;
boxDef.type = b2_dynamicBody;
boxDef.position = b2Vec2(0.0f, 25.0f);
b2PolygonShape boxShap;
boxShap.SetAsBox(5,5);
b2FixtureDef boxFixture;
boxFixture.shape = &boxShap;
boxFixture.density = 2.0f;
boxFixture.friction = 2.5f;
boxFixture.restitution = 0.01f;
b2Body* boxBody = m_world->CreateBody(&boxDef);
boxBody->CreateFixture(&boxFixture);
*/
//wheelBody2->ApplyAngularImpulse(-2000.0f);
}
static Test* Create() {
return new MySimpleTest();
}
};
[code]
[code]
class MySimpleTest : public Test
{
public:
MySimpleTest()
{
// ground
b2BodyDef groundDef;
groundDef.type = b2_staticBody;
groundDef.position = b2Vec2(0.0f, 0.0f);
b2Body* groundBody = m_world->CreateBody(&groundDef);
b2PolygonShape groundShap;
groundShap.SetAsBox(100.0f, 2.0f);
groundBody->CreateFixture(&groundShap, 0.0f);
groundDef.position = b2Vec2(-99.0f, 20.0f);
groundShap.SetAsBox(1.0f, 18.0f);
b2Body* breakBodyLeft = m_world->CreateBody(&groundDef);
breakBodyLeft->CreateFixture(&groundShap, 0.0f);
groundDef.position = b2Vec2(99.0f, 20.0f);
groundShap.SetAsBox(1.0f, 18.0f);
b2Body* breakBodyRight = m_world->CreateBody(&groundDef);
breakBodyRight->CreateFixture(&groundShap, 0.0f);
// slope
groundDef.position.Set(0.0f, 20.0f);
groundDef.angle = -0.3f;
groundShap.SetAsBox(20.0f,0.2f);
b2Body* slope = m_world->CreateBody(&groundDef);
slope->CreateFixture(&groundShap, 0.0f);
// wheel
b2BodyDef wheelDef;
wheelDef.type = b2_dynamicBody;
wheelDef.position = b2Vec2(-5.0f, 32.0f);
b2CircleShape wheelShap;
wheelShap.m_p.SetZero();
wheelShap.m_radius = 3.0f;
b2FixtureDef wheelFixture;
wheelFixture.shape = &wheelShap;
wheelFixture.density = 3.0f;
wheelFixture.friction = 5.5f;
wheelFixture.restitution = 0.3f;
b2Body* wheelBody1 = m_world->CreateBody(&wheelDef);
wheelBody1->CreateFixture(&wheelFixture);
wheelDef.position.x += 10.0f;
b2Body* wheelBody2 = m_world->CreateBody(&wheelDef);
wheelBody2->CreateFixture(&wheelFixture);
// join the two wheels
b2DistanceJointDef wjion;
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition(), wheelBody2->GetPosition());
m_world->CreateJoint(&wjion);
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition()+b2Vec2(0, 1), wheelBody2->GetPosition()+b2Vec2(0, 1));
m_world->CreateJoint(&wjion);
wjion.Initialize(wheelBody1, wheelBody2, wheelBody1->GetPosition()+b2Vec2(1, 0), wheelBody2->GetPosition()+b2Vec2(1, 0));
m_world->CreateJoint(&wjion);
/*
// box
b2BodyDef boxDef;
boxDef.type = b2_dynamicBody;
boxDef.position = b2Vec2(0.0f, 25.0f);
b2PolygonShape boxShap;
boxShap.SetAsBox(5,5);
b2FixtureDef boxFixture;
boxFixture.shape = &boxShap;
boxFixture.density = 2.0f;
boxFixture.friction = 2.5f;
boxFixture.restitution = 0.01f;
b2Body* boxBody = m_world->CreateBody(&boxDef);
boxBody->CreateFixture(&boxFixture);
*/
//wheelBody2->ApplyAngularImpulse(-2000.0f);
}
static Test* Create() {
return new MySimpleTest();
}
};
[code]