Hi pico,
Interesting. I guess this solution worked across the board for us because our artists maintained the winding order of our collision meshes, so we never had these problems once we straightened it out initially.
This leads me to think that Bullet doesn't care about the actual normal of the triangles in a mesh when it collides? I'm not sure how the simplex solver returns the points that determine the contact normal, but it certainly doesn't seem to have anything to do with the triangle normal. Is this correct? If so, perhaps we can compare the normal computed from the simplex solver points with the triangle normal, and set the contact normal to the triangle normal, but reversed if it isn't in the same direction as the current contact normal. Something like this...
Code:
//////////////////////////////////////////////////////////////
// NotifyOnCollision
// Let an object know it's been collided
//////////////////////////////////////////////////////////////
bool NotifyOnCollision(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1)
{
// Correct the normal
if (colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE)
{
btVector3 tempNorm;
((btTriangleShape*)colObj0->getCollisionShape())->calcNormal(tempNorm);
if(tempNorm.dot(cp.m_normalWorldOnB) < 1)
cp.m_normalWorldOnB = tempNorm * -1;
else
cp.m_normalWorldOnB = tempNorm;
}
else if (colObj1->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE)
{
btVector3 tempNorm;
((btTriangleShape*)colObj1->getCollisionShape())->calcNormal(tempNorm);
if(tempNorm.dot(cp.m_normalWorldOnB) < 1)
cp.m_normalWorldOnB = tempNorm * -1;
else
cp.m_normalWorldOnB = tempNorm;
}
}
One problem with this solution is that I don't know (perhaps due again to my lack of knowledge with the simplex solver) what the "incorrect" normals will be in those cases where the edges cause collisions, so I don't know if the dot product test will be sufficient, or appropriate.
Hope this helps.
- Alex