void BulletPhysics::SendCollisionPairAddEvent(const btPersistentManifold* manifold, const btRigidBody* body0, const btRigidBody* body1) { // send an event for 2 bodies colliding if (body0->getUserPointer() || body1->getUserPointer()) { // only triggers have non NULL user pointers, so this is a trigger collision const btRigidBody* triggerBody; const btRigidBody* otherBody; if (body0->getUserPointer()) { // body0 is the trigger triggerBody = body0; otherBody = body1; } else { // body1 is the trigger otherBody = body0; triggerBody = body1; } // send trigger event const int triggerId = *static_cast<int*>(triggerBody->getUserPointer()); shared_ptr<Event_PhysTriggerEnter> pEvent(CB_NEW Event_PhysTriggerEnter(triggerId, FindObjectId(otherBody))); IEventManager::Get()->QueueEvent(pEvent); } else { // two non-trigger bodies const GameObjectId id0 = FindObjectId(body0); const GameObjectId id1 = FindObjectId(body1); if (id0 == INVALID_GAMEOBJECT_ID || id1 == INVALID_GAMEOBJECT_ID) { // something collided with a non game object, ignore it return; } // send collision began event Vec3List collisionPoints; Vec3 sumNormalForce; Vec3 sumFrictionForce; for (int i = 0; i < manifold->getNumContacts(); i++) { const btManifoldPoint& point = manifold->getContactPoint(i); collisionPoints.push_back(btVector3_to_Vec3(point.getPositionWorldOnB())); sumNormalForce += btVector3_to_Vec3(point.m_combinedRestitution * point.m_normalWorldOnB); sumFrictionForce += btVector3_to_Vec3(point.m_combinedFriction * point.m_lateralFrictionDir1); } // send game event shared_ptr<Event_PhysCollision> pEvent(CB_NEW Event_PhysCollision(id0, id1, sumNormalForce, sumFrictionForce, collisionPoints)); IEventManager::Get()->QueueEvent(pEvent); } }
/* virtual */ void ParticleSystem::Draw() { // this is slow! Vec3List parts; parts.reserve(numParticles); FOR_EACH(pIt, particles) { Particle* p = *pIt; if (not p->alive) continue; parts.push_back(p->pos); }