CharacterVirtualTest.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Called whenever the character collides with a body. Returns true if the contact can push the character.
  18. virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, Vec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings) override;
  19. protected:
  20. // Get position of the character
  21. virtual Vec3 GetCharacterPosition() const override { return mCharacter->GetPosition(); }
  22. // Handle user input to the character
  23. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) override;
  24. private:
  25. // Test settings
  26. static inline float sMaxSlopeAngle = DegreesToRadians(45.0f);
  27. static inline float sMaxStrength = 100.0f;
  28. static inline float sCharacterPadding = 0.02f;
  29. static inline float sPenetrationRecoverySpeed = 1.0f;
  30. static inline float sPredictiveContactDistance = 0.1f;
  31. // The 'player' character
  32. Ref<CharacterVirtual> mCharacter;
  33. // Smoothed value of the player input
  34. Vec3 mSmoothMovementDirection = Vec3::sZero();
  35. };