Problem specific question about bullet collision detection

Post Reply
uschwes
Posts: 2
Joined: Wed Mar 05, 2014 10:12 am

Problem specific question about bullet collision detection

Post by uschwes »

Hi guys,

I am fairly new to bullet and have a specific use case where I could use your expertise. It aims at implementation details regarding the collision detection in bullet.

Here's the problem: I have a couple of car-like vehicles (box shapes or even sphere shapes for simplicity) together with their future positions (2D) over a certain time horizon. So each car's future path is represented by discretized tuples of 2D position and time. I have the same for an ego car. Now I want to find out whether the trajectory of my ego car collides with any other car's trajectory now or in the future.

What I did so far was interpreting the usual z-coordinate in the world as time and inserting the discretized position/time tuples of the other car's in a btCollisionWorld. Afterwards I am querying each discretized position/time tuple of the ego car for collision with the btCollisionWorld via the btCollisionWorld::ContactResultCallback. A boiled down code example (illustrative) is here:

Code: Select all


class CollisionCallback : public ::btCollisionWorld::ContactResultCallback {

  CollisionCallback()
      : btCollisionWorld::ContactResultCallback(),
        m_collisionOccured(false) {
  }

  inline virtual bool needsCollision(btBroadphaseProxy* proxy) const {
    if (!btCollisionWorld::ContactResultCallback::needsCollision(proxy)) {
      return false;
    }
    return true;
  }
  inline virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0,
                                   const btCollisionObject* colObj1, int partId1, int index1) {
    m_collisionOccured = true;
    return (btScalar)0;  // not actually sure if return value is used for anything...?
  }
  bool m_collisionOccured;
};

btBroadphaseInterface* m_broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* m_collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* m_dispatcher = new btCollisionDispatcher(collisionConfiguration);
btCollisionWorld* m_collisionWorld = new btCollisionWorld(m_dispatcher, m_broadphase, m_collisionConfiguration);

// add all the discretized position/time tuples of the other cars
for(size_t i=0; i<nCars; i++) {
  for (size_t j=0; j<nPosesPerCar; j++) {
    btBoxShape* box = new btBoxShape(btVector3(halfSizeX, halfSizeY, halfSizeZ));
    btCollisionObject* obj = new btCollisionObject();
    obj->setCollisionShape(box);

    btTransform tf;
    tf.setOrigin(btVector3(xObject, yObject, timeObject));
    tfQuery.setRotation(btQuaternion(yawObject, 0., 0.));
    obj->setWorldTransform(tf);
    m_collisionWorld->addCollisionObject(obj);
  }
}

// query all the ego position/time tuples
for (size_t i=0; i<nEgoPoses; i++) {
  m_collisionWorld->contactTest(egoPose[i], m_collisionCallback);
  if (m_collisionCallback.m_collisionOccured) {
    return true;
  }
}

This code kind of works, but I have two questions regarding this approach:
  1. For some reason, this approach gets quite slow when objects get close together, hence when we have to go into the narrow-phase. I compared it to the AABB tree implementation of CGAL (both bullet and CGAL using spheres as collision shapes), and it gets about 2 orders of magnitude slower! Is there a major flaw in the code that would explain the difference? Is bullet performing exact contact point computation that makes it that slow? I basically only need a boolean answer, collision or not. I don't care about exact contact points. If this is the case, is there another piece of API that would speed this up?
  2. Checking each pose/time tuple of my ego car seems not optimal to me performance-wise. I guess performance would be better if the poses of the ego car would get pushed into another AABB tree, and then these two trees are traversed in order to determine whether they collide somewhere. Is that possible in bullet? I could not find the correct things in the API.

Thanks in advance for your answers,

Ulrich
uschwes
Posts: 2
Joined: Wed Mar 05, 2014 10:12 am

Re: Problem specific question about bullet collision detecti

Post by uschwes »

Update: It seems like the addSingleResult method in the ContactResultCallback is called for every generated contact point. I would like to abort the test whenever the first contact point is found. Is there a way to do so?
nictosi
Posts: 11
Joined: Mon Jul 06, 2015 9:25 am

Re: Problem specific question about bullet collision detecti

Post by nictosi »

uschwes wrote:Update: It seems like the addSingleResult method in the ContactResultCallback is called for every generated contact point. I would like to abort the test whenever the first contact point is found. Is there a way to do so?
Same problem here. Have you found any solution in the mean time?
Post Reply