void World::RunPhysics(float frame_dt) { if (!_physicsSetUp) return; _currentTouches.clear(); // fixed time step const float physicsDT = 1.0f/60.f; float total_step = _physicsRemainderDT + frame_dt; while (total_step >= physicsDT) { // more iterations -> more stability, more cpu // tune to your liking... GetPhysicsWorld().Step(physicsDT, /*iterations*/ 10); total_step -= physicsDT; } _physicsRemainderDT = total_step; // update PhysicsActors for (b2Body* b = GetPhysicsWorld().GetBodyList(); b; b = b->GetNext()) { b2Vec2 vec = b->GetPosition(); PhysicsActor *physActor = reinterpret_cast<PhysicsActor*>(b->GetUserData()); if (physActor != NULL) { physActor->_syncPosRot(vec.x, vec.y, MathUtil::ToDegrees(b->GetAngle())); } } }
void World::WakeAllPhysics() { for (b2Body* b = GetPhysicsWorld().GetBodyList(); b; b = b->GetNext()) { b->WakeUp(); } }
RuntimeGameObject::~RuntimeGameObject() { auto body = _body.lock(); auto world = _gameWorld.lock(); if (body && world) { world->GetPhysicsWorld()->DestroyBody(body); } }