collision btGImpactMeshShape and btBvhTriangleMeshShape

tpost
Posts: 1
Joined: Wed Dec 12, 2012 9:51 am

collision btGImpactMeshShape and btBvhTriangleMeshShape

Post by tpost »

I have a scene (a moving car, and a world) where I'd like to do collision detection between the Scenen and the car. (no physics, just collision detection)
So I made a btGImpactMeshShape for both of them. Each has about 80'000 triangles. This has a very poor performance, but collisions are detected correct.
To speed up the collision detection I thought I can put the world into a btBvhTriangleMeshShape. But as soon as I do that, collisions aren't detected anymore.

Code: Select all

btCollisionObject *collisionObject = new btCollisionObject()
if(strcmp(name,"scene") == 0) {
    btBvhTriangleMeshShape *collisionShape = new btBvhTriangleMeshShape(mesh, true);
    collisionObject->setCollisionShape(collisionShape);
} else {
    btGImpactMeshShape *collisionShape = new btGImpactMeshShape(mesh);
    collisionShape->updateBound();
    collisionObject->setCollisionShape(collisionShape);
}
Anyone any ideas what I'm doing wrong? I'm new to bullet so it might be some basic misunderstanding!
jay
Posts: 1
Joined: Tue Feb 05, 2013 5:12 am

Re: collision btGImpactMeshShape and btBvhTriangleMeshShape

Post by jay »

I've run into the same problem and haven't found a good solution yet using a btGImpactMeshShape for the moving object (a rocket in my case). What has worked is using a btConvexHullShape, and I just manually decomposed my rocket into convex meshes and joined them together as a btCompoundShape.

Code: Select all

    StlMesh *mesh = new StlMesh(filename); // StlMesh extends btTriangleMesh
    
    btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(mesh);
 
    // create a hull approximation
    btShapeHull* hull = new btShapeHull(tmpConvexShape);
    btScalar margin = tmpConvexShape->getMargin();
    hull->buildHull(margin);
    tmpConvexShape->setUserPointer(hull);
  
    btConvexHullShape* convexShape = new btConvexHullShape();
    for (int i=0;i<hull->numVertices();i++) {
        convexShape->addPoint(hull->getVertexPointer()[i]); 
    }

    // Now, use convexShape as the shape for your btRigidBodies or whatever.
Good luck