I am using Bullet, and am attempting to make a collision algorithm that generates contact points off of a voxel (cube) based terrain, and creates the appropriate collision response. I also plan to extend this to include non-box shapes too, however that is not vital atm. I've found that using a trimesh is too much of a RAM hog for large maps.
I have tried the procedure outlined by Byte56 here, How do I implement a Bullet Physics CollisionObject that represents my cube like terrain? , however, I have a number of questions regarding implementing this with Bullet.
- How do you generate a collision shape for the world? Do you use a custom shape? What do you set
m_shapeTypeto be on it?
- Or do you still use a box shape the size of the world?
- How do you ensure that contact points are freed?
- How exactly do you modify
What I've done:
- I've created a
btBoxShape, the only difference being that
m_shapeType = CUSTOM_CONVEX_SHAPE_TYPE, in order for me to be able to register a new collision algorithm with the dispatcher for objects with only this shape.
- I've extended the
btRigidBodyclass in a way similar to Byte56 in his question (see the link in the 2nd paragraph), however
checkCollisionWith(CollisionObject * co)returns true if ANY voxel in the aabb of
cois not air.
I've extended the
btCollisionAlgorithmclass, in a way similar to
processCollisiondoing the following:
- Check the colliding objects passed as arguments, and determine which is the terrain, and which is the entity.
- Clear the manifolds any child algorithms.
- Generate new box shapes and transforms in the AABB occupied by the colliding entity, and then call
m_dispatcher->findAlgorithm. Store the shape, transform and found algorithm in a Child Algorithm struct for each voxel within the AABB.
- Iterate over all child algorithms, calling
- Iterate over all child algorithms, removing any now outside of the AABB of the colliding entity. (calling
processCollision is called whenever the player's aabb intersects with non-air voxels.
What doesn't: The collision response is is just plain weird... The player entity starts levitating upwards. If it walks into something, it bounces off violently. Sometimes, it is unable to keep moving on one axis after walking into something. What I suspect is going on is that contact points are not being released after collision response, possibly due to the player entity always being in the world object's aabb. I am curious to see if I am barking up the right tree w.r.t