src/collision/shapes/TriangleShape.cpp
void TriangleShape::computeSmoothMeshContact(Vector3 localContactPointTriangle, const Transform& triangleShapeToWorldTransform,
                                             const Transform& worldToOtherShapeTransform, decimal penetrationDepth, bool isTriangleShape1,
                                             Vector3& outNewLocalContactPointOtherShape, Vector3& outSmoothWorldContactTriangleNormal) const {

    // Get the smooth contact normal of the mesh at the contact point on the triangle
    Vector3 triangleLocalNormal = computeSmoothLocalContactNormalForTriangle(localContactPointTriangle);

    // Convert the local contact normal into world-space
    Vector3 triangleWorldNormal = triangleShapeToWorldTransform.getOrientation() * triangleLocalNormal;

    // Penetration axis with direction from triangle to other shape
    Vector3 triangleToOtherShapePenAxis = isTriangleShape1 ? outSmoothWorldContactTriangleNormal : -outSmoothWorldContactTriangleNormal;

    // The triangle normal should be the one in the direction out of the current colliding face of the triangle
    if (triangleWorldNormal.dot(triangleToOtherShapePenAxis) < decimal(0.0)) {
        triangleWorldNormal = -triangleWorldNormal;
        triangleLocalNormal = -triangleLocalNormal;
    }

    // Compute the final contact normal from shape 1 to shape 2
    outSmoothWorldContactTriangleNormal = isTriangleShape1 ? triangleWorldNormal : -triangleWorldNormal;

    // Re-align the local contact point on the other shape such that it is aligned along the new contact normal
    Vector3 otherShapePointTriangleSpace = localContactPointTriangle - triangleLocalNormal * penetrationDepth;
    Vector3 otherShapePoint = worldToOtherShapeTransform * triangleShapeToWorldTransform * otherShapePointTriangleSpace;
    outNewLocalContactPointOtherShape.setAllValues(otherShapePoint.x, otherShapePoint.y, otherShapePoint.z);
}
// This method implements the technique described in Game Physics Pearl book
// by Gino van der Bergen and Dirk Gregorius to get smooth triangle mesh collision. The idea is
// to replace the contact normal of the triangle shape with the precomputed normal of the triangle
// mesh at this point. Then, we need to recompute the contact point on the other shape in order to
// stay aligned with the new contact normal. This method will return the new smooth world contact
// normal of the triangle and the the local contact point on the other shape.
This method implements the technique described in Game Physics Pearl book
by Gino van der Bergen and Dirk Gregorius to get smooth triangle mesh collision. The idea is
to replace the contact normal of the triangle shape with the precomputed normal of the triangle
mesh at this point. Then, we need to recompute the contact point on the other shape in order to
stay aligned with the new contact normal. This method will return the new smooth world contact
normal of the triangle and the the local contact point on the other shape.
This method implements the technique described in Game Physics Pearl book by Gino van der Bergen and Dirk Gregorius to get smooth triangle mesh collision . The idea is to replace the contact normal of the triangle shape with the precomputed normal of the triangle mesh at this point . Then we need to recompute the contact point on the other shape in order to stay aligned with the new contact normal . This method will return the new smooth world contact normal of the triangle and the the local contact point on the other shape .
void TriangleShape::computeSmoothMeshContact(Vector3 localContactPointTriangle, const Transform& triangleShapeToWorldTransform,
                                             const Transform& worldToOtherShapeTransform, decimal penetrationDepth, bool isTriangleShape1,
                                             Vector3& outNewLocalContactPointOtherShape, Vector3& outSmoothWorldContactTriangleNormal) const {
    Vector3 triangleLocalNormal = computeSmoothLocalContactNormalForTriangle(localContactPointTriangle);
    Vector3 triangleWorldNormal = triangleShapeToWorldTransform.getOrientation() * triangleLocalNormal;
    Vector3 triangleToOtherShapePenAxis = isTriangleShape1 ? outSmoothWorldContactTriangleNormal : -outSmoothWorldContactTriangleNormal;
    if (triangleWorldNormal.dot(triangleToOtherShapePenAxis) < decimal(0.0)) {
        triangleWorldNormal = -triangleWorldNormal;
        triangleLocalNormal = -triangleLocalNormal;
    }
    outSmoothWorldContactTriangleNormal = isTriangleShape1 ? triangleWorldNormal : -triangleWorldNormal;
    Vector3 otherShapePointTriangleSpace = localContactPointTriangle - triangleLocalNormal * penetrationDepth;
    Vector3 otherShapePoint = worldToOtherShapeTransform * triangleShapeToWorldTransform * otherShapePointTriangleSpace;
    outNewLocalContactPointOtherShape.setAllValues(otherShapePoint.x, otherShapePoint.y, otherShapePoint.z);
}
void TriangleShape :: computeSmoothMeshContact ( Vector3 localContactPointTriangle , const Transform & triangleShapeToWorldTransform , const Transform & worldToOtherShapeTransform , decimal penetrationDepth , bool isTriangleShape1 , Vector3 & outNewLocalContactPointOtherShape , Vector3 & outSmoothWorldContactTriangleNormal ) const { Vector3 triangleLocalNormal = computeSmoothLocalContactNormalForTriangle ( localContactPointTriangle ) ; Vector3 triangleWorldNormal = triangleShapeToWorldTransform . getOrientation ( ) * triangleLocalNormal ; Vector3 triangleToOtherShapePenAxis = isTriangleShape1 ? outSmoothWorldContactTriangleNormal : - outSmoothWorldContactTriangleNormal ; if ( triangleWorldNormal . dot ( triangleToOtherShapePenAxis ) < decimal ( 0.0 ) ) { triangleWorldNormal = - triangleWorldNormal ; triangleLocalNormal = - triangleLocalNormal ; } outSmoothWorldContactTriangleNormal = isTriangleShape1 ? triangleWorldNormal : - triangleWorldNormal ; Vector3 otherShapePointTriangleSpace = localContactPointTriangle - triangleLocalNormal * penetrationDepth ; Vector3 otherShapePoint = worldToOtherShapeTransform * triangleShapeToWorldTransform * otherShapePointTriangleSpace ; outNewLocalContactPointOtherShape . setAllValues ( otherShapePoint . x , otherShapePoint . y , otherShapePoint . z ) ; }
This method implements the technique described in Game Physics Pearl book
by Gino van der Bergen and Dirk Gregorius to get smooth triangle mesh collision.
This method implements the technique described in Game Physics Pearl book by Gino van der Bergen and Dirk Gregorius to get smooth triangle mesh collision .
// Get the smooth contact normal of the mesh at the contact point on the triangle // Convert the local contact normal into world-space // Penetration axis with direction from triangle to other shape // The triangle normal should be the one in the direction out of the current colliding face of the triangle // Compute the final contact normal from shape 1 to shape 2 // Re-align the local contact point on the other shape such that it is aligned along the new contact normal