Browse Source

Drawing current ground state of character

Jorrit Rouwe 1 year ago
parent
commit
b0c10849d8

+ 14 - 0
Jolt/Physics/Character/CharacterBase.cpp

@@ -19,6 +19,20 @@ CharacterBase::CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSys
 	SetMaxSlopeAngle(inSettings->mMaxSlopeAngle);
 }
 
+const char *CharacterBase::sToString(EGroundState inState)
+{
+	switch (inState)
+	{
+	case EGroundState::OnGround:		return "OnGround";
+	case EGroundState::OnSteepGround:	return "OnSteepGround";
+	case EGroundState::NotSupported:	return "NotSupported";
+	case EGroundState::InAir:			return "InAir";
+	}
+
+	JPH_ASSERT(false);
+	return "Unknown";
+}
+
 void CharacterBase::SaveState(StateRecorder &inStream) const
 {
 	inStream.Write(mGroundState);

+ 3 - 0
Jolt/Physics/Character/CharacterBase.h

@@ -80,6 +80,9 @@ public:
 		InAir,							///< Character is in the air and is not touching anything.
 	};
 
+	/// Debug function to convert enum values to string
+	static const char *					sToString(EGroundState inState);
+
 	///@name Properties of the ground this character is standing on
 
 	/// Current ground state

+ 1 - 1
Samples/Tests/Character/CharacterBaseTest.cpp

@@ -692,5 +692,5 @@ void CharacterBaseTest::DrawCharacterState(const CharacterBase *inCharacter, RMa
 	const PhysicsMaterial *ground_material = inCharacter->GetGroundMaterial();
 	Vec3 horizontal_velocity = inCharacterVelocity;
 	horizontal_velocity.SetY(0);
-	mDebugRenderer->DrawText3D(inCharacterTransform.GetTranslation(), StringFormat("Mat: %s\nHorizontal Vel: %.1f m/s\nVertical Vel: %.1f m/s", ground_material->GetDebugName(), (double)horizontal_velocity.Length(), (double)inCharacterVelocity.GetY()), color, 0.25f);
+	mDebugRenderer->DrawText3D(inCharacterTransform.GetTranslation(), StringFormat("State: %s\nMat: %s\nHorizontal Vel: %.1f m/s\nVertical Vel: %.1f m/s", CharacterBase::sToString(ground_state), ground_material->GetDebugName(), (double)horizontal_velocity.Length(), (double)inCharacterVelocity.GetY()), color, 0.25f);
 }