Explorar o código

Clarified that angular surface velocity is relative to body 1's COM

Also updated example to correct for bodies being swapped.
Jorrit Rouwe %!s(int64=2) %!d(string=hai) anos
pai
achega
e6a18ba502

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

@@ -48,7 +48,7 @@ public:
 	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)
 	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)
+	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 world space center of mass - body 1 world space center of mass) x mRelativeAngularSurfaceVelocity to mRelativeSurfaceVelocity.
 };
 
 /// Return value for the OnContactValidate callback. Determines if the contact is being processed or not.

+ 4 - 0
Samples/Tests/General/ConveyorBeltTest.cpp

@@ -94,8 +94,12 @@ void ConveyorBeltTest::OnContactAdded(const Body &inBody1, const Body &inBody2,
 		const Vec3 cLocalSpaceAngularVelocity(0, DegreesToRadians(10.0f), 0);
 		Vec3 body1_angular_surface_velocity = body1_angular? inBody1.GetRotation() * cLocalSpaceAngularVelocity : Vec3::sZero();
 		Vec3 body2_angular_surface_velocity = body2_angular? inBody2.GetRotation() * cLocalSpaceAngularVelocity : Vec3::sZero();
+
+		// Note that the angular velocity is the angular velocity around body 1's center of mass, so we need to add the linear velocity of body 2's center of mass
+		Vec3 body2_linear_surface_velocity = body2_angular? (inBody2.GetCenterOfMassPosition() - inBody1.GetCenterOfMassPosition()).Cross(body2_angular_surface_velocity) : Vec3::sZero();
 		
 		// Calculate the relative angular surface velocity
+		ioSettings.mRelativeSurfaceVelocity = body2_linear_surface_velocity;
 		ioSettings.mRelativeAngularSurfaceVelocity = body2_angular_surface_velocity - body1_angular_surface_velocity;
 	}
 }