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));
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 question is follow – what I do wrong and how to increase the speed of calculation during the non-penetrate phase?
Thx / Brgds
Mikhail Konev