Browse Source

Replaced quat.Conjugate() * vec with quat.InverseRotate(vec)

SixDOF: Reusing local variables instead of calling GetRotation() again
Jorrit Rouwe 1 month ago
parent
commit
7038776e2a

+ 1 - 1
Jolt/Physics/Body/Body.cpp

@@ -242,7 +242,7 @@ bool Body::ApplyBuoyancyImpulse(float inTotalVolume, float inSubmergedVolume, Ve
 		float relative_center_of_buoyancy_velocity_len_sq = relative_center_of_buoyancy_velocity.LengthSq();
 		if (relative_center_of_buoyancy_velocity_len_sq > 1.0e-12f)
 		{
-			Vec3 local_relative_center_of_buoyancy_velocity = GetRotation().Conjugated() * relative_center_of_buoyancy_velocity;
+			Vec3 local_relative_center_of_buoyancy_velocity = GetRotation().InverseRotate(relative_center_of_buoyancy_velocity);
 			area = local_relative_center_of_buoyancy_velocity.Abs().Dot(size.Swizzle<SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X>() * size.Swizzle<SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y>()) / sqrt(relative_center_of_buoyancy_velocity_len_sq);
 		}
 

+ 1 - 1
Jolt/Physics/Body/MotionProperties.inl

@@ -113,7 +113,7 @@ void MotionProperties::ApplyGyroscopicForceInternal(QuatArg inBodyRotation, floa
 
 	// Calculate local space angular momentum
 	Quat inertia_space_to_world_space = inBodyRotation * mInertiaRotation;
-	Vec3 local_angular_velocity = inertia_space_to_world_space.Conjugated() * mAngularVelocity;
+	Vec3 local_angular_velocity = inertia_space_to_world_space.InverseRotate(mAngularVelocity);
 	Vec3 local_momentum = local_inertia * local_angular_velocity;
 
 	// The gyroscopic force applies a torque: T = -w x I w where w is angular velocity and I the inertia tensor

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

@@ -444,12 +444,12 @@ void SixDOFConstraint::SetupVelocityConstraint(float inDeltaTime)
 	if (IsRotationFullyConstrained())
 	{
 		// All rotation locked: Setup rotation constraint
-		mRotationConstraintPart.CalculateConstraintProperties(*mBody1, Mat44::sRotation(mBody1->GetRotation()), *mBody2, Mat44::sRotation(mBody2->GetRotation()));
+		mRotationConstraintPart.CalculateConstraintProperties(*mBody1, Mat44::sRotation(rotation1), *mBody2, Mat44::sRotation(rotation2));
 	}
 	else if (IsRotationConstrained() || mRotationMotorActive)
 	{
 		// GetRotationInConstraintSpace without redoing the calculation of constraint_body1_to_world
-		Quat constraint_body2_to_world = mBody2->GetRotation() * mConstraintToBody2;
+		Quat constraint_body2_to_world = rotation2 * mConstraintToBody2;
 		Quat q = constraint_body1_to_world.Conjugated() * constraint_body2_to_world;
 
 		// Use swing twist constraint part