CharacterTest.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. class CharacterTest : public CharacterBaseTest, public ContactListener
  7. {
  8. public:
  9. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, CharacterTest)
  10. // Description of the test
  11. virtual const char * GetDescription() const override
  12. {
  13. return "Shows the Character class. Move around with the arrow keys, Shift for crouch and Ctrl for jump.\n"
  14. "Note that most games should use CharacterVirtual instead of the Character class.";
  15. }
  16. // Destructor
  17. virtual ~CharacterTest() override;
  18. // Initialize the test
  19. virtual void Initialize() override;
  20. // Update the test, called before the physics update
  21. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  22. // Update the test, called after the physics update
  23. virtual void PostPhysicsUpdate(float inDeltaTime) override;
  24. // Saving / restoring state for replay
  25. virtual void SaveState(StateRecorder &inStream) const override;
  26. virtual void RestoreState(StateRecorder &inStream) override;
  27. // If this test implements a contact listener, it should be returned here
  28. virtual ContactListener *GetContactListener() override { return this; }
  29. // See: ContactListener
  30. virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  31. virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  32. protected:
  33. // Get position of the character
  34. virtual RVec3 GetCharacterPosition() const override { return mCharacter->GetPosition(); }
  35. // Handle user input to the character
  36. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) override;
  37. private:
  38. // The 'player' character
  39. Ref<Character> mCharacter;
  40. };