CharacterBaseTest.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/Test.h>
  6. #include <Jolt/Physics/Character/CharacterBase.h>
  7. // Base class for the character tests, initializes the test scene.
  8. class CharacterBaseTest : public Test
  9. {
  10. public:
  11. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, CharacterBaseTest)
  12. // Number used to scale the terrain and camera movement to the scene
  13. virtual float GetWorldScale() const override { return 0.2f; }
  14. // Initialize the test
  15. virtual void Initialize() override;
  16. // Update the test, called before the physics update
  17. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  18. // Override to specify the initial camera state (local to GetCameraPivot)
  19. virtual void GetInitialCamera(CameraState &ioState) const override;
  20. // Override to specify a camera pivot point and orientation (world space)
  21. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override;
  22. // Optional settings menu
  23. virtual bool HasSettingsMenu() const override { return true; }
  24. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  25. // Saving / restoring state for replay
  26. virtual void SaveState(StateRecorder &inStream) const override;
  27. virtual void RestoreState(StateRecorder &inStream) override;
  28. protected:
  29. // Get position of the character
  30. virtual RVec3 GetCharacterPosition() const = 0;
  31. // Handle user input to the character
  32. virtual void HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime) = 0;
  33. // Draw the character state
  34. void DrawCharacterState(const CharacterBase *inCharacter, RMat44Arg inCharacterTransform, Vec3Arg inCharacterVelocity);
  35. // Add character movement settings
  36. virtual void AddCharacterMovementSettings(DebugUI* inUI, UIElement* inSubMenu) { /* Nothing by default */ }
  37. // Add test configuration settings
  38. virtual void AddConfigurationSettings(DebugUI *inUI, UIElement *inSubMenu) { /* Nothing by default */ }
  39. // Character size
  40. static constexpr float cCharacterHeightStanding = 1.35f;
  41. static constexpr float cCharacterRadiusStanding = 0.3f;
  42. static constexpr float cCharacterHeightCrouching = 0.8f;
  43. static constexpr float cCharacterRadiusCrouching = 0.3f;
  44. // Character movement properties
  45. inline static bool sControlMovementDuringJump = true; ///< If false the character cannot change movement direction in mid air
  46. inline static float sCharacterSpeed = 6.0f;
  47. inline static float sJumpSpeed = 4.0f;
  48. // The different stances for the character
  49. RefConst<Shape> mStandingShape;
  50. RefConst<Shape> mCrouchingShape;
  51. // List of boxes on ramp
  52. Array<BodyID> mRampBlocks;
  53. float mRampBlocksTimeLeft = 0.0f;
  54. // Conveyor belt body
  55. BodyID mConveyorBeltBody;
  56. // Sensor body
  57. BodyID mSensorBody;
  58. private:
  59. // Shape types
  60. enum class EType
  61. {
  62. Capsule,
  63. Cylinder,
  64. Box
  65. };
  66. // Character shape type
  67. static inline EType sShapeType = EType::Capsule;
  68. // List of possible scene names
  69. static const char * sScenes[];
  70. // Filename of animation to load for this test
  71. static const char * sSceneName;
  72. // Scene time (for moving bodies)
  73. float mTime = 0.0f;
  74. // Moving bodies
  75. BodyID mRotatingBody;
  76. BodyID mRotatingWallBody;
  77. BodyID mRotatingAndTranslatingBody;
  78. BodyID mSmoothVerticallyMovingBody;
  79. BodyID mReversingVerticallyMovingBody;
  80. float mReversingVerticallyMovingVelocity = 1.0f;
  81. BodyID mHorizontallyMovingBody;
  82. };