Using Just Collision Detection

bobthebuilder
Posts: 6
Joined: Mon May 09, 2011 2:03 am

Using Just Collision Detection

Post by bobthebuilder »

Dear Bullet Community,

Is it possible to use just the collision detection routines from Bullet, not the dynamics? For example, say I have two triangle meshes and an associated translation and orientation for each body, and the translated/rotated meshes are intersecting. I would like to compute the contact points and contact normals of these two meshes. Is it possible to use the Bullet API at this 'level?' If so, is an example or documentation available for using the API at this level?

Thanks!
bobthebuilder
Posts: 6
Joined: Mon May 09, 2011 2:03 am

Re: Using Just Collision Detection

Post by bobthebuilder »

Can anyone tell me if I'm on the right track with this code? I've searched the forums but haven't found any similar examples.

Code: Select all

... code to load a mesh, let's say a torus ...

// Create a btTriangleIndexVertexArray
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray( m_num_torus_faces, m_torus_faces, 3*sizeof(int), m_num_torus_verts, m_torus_verts, sizeof(double)*3 );
// Create an impact shape
btGImpactMeshShape* trimesh = new btGImpactMeshShape( indexVertexArrays );
btCollisionShape* collisionShape = trimesh;

// Create a transform for the first object
btMatrix3x3 orientation0( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); // Row Major
btVector3 translation0( 0.0, 0.0, 0.0 );
btTransform shapeTransform0(orientation0,translation0);

// Create a transform for the second object
btMatrix3x3 orientation1( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); // Row Major
btVector3 translation1( 0.0, 4.0, 0.0 );
btTransform shapeTransform1(orientation1,translation1);

// Create the collision objects
btCollisionObject* collision_object0 = new btCollisionObject;
collision_object0->setCollisionShape(collisionShape);
collision_object0->setWorldTransform(shapeTransform0);

btCollisionObject* collision_object1 = new btCollisionObject;
collision_object1->setCollisionShape(collisionShape);
collision_object1->setWorldTransform(shapeTransform1);

// Create a collision algorithm
btCollisionAlgorithmConstructionInfo ci;
btGImpactCollisionAlgorithm gimpact_algorithm( ci, collision_object0, collision_object1 );

// Run narrow phase
btDispatcherInfo dispatchInfo;
btManifoldResult resultOut;
gimpact_algorithm.processCollision( collision_object0, collision_object1, dispatchInfo, &resultOut );
Unfortunately, this code segfaults in the following method in btGImpactCollisionAlgorithm:

Code: Select all

SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1)
{
   m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
   return m_manifoldPtr;
}
My goal is to JUST use the narrow phase.

Thanks for the input!
bobthebuilder
Posts: 6
Joined: Mon May 09, 2011 2:03 am

Re: Using Just Collision Detection

Post by bobthebuilder »

So, it appears btCollisionWorld has a method 'contactPairTest'. After registering GIMPACT, this should allow me to compare two primitives without invoking the broadphase, no? Is this the most 'lightweight' way to call GIMPACT, or is there a lower level interface?

Thanks for the help friends. Tschuess!