CharacterBaseTest.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Tests/Test.h>
  5. #include <Jolt/Physics/Character/CharacterBase.h>
  6. // Base class for the character tests, initializes the test scene.
  7. class CharacterBaseTest : public Test
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(CharacterBaseTest)
  11. // Number used to scale the terrain and camera movement to the scene
  12. virtual float GetWorldScale() const override { return 0.2f; }
  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. // Override to specify the initial camera state (local to GetCameraPivot)
  18. virtual void GetInitialCamera(CameraState &ioState) const override;
  19. // Override to specify a camera pivot point and orientation (world space)
  20. virtual Mat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override;
  21. // Optional settings menu
  22. virtual bool HasSettingsMenu() const override { return true; }
  23. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  24. // Saving / restoring state for replay
  25. virtual void SaveState(StateRecorder &inStream) const override;
  26. virtual void RestoreState(StateRecorder &inStream) override;
  27. protected:
  28. // Get position of the character
  29. virtual Vec3 GetCharacterPosition() const = 0;
  30. // Handle user input to the character
  31. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) = 0;
  32. // Draw the character state
  33. void DrawCharacterState(const CharacterBase *inCharacter, Mat44Arg inCharacterTransform, Vec3Arg inCharacterVelocity);
  34. // Character size
  35. inline static constexpr float cCharacterHeightStanding = 1.35f;
  36. inline static constexpr float cCharacterRadiusStanding = 0.3f;
  37. inline static constexpr float cCharacterHeightCrouching = 0.8f;
  38. inline static constexpr float cCharacterRadiusCrouching = 0.3f;
  39. inline static constexpr float cCharacterSpeed = 6.0f;
  40. inline static constexpr float cJumpSpeed = 4.0f;
  41. // The different stances for the character
  42. RefConst<Shape> mStandingShape;
  43. RefConst<Shape> mCrouchingShape;
  44. // List of boxes on ramp
  45. vector<BodyID> mRampBlocks;
  46. float mRampBlocksTimeLeft = 0.0f;
  47. private:
  48. // List of possible scene names
  49. static const char * sScenes[];
  50. // Filename of animation to load for this test
  51. static const char * sSceneName;
  52. // Scene time (for moving bodies)
  53. float mTime = 0.0f;
  54. // Moving bodies
  55. BodyID mRotatingBody;
  56. BodyID mVerticallyMovingBody;
  57. BodyID mHorizontallyMovingBody;
  58. };