CharacterTest.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Character/CharacterBaseTest.h>
  6. #include <Jolt/Physics/Character/Character.h>
  7. // Simple test that test the Character class. Allows the user to move around with the arrow keys and jump with the J button.
  8. class CharacterTest : public CharacterBaseTest, public ContactListener
  9. {
  10. public:
  11. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, CharacterTest)
  12. // Destructor
  13. virtual ~CharacterTest() override;
  14. // Initialize the test
  15. virtual void Initialize() override;
  16. // Update the test, called before the physics update
  17. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  18. // Update the test, called after the physics update
  19. virtual void PostPhysicsUpdate(float inDeltaTime) override;
  20. // Saving / restoring state for replay
  21. virtual void SaveState(StateRecorder &inStream) const override;
  22. virtual void RestoreState(StateRecorder &inStream) override;
  23. // If this test implements a contact listener, it should be returned here
  24. virtual ContactListener *GetContactListener() override { return this; }
  25. // See: ContactListener
  26. virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  27. virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  28. protected:
  29. // Get position of the character
  30. virtual RVec3 GetCharacterPosition() const override { return mCharacter->GetPosition(); }
  31. // Handle user input to the character
  32. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) override;
  33. private:
  34. // The 'player' character
  35. Ref<Character> mCharacter;
  36. };