CharacterTest.h 1.8 KB

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