Collision Detection Algorithm - Triangle Mesh/Simple

Please don't post Bullet support questions here, use the above forums instead.
mikon
Posts: 6
Joined: Tue Sep 18, 2007 3:15 pm
Location: Germany

Collision Detection Algorithm - Triangle Mesh/Simple

Post by mikon »

Hi…

I have some problems with implementation of collision detection algorithm. I try to realize the collision detection between convex triangle mesh object and simple one. The part of initializing of objects is follow:

Code: Select all

// Define of Sphere Object
// Define shape of object Sphere
	btConvexTriangleMeshShape* _sphere_Shape = new btConvexTriangleMeshShape(_sphere_triangle);
	_sphere_Shape->setMargin(1e-6f);
	// Define translation of object Sphere
	btTransform* _sphere_TR = new btTransform();
		btMatrix3x3 _sphere_Basis;.setIdentity();
			_sphere_Basis;.setIdentity();
		_sphere_TR->setBasis(_sphere_Basis);
		_sphere_TR->setOrigin(btVector3(0.0f,0.0f,0.0f));
// Define of Plane Object
// Define shape of object Plane
	btBoxShape*	_plane_Shape = new btBoxShape(PlaneSize);
	// Define translation of object Plane
	btTransform* _plane_TR = new btTransform();
		btMatrix3x3 _plane_Basis;
			_plane_Basis;.setIdentity();
		_plane_TR->setBasis(_plane_Basis);
		_plane_TR->setOrigin(btVector3(0.0f,-0.2f,0.0f));
The part of collision detection algorithms is a simple one:

Code: Select all

btScalar penetrationDepth = 0.0f;
btVector3 penetrationVector(0.0f, 0.0f, 0.0f);
btScalar hasResult = 0.0f;

// Update Transformation Matrix
sphere_TR->setOrigin(LinPos[0]);
// Collision Detection
btGjkPairDetector convexConvex(plane_Shape,sphere_Shape,&sGjkSimplexSolver,&sGjkPenetrationDepthSolver);
btGjkPairDetector::ClosestPointInput input;
	input.m_transformA = *plane_TR; 
	input.m_transformB = *sphere_TR; 
btPointCollector gjkOutput;
	convexConvex.getClosestPoints(input, gjkOutput, 0);
if (gjkOutput.m_hasResult && gjkOutput.m_distance<0.0f) { hasResult = 1.0f; penetrationDepth = -gjkOutput.m_distance; penetrationVector = gjkOutput.m_distance*gjkOutput.m_normalOnBInWorld; }
else { hasResult = 0.0f; penetrationDepth = 0.0f; penetrationVector = 0.0*gjkOutput.m_normalOnBInWorld; }
The problem is follow – if I have the convex triangle objects with about 500 triangles, the algorithm is fast. But if I load the objects with about 15000 triangles, the algorithm becomes to be very slow. Everything will be OK, if this slow calculation happens only if the objects penetrate each other but if the objects don’t penetrates the algorithm must be faster. I think the problem is that I implement only the “narrow phase” of collision detection algorithm.

The question is follow – what I do wrong and how to increase the speed of calculation during the non-penetrate phase?

Thx / Brgds
Mikhail Konev
User avatar
projectileman
Posts: 109
Joined: Thu Dec 14, 2006 4:27 pm
Location: Colombia

Re: Collision Detection Algorithm - Triangle Mesh/Simple

Post by projectileman »

If you have large meshes, you should subdivide them.
Just take a look to ConvexDecompositionDemo and ConvexDecomposition in Extras folder.

Also you can try GIMPACT.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Collision Detection Algorithm - Triangle Mesh/Simple

Post by Erwin Coumans »

What do you mean by 'simple one' ?

If you deal with large static (non-moving) 3d triangle meshes, the recommended way it to use the btBvhTriangleMeshShape. See ConcaveDemo how to use this.

Moving convex triangles meshes shouldn't have more then 100 vertices, otherwise it would approximate a sphere/cylinder.

Can you please describe how you use those triangle meshes exactly?
Thanks,
Erwin

By the way, please use the Bullet section, not the general physics section.
mikon
Posts: 6
Joined: Tue Sep 18, 2007 3:15 pm
Location: Germany

Re: Collision Detection Algorithm - Triangle Mesh/Simple

Post by mikon »

Hi...
Thx for the fasr answer.
I'm here for a first time, that's why I didn't see the Bullet section. Erwin Coumans, if you can please move my post to the corresponding section.
May be I've explained my question not exact or very simple. Now I'll try to expand my question.
My task is to implement contact proccessing in Matlab/Simulink for the simulaton of robotic sysmets. For this purpose I need to determine the penetration depth between objects (for example it can be tool of manipulator and some obstacle, leg of legged robot and underground and so on). I've already tried to solve this task using Solid, but I got some problem, the most important one was not stable penetration derermination. That's why I try to use Bullet for determination of penetration depth and only for this. First tests give me a very good and stable results. In comparison to Solid, Bullet gives more stable results, but if I load the triangle mesh object with a number of triangle about 15000 it very slow. I think that the problem is that I use btGjkPairDetector for calculation the penetration depth, but it result is the distance between objects and not only the penetrion. If I understand right, I must to use btCollisionWorld for my task, am I?

Thx/Brgds - Mikhail Konev