Пример #1
0
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()));
		}
	}
}
Пример #2
0
void World::WakeAllPhysics()
{
	for (b2Body* b = GetPhysicsWorld().GetBodyList(); b; b = b->GetNext())
	{
		b->WakeUp();
	}
}
Пример #3
0
    RuntimeGameObject::~RuntimeGameObject()
    {
        auto body = _body.lock();
        auto world = _gameWorld.lock();

        if (body && world)
        {
            world->GetPhysicsWorld()->DestroyBody(body);
        }
    }