Hey,
So I'm using bullet in my opengl project, and so far I'm enjoying very much.
Just to test things out, I added to my OpenGL scene 16 cones with 64 triangles, 16 spheres with 1600 triangles each, and a floor where all these objects can fall and collide with each other. The problem is when the collisions start happening, and the framerate drops alot.
I'm using btTriangleMesh for all the objects and I'm sharing the btCollisionShape among objects with the same collision shape, so, in the end, there are only 3 collision shapes (cone, sphere and floor).
I can understand that using a btTriangleMesh to represent my 1600 triangles sphere is probably not the best. Could that be the reason why my app is so slow? If so, any tips? Need to see some of my code?
Thanks!
slow collision detection
-
- Posts: 107
- Joined: Fri Sep 19, 2008 6:08 pm
Re: slow collision detection
btTriangleMesh might be using a face to face collision detection. But since you are using standard primitive shapes, why don't you go for Bullet's standard primitive collision shapes? eg, use Sphere for your sphere object. Use the cone collision shape for your cones. Collision detection works fastest when you use these primitive shapes to approximate your game objects.
btTriangleMesh seems like also good for static objects, so you may want to use this for your levels or any objects that you don't need to move.
Hope that helps.
btTriangleMesh seems like also good for static objects, so you may want to use this for your levels or any objects that you don't need to move.
Hope that helps.
-
- Posts: 21
- Joined: Sun Oct 12, 2008 3:38 pm
Re: slow collision detection
I see, the thing is I don't know what objects my scene will include, they can be very simple or they can be very complex. At least they're going to be a bit more complex than a cube. Should I use the primitive shapes even for these objects? Or is there a better way?mickey wrote:btTriangleMesh might be using a face to face collision detection. But since you are using standard primitive shapes, why don't you go for Bullet's standard primitive collision shapes? eg, use Sphere for your sphere object. Use the cone collision shape for your cones. Collision detection works fastest when you use these primitive shapes to approximate your game objects.
btTriangleMesh seems like also good for static objects, so you may want to use this for your levels or any objects that you don't need to move.
Hope that helps.
Thanks again!
-
- Posts: 229
- Joined: Sun Sep 30, 2007 7:58 am
Re: slow collision detection
In many games simplified collision meshes are used instead of the real geometry. We often replace 'almost' cubes with bullets primitive shapes. Especially for spheres this is a must as the number of triangles is simple not needed.haba wrote:mickey wrote: I see, the thing is I don't know what objects my scene will include, they can be very simple or they can be very complex. At least they're going to be a bit more complex than a cube. Should I use the primitive shapes even for these objects? Or is there a better way?
Thanks again!
regards
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: slow collision detection
btTriangleMesh is not a collision shape, which collision shape are you using? Only use btBvhTriangleMeshShape for non-moving world geometry, and btGimpactShape can be slow.
The best is to provide the option to approximate the shape by one of the predefined types: sphere, cone, cylinder, box and convex hull. For convex hull meshes, there is an automatic way to reduce the number of vertices.
If you really need moving concave objects you can consider using an automatic convex decomposition in combination with btCompoundShape. See Bullet/Demos/ConvexDecompositionDemo.
Hope this helps,
Erwin
The best is to provide the option to approximate the shape by one of the predefined types: sphere, cone, cylinder, box and convex hull. For convex hull meshes, there is an automatic way to reduce the number of vertices.
Code: Select all
btTriangleMesh* meshInterface = ...;
btConvexTriangleMeshShape* complexHullShape = new btConvexTriangleMeshShape(meshInterface);
btShapeHull* triHull = new btShapeHull (hullShape);
if (triHull->buildHull (0.0) == false)
{
printf("Failed to build triangle mesh of hull\n");
return;
}
btConvexShape* simplifiedShape = new btConvexHullShape(triHull->getVertexPointer(),triHull->numVertices());
//now discard the complexHullShape and use simplifiedShape instead.
Hope this helps,
Erwin