fast speed yet slow moving...in direct9

General Box2D issues or C++ specific issues
sunsflower
Posts: 2
Joined: Sun Oct 11, 2015 9:34 pm

fast speed yet slow moving...in direct9

Postby sunsflower » Sun Oct 11, 2015 10:05 pm

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);

sunsflower
Posts: 2
Joined: Sun Oct 11, 2015 9:34 pm

Re: fast speed yet slow moving...in direct9

Postby sunsflower » Tue Oct 27, 2015 11:18 pm

anyone here?... now I know it's because box2d use meters to calculate physics stuff. So when I pass data to box2d I divided them by 100 and when I get data from box2d I multipy them by 100. It works but results in some incorrectness of the output data - they are a little bit smaller than the original ones. Do you know what happend?


Return to “Bugs, Requests, and Feedback”



Who is online

Users browsing this forum: No registered users and 2 guests