CharacterBaseTest.h 3.2 KB

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