It seems that everything is alright. Yet when I run the program, the box accelerates till its speed reaches 120(this is the same as in testbed). But till then, the box only moves a tiny little distance on screen. What's wrong with my program?
Code: Select all
void b2_intg::create_body(b2World* m_world, vector2 pos, b2BodyType type)
{
body = NULL;
b2BodyDef mbodydef;
mbodydef.type = type;
mbodydef.position.Set(pos.x, pos.y);
body = m_world->CreateBody(&mbodydef);
}
void b2_intg::add_fixture(vector<vector2> vert, shape_type type)
{
vector<b2Vec2> b2vert;
for (size_t i = 0; i < vert.size(); i++)
{
b2vert.push_back( b2Vec2(vert[i].x, vert[i].y) );
}
if (type == shape_type::edge && vert.size() == 2)
{
b2EdgeShape bedge;
bedge.Set(b2Vec2(vert[0].x, vert[0].y), b2Vec2(vert[1].x, vert[1].y));
b2FixtureDef fixdef;
fixdef.density = 2;
fixdef.shape = &bedge;
body->CreateFixture(&fixdef);
}
else if (type == shape_type::polygon && vert.size() > 2)
{
b2PolygonShape bpoly;
bpoly.Set(&b2vert[0], b2vert.size());
b2FixtureDef fixdef;
fixdef.density = 1;
fixdef.shape = &bpoly;
body->CreateFixture(&fixdef);
}
}
//different file
t_world = new b2World(b2Vec2(0, 20));
//different file
t_world->Step(1.f / 60.f, 8, 3);