void Simple::OnTimer(wxCommandEvent& event)
{
world->Step(timeStep, velocityIterations, positionIterations);
for (b2Body *b = world->GetBodyList(); b; b=b->GetNext())
{
if(b->GetType() ==b2BodyType::b2_dynamicBody)
{
b2Fixture* fixture = b->GetFixtureList();
b2Shape* shape = b->GetFixtureList()->GetShape();
//抵消重力
switch(shape->GetType()){
case b2Shape::e_circle:
//抵消圆球的重力。重力抵消后,圆球不会下降
printf("Mass=%4.2f \n",b->GetMass());
b->ApplyForce(-(b->GetMass() * world->GetGravity()),b->GetWorldCenter(),true);
break;
case b2Shape::e_polygon:
//抵消重力后,原地旋转
b->SetGravityScale(0);//如果0改成-1,则向上漂
}
}
}
Refresh();
}