ソースを参照

Added sub shape ID's to friction/restitution combine function (#144)

Jorrit Rouwe 3 年 前
コミット
6b87356373

+ 6 - 6
Jolt/Physics/Constraints/ContactConstraintManager.cpp

@@ -777,8 +777,8 @@ void ContactConstraintManager::GetContactsFromCache(ContactAllocator &ioContactA
 
 		// Calculate default contact settings
 		ContactSettings settings;
-		settings.mCombinedFriction = mCombineFriction(*body1, *body2);
-		settings.mCombinedRestitution = mCombineRestitution(*body1, *body2);
+		settings.mCombinedFriction = mCombineFriction(*body1, input_key.GetSubShapeID1(), *body2, input_key.GetSubShapeID2());
+		settings.mCombinedRestitution = mCombineRestitution(*body1, input_key.GetSubShapeID1(), *body2, input_key.GetSubShapeID2());
 
 		// Calculate world space contact normal
 		Vec3 world_space_normal = transform_body2.Multiply3x3(Vec3::sLoadFloat3Unsafe(output_cm->mContactNormal)).Normalized();
@@ -928,8 +928,8 @@ void ContactConstraintManager::TemplatedAddContactConstraint(ContactAllocator &i
 
 	// Settings object that gets passed to the callback
 	ContactSettings settings;
-	settings.mCombinedFriction = mCombineFriction(inBody1, inBody2);
-	settings.mCombinedRestitution = mCombineRestitution(inBody1, inBody2);
+	settings.mCombinedFriction = mCombineFriction(inBody1, inManifold.mSubShapeID1, inBody2, inManifold.mSubShapeID2);
+	settings.mCombinedRestitution = mCombineRestitution(inBody1, inManifold.mSubShapeID1, inBody2, inManifold.mSubShapeID2);
 
 	// Get the contact points for the old cache entry
 	const ManifoldCache &read_cache = mCache[mCacheWriteIdx ^ 1];
@@ -1174,8 +1174,8 @@ void ContactConstraintManager::OnCCDContactAdded(ContactAllocator &ioContactAllo
 	JPH_ASSERT(inManifold.mWorldSpaceNormal.IsNormalized());
 
 	// Calculate contact settings
-	outSettings.mCombinedFriction = mCombineFriction(inBody1, inBody2);
-	outSettings.mCombinedRestitution = mCombineRestitution(inBody1, inBody2);
+	outSettings.mCombinedFriction = mCombineFriction(inBody1, inManifold.mSubShapeID1, inBody2, inManifold.mSubShapeID2);
+	outSettings.mCombinedRestitution = mCombineRestitution(inBody1, inManifold.mSubShapeID1, inBody2, inManifold.mSubShapeID2);
 
 	// The remainder of this function only deals with calling contact callbacks, if there's no contact callback we also don't need to do this work
 	if (mContactListener != nullptr)

+ 3 - 3
Jolt/Physics/Constraints/ContactConstraintManager.h

@@ -38,7 +38,7 @@ public:
 	ContactListener *			GetContactListener() const											{ return mContactListener; }
 
 	/// Callback function to combine the restitution or friction of two bodies
-	using CombineFunction = float (*)(const Body &inBody1, const Body &inBody2);
+	using CombineFunction = float (*)(const Body &inBody1, const SubShapeID &inSubShapeID1, const Body &inBody2, const SubShapeID &inSubShapeID2);
 
 	/// Set the function that combines the friction of two bodies and returns it
 	/// Default method is the geometric mean: sqrt(friction1 * friction2).
@@ -467,8 +467,8 @@ private:
 	ContactListener *			mContactListener = nullptr;
 
 	/// Functions that are used to combine friction and restitution of 2 bodies
-	CombineFunction				mCombineFriction = [](const Body &inBody1, const Body &inBody2) { return sqrt(inBody1.GetFriction() * inBody2.GetFriction()); };
-	CombineFunction				mCombineRestitution = [](const Body &inBody1, const Body &inBody2) { return max(inBody1.GetRestitution(), inBody2.GetRestitution()); };
+	CombineFunction				mCombineFriction = [](const Body &inBody1, const SubShapeID &, const Body &inBody2, const SubShapeID &) { return sqrt(inBody1.GetFriction() * inBody2.GetFriction()); };
+	CombineFunction				mCombineRestitution = [](const Body &inBody1, const SubShapeID &, const Body &inBody2, const SubShapeID &) { return max(inBody1.GetRestitution(), inBody2.GetRestitution()); };
 
 	/// The constraints that were added this frame
 	ContactConstraint *			mConstraints = nullptr;