Is it straightforward to create a custom collidable? I would like to create a complex static object based on a special data structure that requires a special collision detection algorithm. The object has general properties that would make a fairly simple algorithm. Implementing the physics object in terms of existing collision shapes will probably suffer from bad performance.
You can combine basic shapes using CompoundCollisionShape or create HullShapes from meshes for dynamic objects, theres also GImpactCollisionShape which allows arbitrary dynamic meshes but its very CPU intense. For static objects I suggest just creating a simple version of the world mesh and using that as a MeshCollisionShape. Implementing actual new shapes is not possible, you’d have to extend bullet physics for that, but its not really necessary.
Thanks for your reply. I’ll be a bit more specific. I would like a terrain the consists of “smooth cubes”: An element in a three dimensional matrix represents a cube of fixed width at a location determined by the matrix element’s indices. In general, a face of a cube could be a triangle mesh based on, say, 4x4 points which form a “smooth” surface. If a cube’s dimensions are of the same magnitude as other collidables it would take O(1) time to find just a few 4x4 trimesh candidates to test collision against.
Can I simply throw in all 4x4 trimeshes to the physics engine and expect good performance? I estimate the number of trimeshes to be in the thousands.
Thanks a lot.
Depending on the size of the mesh you might want to split it into multiple objects to load off work to the broadphase instead of the nearphase which is more cpu intense. How exactly your game performs well is research on your side I guess, more big meshes? more simplex shapes? who knows exactly ^^.
Hmm. What are the internal structures of Bullet, one might wonder. I mean, if i throw in a 4x4 mesh which may be contained by a “small” bounding box of sides 1 located at (0,0,0), and then if a object of size 1 is moving about (42,0,0), would that mesh need attention at all by Bullet in investigating collisions for that movement? Say there are hundreds of such meshes new (0,0,0), would that make any difference? I’d expect that Bullet has some octree of likewise going on in the background, making it really easy to discard those hundreds of meshes being candidates for collision…? If so, I am in good shape. If not, I am a bit surprised…
Theres an object for each base shape of bullet. They are all computed differently, a sphere for example is a perfect sphere, no mesh or vertexes or anything. I listed your possibilities up in the thread.
Yes, so dividing the complete terrain into tiled, “small” meshes is my strategy which would be the first idea of the possibilities you suggested. If that implies that many collision candidates can be discarded in the broad phase (as in the scenario i described) then I am happy and I probably won’t need a custom collision shape. Is that the case? If performance ends up too bad anyway is another question…
Okay, thanks a lot. I will not bug you with more questions that relate to the Bullet implementation. I should bug some Bullet guy instead