CharacterBaseTest.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 RMat44 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 RVec3 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, RMat44Arg inCharacterTransform, Vec3Arg inCharacterVelocity);
  34. // Add test configuration settings
  35. virtual void AddConfigurationSettings(DebugUI *inUI, UIElement *inSubMenu) { /* Nothing by default */ }
  36. // Character size
  37. static constexpr float cCharacterHeightStanding = 1.35f;
  38. static constexpr float cCharacterRadiusStanding = 0.3f;
  39. static constexpr float cCharacterHeightCrouching = 0.8f;
  40. static constexpr float cCharacterRadiusCrouching = 0.3f;
  41. // Character movement properties
  42. inline static bool sControlMovementDuringJump = true; ///< If false the character cannot change movement direction in mid air
  43. inline static float sCharacterSpeed = 6.0f;
  44. inline static float sJumpSpeed = 4.0f;
  45. // The different stances for the character
  46. RefConst<Shape> mStandingShape;
  47. RefConst<Shape> mCrouchingShape;
  48. // List of boxes on ramp
  49. Array<BodyID> mRampBlocks;
  50. float mRampBlocksTimeLeft = 0.0f;
  51. // Conveyor belt body
  52. BodyID mConveyorBeltBody;
  53. private:
  54. // Shape types
  55. enum class EType
  56. {
  57. Capsule,
  58. Cylinder,
  59. Box
  60. };
  61. // Character shape type
  62. static inline EType sShapeType = EType::Capsule;
  63. // List of possible scene names
  64. static const char * sScenes[];
  65. // Filename of animation to load for this test
  66. static const char * sSceneName;
  67. // Scene time (for moving bodies)
  68. float mTime = 0.0f;
  69. // Moving bodies
  70. BodyID mRotatingBody;
  71. BodyID mVerticallyMovingBody;
  72. BodyID mHorizontallyMovingBody;
  73. };