CharacterVirtualTest.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Tests/Character/CharacterBaseTest.h>
  5. #include <Jolt/Physics/Character/CharacterVirtual.h>
  6. // Simple test that test the CharacterVirtual class. Allows the user to move around with the arrow keys and jump with the J button.
  7. class CharacterVirtualTest : public CharacterBaseTest, public CharacterContactListener
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(CharacterVirtualTest)
  11. // Initialize the test
  12. virtual void Initialize() override;
  13. // Update the test, called before the physics update
  14. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  15. // Optional settings menu
  16. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  17. // Saving / restoring state for replay
  18. virtual void SaveState(StateRecorder &inStream) const override;
  19. virtual void RestoreState(StateRecorder &inStream) override;
  20. // Called whenever the character collides with a body. Returns true if the contact can push the character.
  21. virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, Vec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings) override;
  22. protected:
  23. // Get position of the character
  24. virtual Vec3 GetCharacterPosition() const override { return mCharacter->GetPosition(); }
  25. // Handle user input to the character
  26. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) override;
  27. private:
  28. // Test settings
  29. static inline float sMaxSlopeAngle = DegreesToRadians(45.0f);
  30. static inline float sMaxStrength = 100.0f;
  31. static inline float sCharacterPadding = 0.02f;
  32. static inline float sPenetrationRecoverySpeed = 1.0f;
  33. static inline float sPredictiveContactDistance = 0.1f;
  34. static inline bool sEnableWalkStairs = true;
  35. // The 'player' character
  36. Ref<CharacterVirtual> mCharacter;
  37. // Smoothed value of the player input
  38. Vec3 mSmoothMovementDirection = Vec3::sZero();
  39. };