Преглед изворни кода

- Drawing anchor points for fixed constraint
- Fixed bug in FixedConstraintTest where the wrong anchor point was calculated

Jorrit Rouwe пре 3 година
родитељ
комит
929b2e28bb

+ 7 - 3
Jolt/Physics/Constraints/FixedConstraint.cpp

@@ -140,11 +140,15 @@ bool FixedConstraint::SolvePositionConstraint(float inDeltaTime, float inBaumgar
 #ifdef JPH_DEBUG_RENDERER
 void FixedConstraint::DrawConstraint(DebugRenderer *inRenderer) const
 {
-	Vec3 com1 = mBody1->GetCenterOfMassPosition();
-	Vec3 com2 = mBody2->GetCenterOfMassPosition();
+	Mat44 com1 = mBody1->GetCenterOfMassTransform();
+	Mat44 com2 = mBody2->GetCenterOfMassTransform();
+
+	Vec3 anchor1 = com1 * mLocalSpacePosition1;
+	Vec3 anchor2 = com2 * mLocalSpacePosition2;
 
 	// Draw constraint
-	inRenderer->DrawLine(com1, com2, Color::sGreen);
+	inRenderer->DrawLine(com1.GetTranslation(), anchor1, Color::sGreen);
+	inRenderer->DrawLine(com2.GetTranslation(), anchor2, Color::sBlue);
 }
 #endif // JPH_DEBUG_RENDERER
 

+ 4 - 4
Samples/Tests/Constraints/FixedConstraintTest.cpp

@@ -126,8 +126,8 @@ void FixedConstraintTest::Initialize()
 				for (int j = 0; j < 2; ++j)
 				{
 					FixedConstraintSettings constraint;
-					constraint.SetPoint(*cross, *pillars[i]);
-					mPhysicsSystem->AddConstraint(constraint.Create(*cross, *pillars[(i + j) % 4]));
+					constraint.SetPoint(*pillars[(i + j) % 4], *cross);
+					mPhysicsSystem->AddConstraint(constraint.Create(*pillars[(i + j) % 4], *cross));
 				}
 
 				// Attach to previous pillar
@@ -153,8 +153,8 @@ void FixedConstraintTest::Initialize()
 		for (int i = 0; i < 4; ++i)
 		{
 			FixedConstraintSettings constraint;
-			constraint.SetPoint(*top, *prev_pillars[i]);
-			mPhysicsSystem->AddConstraint(constraint.Create(*top, *prev_pillars[i]));
+			constraint.SetPoint(*prev_pillars[i], *top);
+			mPhysicsSystem->AddConstraint(constraint.Create(*prev_pillars[i], *top));
 		}
 	}
 }