I'm doing something obviously dumb, but I can't figure it out. I *almost* have a test example working but not quite. I've got an 800x600 window, where 0,0 is the top left and 799,599 is the bottom right of the screen. I'm trying to put a floor of size 800x20 at location 0, 580, and a player object (an ugly square) at 0, 200. I get the player to fall and eventually hit the floor.....but it's not stopping at the correct spot. Weirdly, I found that if I set the extents on the player to <anything>x10 (meaning a width of any value and a height of 20) it lands perfectly....but if I change the height at all it doesn't. Here's how I'm setting things up:
I'm doing 10 iterations and have a time step of 1/60.0. My update loop only contains gWorld->Step(gTimeStep, gIterations). Perhaps my draw function is to blame? Here's how I draw things:
Thanks a ton for the help, I really appreciate it.
Code:
b2AABB worldbb;
worldbb.minVertex.Set(0, 0);
worldbb.maxVertex.Set(800, 600);
gWorld = new b2World(worldbb, b2Vec2(0, 100.0f), true);
b2BoxDef groundBoxDef;
groundBoxDef.extents.Set(800 / 2, 20 / 2);
groundBoxDef.density = 0.0f;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 580);
groundBodyDef.AddShape(&groundBoxDef);
gGround = gWorld->CreateBody(&groundBodyDef);
b2BoxDef boxDef;
boxDef.extents.Set(gPlayerWidth/2, gPlayerHeight/2);
boxDef.density = 10.0f;
boxDef.friction = 0.3f;
b2BodyDef bodyDef;
bodyDef.position.Set(0, 200);
bodyDef.AddShape(&boxDef);
gPlayer = gWorld->CreateBody(&bodyDef);
gPlayer->m_invI = 0.0f; // don't rotate
worldbb.minVertex.Set(0, 0);
worldbb.maxVertex.Set(800, 600);
gWorld = new b2World(worldbb, b2Vec2(0, 100.0f), true);
b2BoxDef groundBoxDef;
groundBoxDef.extents.Set(800 / 2, 20 / 2);
groundBoxDef.density = 0.0f;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 580);
groundBodyDef.AddShape(&groundBoxDef);
gGround = gWorld->CreateBody(&groundBodyDef);
b2BoxDef boxDef;
boxDef.extents.Set(gPlayerWidth/2, gPlayerHeight/2);
boxDef.density = 10.0f;
boxDef.friction = 0.3f;
b2BodyDef bodyDef;
bodyDef.position.Set(0, 200);
bodyDef.AddShape(&boxDef);
gPlayer = gWorld->CreateBody(&bodyDef);
gPlayer->m_invI = 0.0f; // don't rotate
I'm doing 10 iterations and have a time step of 1/60.0. My update loop only contains gWorld->Step(gTimeStep, gIterations). Perhaps my draw function is to blame? Here's how I draw things:
Code:
b2Vec2 gpos = gGround->GetOriginPosition();
b2Vec2 ppos = gPlayer->GetOriginPosition();
// white color, draw at X, Y with width/height of 800, 20
SetColor(Color::White);
FillRect(gpos.x, gpos.y, 800, 20);
SetColor(Color(255, 0, 0));
FillRect(ppos.x, ppos.y, gPlayerWidth, gPlayerHeight);
b2Vec2 ppos = gPlayer->GetOriginPosition();
// white color, draw at X, Y with width/height of 800, 20
SetColor(Color::White);
FillRect(gpos.x, gpos.y, 800, 20);
SetColor(Color(255, 0, 0));
FillRect(ppos.x, ppos.y, gPlayerWidth, gPlayerHeight);
Thanks a ton for the help, I really appreciate it.