|
|
@@ -14,8 +14,9 @@ class JPH_EXPORT CollideSoftBodyVerticesVsTriangles
|
|
|
{
|
|
|
public:
|
|
|
CollideSoftBodyVerticesVsTriangles(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) :
|
|
|
- mTransform(inCenterOfMassTransform * Mat44::sScale(inScale)),
|
|
|
- mInvTransform(mTransform.Inversed()),
|
|
|
+ mTransform(inCenterOfMassTransform),
|
|
|
+ mInvTransform(mTransform.InversedRotationTranslation()),
|
|
|
+ mScale(inScale),
|
|
|
mNormalSign(ScaleHelpers::IsInsideOut(inScale)? -1.0f : 1.0f)
|
|
|
{
|
|
|
}
|
|
|
@@ -28,15 +29,20 @@ public:
|
|
|
|
|
|
JPH_INLINE void ProcessTriangle(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2)
|
|
|
{
|
|
|
+ // Apply the scale to the triangle
|
|
|
+ Vec3 v0 = mScale * inV0;
|
|
|
+ Vec3 v1 = mScale * inV1;
|
|
|
+ Vec3 v2 = mScale * inV2;
|
|
|
+
|
|
|
// Get the closest point from the vertex to the triangle
|
|
|
uint32 set;
|
|
|
- Vec3 closest_point = ClosestPoint::GetClosestPointOnTriangle(inV0 - mLocalPosition, inV1 - mLocalPosition, inV2 - mLocalPosition, set);
|
|
|
+ Vec3 closest_point = ClosestPoint::GetClosestPointOnTriangle(v0 - mLocalPosition, v1 - mLocalPosition, v2 - mLocalPosition, set);
|
|
|
float dist_sq = closest_point.LengthSq();
|
|
|
if (dist_sq < mClosestDistanceSq)
|
|
|
{
|
|
|
- mV0 = inV0;
|
|
|
- mV1 = inV1;
|
|
|
- mV2 = inV2;
|
|
|
+ mV0 = v0;
|
|
|
+ mV1 = v1;
|
|
|
+ mV2 = v2;
|
|
|
mClosestPoint = closest_point;
|
|
|
mClosestDistanceSq = dist_sq;
|
|
|
mSet = set;
|
|
|
@@ -55,10 +61,10 @@ public:
|
|
|
|
|
|
if (mSet == 0b111)
|
|
|
{
|
|
|
- // Closest is interior to the triangle, use plane as collision plane but don't allow more than 0.1 m penetration
|
|
|
+ // Closest is interior to the triangle, use plane as collision plane but don't allow more than sTriangleThickness penetration
|
|
|
// because otherwise a triangle half a level a way will have a huge penetration if it is back facing
|
|
|
- float penetration = min(triangle_normal.Dot(v0 - ioVertex.GetPosition()), 0.1f);
|
|
|
- if (ioVertex.UpdatePenetration(penetration))
|
|
|
+ float penetration = triangle_normal.Dot(v0 - ioVertex.GetPosition());
|
|
|
+ if (penetration < sTriangleThickness && ioVertex.UpdatePenetration(penetration))
|
|
|
ioVertex.SetCollision(Plane::sFromPointAndNormal(v0, triangle_normal), inCollidingShapeIndex);
|
|
|
}
|
|
|
else
|
|
|
@@ -77,8 +83,14 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Triangles are considered to have some thickness. This thickness extends backwards along the negative triangle normal.
|
|
|
+ /// Make this value smaller than the smallest 'wall thickness' so that the back side of the triangle doesn't protrude through the other side.
|
|
|
+ /// Make this value too small and tunneling is more likely to occur.
|
|
|
+ static inline float sTriangleThickness = 0.1f;
|
|
|
+
|
|
|
Mat44 mTransform;
|
|
|
Mat44 mInvTransform;
|
|
|
+ Vec3 mScale;
|
|
|
Vec3 mLocalPosition;
|
|
|
Vec3 mV0, mV1, mV2;
|
|
|
Vec3 mClosestPoint;
|