Browse Source

Rename ContactSettings::mRelativeSurfaceVelocity to mRelativeLinearSurfaceVelocity to be more consistent (#657)

Jorrit Rouwe 2 years ago
parent
commit
76b809ddb1

+ 2 - 2
Jolt/Physics/Collision/ContactListener.h

@@ -47,8 +47,8 @@ public:
 	float					mInvMassScale2 = 1.0f;				///< Scale factor for the inverse mass of body 2 (0 = infinite mass, 1 = use original mass, 2 = body has half the mass). For the same contact pair, you should strive to keep the value the same over time.
 	float					mInvMassScale2 = 1.0f;				///< Scale factor for the inverse mass of body 2 (0 = infinite mass, 1 = use original mass, 2 = body has half the mass). For the same contact pair, you should strive to keep the value the same over time.
 	float					mInvInertiaScale2 = 1.0f;			///< Scale factor for the inverse inertia of body 2 (usually same as mInvMassScale2)
 	float					mInvInertiaScale2 = 1.0f;			///< Scale factor for the inverse inertia of body 2 (usually same as mInvMassScale2)
 	bool					mIsSensor;							///< If the contact should be treated as a sensor vs body contact (no collision response)
 	bool					mIsSensor;							///< If the contact should be treated as a sensor vs body contact (no collision response)
-	Vec3					mRelativeSurfaceVelocity = Vec3::sZero(); ///< Relative surface velocity between the bodies (world space surface velocity of body 2 - world space surface velocity of body 1), can be used to create a conveyor belt effect
-	Vec3					mRelativeAngularSurfaceVelocity = Vec3::sZero(); ///< Relative angular surface velocity between the bodies (world space angular surface velocity of body 2 - world space angular surface velocity of body 1). Note that this angular velocity is relative to the center of mass of body 1, so if you want it relative to body 2's center of mass you need to add body 2 angular velocity x (body 1 world space center of mass - body 2 world space center of mass) to mRelativeSurfaceVelocity.
+	Vec3					mRelativeLinearSurfaceVelocity = Vec3::sZero(); ///< Relative linear surface velocity between the bodies (world space surface velocity of body 2 - world space surface velocity of body 1), can be used to create a conveyor belt effect
+	Vec3					mRelativeAngularSurfaceVelocity = Vec3::sZero(); ///< Relative angular surface velocity between the bodies (world space angular surface velocity of body 2 - world space angular surface velocity of body 1). Note that this angular velocity is relative to the center of mass of body 1, so if you want it relative to body 2's center of mass you need to add body 2 angular velocity x (body 1 world space center of mass - body 2 world space center of mass) to mRelativeLinearSurfaceVelocity.
 };
 };
 
 
 /// Return value for the OnContactValidate callback. Determines if the contact is being processed or not.
 /// Return value for the OnContactValidate callback. Determines if the contact is being processed or not.

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

@@ -49,7 +49,7 @@ JPH_INLINE void ContactConstraintManager::WorldContactPoint::TemplatedCalculateF
 	JPH_DET_LOG("TemplatedCalculateFrictionAndNonPenetrationConstraintProperties: p1: " << inWorldSpacePosition1 << " p2: " << inWorldSpacePosition2
 	JPH_DET_LOG("TemplatedCalculateFrictionAndNonPenetrationConstraintProperties: p1: " << inWorldSpacePosition1 << " p2: " << inWorldSpacePosition2
 		<< " normal: " << inWorldSpaceNormal << " tangent1: " << inWorldSpaceTangent1 << " tangent2: " << inWorldSpaceTangent2
 		<< " normal: " << inWorldSpaceNormal << " tangent1: " << inWorldSpaceTangent1 << " tangent2: " << inWorldSpaceTangent2
 		<< " restitution: " << inSettings.mCombinedRestitution << " friction: " << inSettings.mCombinedFriction << " minv: " << inMinVelocityForRestitution
 		<< " restitution: " << inSettings.mCombinedRestitution << " friction: " << inSettings.mCombinedFriction << " minv: " << inMinVelocityForRestitution
-		<< " surface_vel: " << inSettings.mRelativeSurfaceVelocity << " surface_ang: " << inSettings.mRelativeAngularSurfaceVelocity);
+		<< " surface_vel: " << inSettings.mRelativeLinearSurfaceVelocity << " surface_ang: " << inSettings.mRelativeAngularSurfaceVelocity);
 
 
 	// Calculate collision points relative to body
 	// Calculate collision points relative to body
 	RVec3 p = 0.5_r * (inWorldSpacePosition1 + inWorldSpacePosition2);
 	RVec3 p = 0.5_r * (inWorldSpacePosition1 + inWorldSpacePosition2);
@@ -110,7 +110,7 @@ JPH_INLINE void ContactConstraintManager::WorldContactPoint::TemplatedCalculateF
 	if (inSettings.mCombinedFriction > 0.0f)
 	if (inSettings.mCombinedFriction > 0.0f)
 	{
 	{
 		// Get surface velocity relative to tangents
 		// Get surface velocity relative to tangents
-		Vec3 ws_surface_velocity = inSettings.mRelativeSurfaceVelocity + inSettings.mRelativeAngularSurfaceVelocity.Cross(r1);
+		Vec3 ws_surface_velocity = inSettings.mRelativeLinearSurfaceVelocity + inSettings.mRelativeAngularSurfaceVelocity.Cross(r1);
 		float surface_velocity1 = inWorldSpaceTangent1.Dot(ws_surface_velocity);
 		float surface_velocity1 = inWorldSpaceTangent1.Dot(ws_surface_velocity);
 		float surface_velocity2 = inWorldSpaceTangent2.Dot(ws_surface_velocity);
 		float surface_velocity2 = inWorldSpaceTangent2.Dot(ws_surface_velocity);
 
 

+ 2 - 2
Samples/Tests/General/ConveyorBeltTest.cpp

@@ -82,7 +82,7 @@ void ConveyorBeltTest::OnContactAdded(const Body &inBody1, const Body &inBody2,
 		Vec3 body2_linear_surface_velocity = body2_linear_belt? inBody2.GetRotation() * cLocalSpaceVelocity : Vec3::sZero();
 		Vec3 body2_linear_surface_velocity = body2_linear_belt? inBody2.GetRotation() * cLocalSpaceVelocity : Vec3::sZero();
 
 
 		// Calculate the relative surface velocity
 		// Calculate the relative surface velocity
-		ioSettings.mRelativeSurfaceVelocity = body2_linear_surface_velocity - body1_linear_surface_velocity;
+		ioSettings.mRelativeLinearSurfaceVelocity = body2_linear_surface_velocity - body1_linear_surface_velocity;
 	}
 	}
 
 
 	// Angular belt
 	// Angular belt
@@ -99,7 +99,7 @@ void ConveyorBeltTest::OnContactAdded(const Body &inBody1, const Body &inBody2,
 		Vec3 body2_linear_surface_velocity = body2_angular? body2_angular_surface_velocity.Cross(Vec3(inBody1.GetCenterOfMassPosition() - inBody2.GetCenterOfMassPosition())) : Vec3::sZero();
 		Vec3 body2_linear_surface_velocity = body2_angular? body2_angular_surface_velocity.Cross(Vec3(inBody1.GetCenterOfMassPosition() - inBody2.GetCenterOfMassPosition())) : Vec3::sZero();
 
 
 		// Calculate the relative angular surface velocity
 		// Calculate the relative angular surface velocity
-		ioSettings.mRelativeSurfaceVelocity = body2_linear_surface_velocity;
+		ioSettings.mRelativeLinearSurfaceVelocity = body2_linear_surface_velocity;
 		ioSettings.mRelativeAngularSurfaceVelocity = body2_angular_surface_velocity - body1_angular_surface_velocity;
 		ioSettings.mRelativeAngularSurfaceVelocity = body2_angular_surface_velocity - body1_angular_surface_velocity;
 	}
 	}
 }
 }

+ 4 - 4
UnitTests/Physics/ContactListenerTests.cpp

@@ -86,7 +86,7 @@ TEST_SUITE("ContactListenerTests")
 			CHECK(remove.mType == EType::Remove);
 			CHECK(remove.mType == EType::Remove);
 			CHECK(remove.mBody1 == floor.GetID()); // Lowest ID should be first
 			CHECK(remove.mBody1 == floor.GetID()); // Lowest ID should be first
 			CHECK(remove.mBody2 == body.GetID()); // Highest ID should be second
 			CHECK(remove.mBody2 == body.GetID()); // Highest ID should be second
-		}		
+		}
 	}
 	}
 
 
 	// Let a sphere fall on the floor with restition = 0, then give it horizontal velocity, then take it away from the floor
 	// Let a sphere fall on the floor with restition = 0, then give it horizontal velocity, then take it away from the floor
@@ -263,7 +263,7 @@ TEST_SUITE("ContactListenerTests")
 			CHECK(remove.mType == EType::Remove);
 			CHECK(remove.mType == EType::Remove);
 			CHECK(remove.mBody1 == floor.GetID()); // Lowest ID first
 			CHECK(remove.mBody1 == floor.GetID()); // Lowest ID first
 			CHECK(remove.mBody2 == body.GetID()); // Highest ID second
 			CHECK(remove.mBody2 == body.GetID()); // Highest ID second
-		}		
+		}
 	}
 	}
 
 
 	TEST_CASE("TestWereBodiesInContact")
 	TEST_CASE("TestWereBodiesInContact")
@@ -348,7 +348,7 @@ TEST_SUITE("ContactListenerTests")
 			// At that point it has to select one of the sub shapes for the contact and if that sub shape no longer collides we get a remove for this sub shape and then an add callback for the other sub shape.
 			// At that point it has to select one of the sub shapes for the contact and if that sub shape no longer collides we get a remove for this sub shape and then an add callback for the other sub shape.
 			CHECK(s->WereBodiesInContact(floor.GetID(), body.GetID()));
 			CHECK(s->WereBodiesInContact(floor.GetID(), body.GetID()));
 			CHECK(s->WereBodiesInContact(body.GetID(), floor.GetID()));
 			CHECK(s->WereBodiesInContact(body.GetID(), floor.GetID()));
-			CHECK(listener.GetAddCount() == 0); 
+			CHECK(listener.GetAddCount() == 0);
 			CHECK((listener.mRemoved == 0 || listener.mWasInContact));
 			CHECK((listener.mRemoved == 0 || listener.mWasInContact));
 			listener.Reset();
 			listener.Reset();
 
 
@@ -390,7 +390,7 @@ TEST_SUITE("ContactListenerTests")
 					JPH_ASSERT(inBody1.GetID() == mFloor.GetID() || inBody2.GetID() == mBox.GetID());
 					JPH_ASSERT(inBody1.GetID() == mFloor.GetID() || inBody2.GetID() == mBox.GetID());
 
 
 					// Calculate the relative surface velocity
 					// Calculate the relative surface velocity
-					ioSettings.mRelativeSurfaceVelocity = -(inBody1.GetRotation() * mLocalSpaceLinearVelocity);
+					ioSettings.mRelativeLinearSurfaceVelocity = -(inBody1.GetRotation() * mLocalSpaceLinearVelocity);
 					ioSettings.mRelativeAngularSurfaceVelocity = -(inBody1.GetRotation() * mLocalSpaceAngularVelocity);
 					ioSettings.mRelativeAngularSurfaceVelocity = -(inBody1.GetRotation() * mLocalSpaceAngularVelocity);
 				}
 				}