void run() {
			btCollisionObject *obj0 = (btCollisionObject *)m_pair.m_pProxy0->m_clientObject;
			btCollisionObject *obj1 = (btCollisionObject *)m_pair.m_pProxy1->m_clientObject;

			// Check for invalid numbers being passed through
			btAssert(obj0->getWorldTransform() == obj0->getWorldTransform());
			btAssert(obj1->getWorldTransform() == obj1->getWorldTransform());

			btCollisionObjectWrapper obj0Wrap(0, obj0->getCollisionShape(), obj0, obj0->getWorldTransform(), -1, -1);
			btCollisionObjectWrapper obj1Wrap(0, obj1->getCollisionShape(), obj1, obj1->getWorldTransform(), -1, -1);

			if (!m_pair.m_algorithm) {
				m_pair.m_algorithm = m_pDispatcher->findAlgorithm(&obj0Wrap, &obj1Wrap);
			}

			if (m_pair.m_algorithm) {
				btManifoldResult contactPointResult(&obj0Wrap, &obj1Wrap);
				
				if (m_pInfo->m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE) {
					m_pair.m_algorithm->processCollision(&obj0Wrap, &obj1Wrap, *m_pInfo, &contactPointResult);
				} else {
					// Continuous dispatch
					m_pair.m_algorithm->calculateTimeOfImpact(obj0, obj1, *m_pInfo, &contactPointResult);
				}
			}
		}
Пример #2
0
void Uncollider::nearCallback(btBroadphasePair &collisionPair,
  btCollisionDispatcher &dispatcher, const btDispatcherInfo &dispatchInfo) {

  btCollisionObject *colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
  btCollisionObject *colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;

  if (dispatcher.needsCollision(colObj0, colObj1)) {
    btCollisionObjectWrapper obj0Wrap(nullptr, colObj0->getCollisionShape(),
      colObj0, colObj0->getWorldTransform(), -1, -1);
    btCollisionObjectWrapper obj1Wrap(nullptr, colObj1->getCollisionShape(),
      colObj1, colObj1->getWorldTransform(), -1, -1);

    btManifoldResult contactPointResult(&obj0Wrap, &obj1Wrap);

    if (not collisionPair.m_algorithm) {
#if (BT_BULLET_VERSION >=286)
      collisionPair.m_algorithm =
        dispatcher.findAlgorithm(&obj0Wrap, &obj1Wrap,
                                 contactPointResult.getPersistentManifold(),
                                 ebtDispatcherQueryType::BT_CONTACT_POINT_ALGORITHMS);
#else
      collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap, &obj1Wrap);
#endif
    }
    if (collisionPair.m_algorithm) {
      if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE) {
        collisionPair.m_algorithm->processCollision(&obj0Wrap, &obj1Wrap, dispatchInfo,
          &contactPointResult);
        for (int i = 0; i < contactPointResult.getPersistentManifold()->getNumContacts(); ++i) {
          const btManifoldPoint &pt = contactPointResult.getPersistentManifold()->
            getContactPoint(i);
          const btVector3 &cp = pt.getPositionWorldOnA();
          if (isPointInUncollideVolume(cp)) {
            contactPointResult.getPersistentManifold()->removeContactPoint(i--);
          }
        }
      } else {
        btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0, colObj1,
          dispatchInfo, &contactPointResult);
        if (dispatchInfo.m_timeOfImpact > toi) {
          dispatchInfo.m_timeOfImpact = toi;
        }
      }
    }
  }
}
Пример #3
0
//вызываеться при столкновении геометрий
void PhysicsManager::mNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
{

    btCollisionObject* colObj0 = static_cast<btCollisionObject*>(collisionPair.m_pProxy0->m_clientObject);
    btCollisionObject* colObj1 = static_cast<btCollisionObject*>(collisionPair.m_pProxy1->m_clientObject);

    if(dispatcher.needsCollision(colObj0,colObj1)) 
    {
        btCollisionObjectWrapper obj0Wrap(0,colObj0->getCollisionShape(),colObj0,colObj0->getWorldTransform());
        btCollisionObjectWrapper obj1Wrap(0,colObj1->getCollisionShape(),colObj1,colObj1->getWorldTransform());
            //dispatcher will keep algorithms persistent in the collision pair
        if (!collisionPair.m_algorithm) 
        {
            collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap);
        }

        if (collisionPair.m_algorithm)
        {
            btManifoldResult contactPointResult(&obj0Wrap,&obj1Wrap);

            if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE) 
            {
                  //discrete collision detection query
                collisionPair.m_algorithm->processCollision(&obj0Wrap,&obj1Wrap,dispatchInfo,&contactPointResult);
            } 
            else 
            {
                  //continuous collision detection query, time of impact (toi)
                btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
                if (dispatchInfo.m_timeOfImpact > toi) 
                {
                    dispatchInfo.m_timeOfImpact = toi;
                }
            }

            if (contactPointResult.getPersistentManifold()->getNumContacts()>0)  //только сдесь мы уверены что есть пересечения 
            {
                GameLogic::getSingletonPtr()->CollideBody(colObj0, colObj1);
            }
        }
    }
    dispatcher.defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
}
Пример #4
0
//by default, Bullet will use this near callback
void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
{
		btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
		btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;

		if (dispatcher.needsCollision(colObj0,colObj1))
		{
			btCollisionObjectWrapper obj0Wrap(0,colObj0->getCollisionShape(),colObj0,colObj0->getWorldTransform(),-1,-1);
			btCollisionObjectWrapper obj1Wrap(0,colObj1->getCollisionShape(),colObj1,colObj1->getWorldTransform(),-1,-1);


			//dispatcher will keep algorithms persistent in the collision pair
			if (!collisionPair.m_algorithm)
			{
				collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap);
			}

			if (collisionPair.m_algorithm)
			{
				btManifoldResult contactPointResult(&obj0Wrap,&obj1Wrap);
				
				if (dispatchInfo.m_dispatchFunc == 		btDispatcherInfo::DISPATCH_DISCRETE)
				{
					//discrete collision detection query
					
					collisionPair.m_algorithm->processCollision(&obj0Wrap,&obj1Wrap,dispatchInfo,&contactPointResult);
				} else
				{
					//continuous collision detection query, time of impact (toi)
					btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
					if (dispatchInfo.m_timeOfImpact > toi)
						dispatchInfo.m_timeOfImpact = toi;

				}
			}
		}

}