MotorcycleTest.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Vehicle/VehicleTest.h>
  6. #include <Jolt/Physics/Vehicle/VehicleConstraint.h>
  7. class MotorcycleTest : public VehicleTest
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, MotorcycleTest)
  11. // Description of the test
  12. virtual const char * GetDescription() const override
  13. {
  14. return "This test shows how a motorcycle could be made with the vehicle constraint.\n"
  15. "Use the arrow keys to drive. Z for hand brake.";
  16. }
  17. // Destructor
  18. virtual ~MotorcycleTest() override;
  19. // See: Test
  20. virtual void Initialize() override;
  21. virtual void ProcessInput(const ProcessInputParams &inParams) override;
  22. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  23. virtual void SaveInputState(StateRecorder &inStream) const override;
  24. virtual void RestoreInputState(StateRecorder &inStream) override;
  25. virtual void GetInitialCamera(CameraState &ioState) const override;
  26. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override { return mCameraPivot; }
  27. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  28. private:
  29. void UpdateCameraPivot();
  30. static inline bool sOverrideFrontSuspensionForcePoint = false; ///< If true, the front suspension force point is overridden
  31. static inline bool sOverrideRearSuspensionForcePoint = false; ///< If true, the rear suspension force point is overridden
  32. static inline bool sEnableLeanController = true; ///< If true, the lean controller is enabled
  33. static inline bool sOverrideGravity = false; ///< If true, gravity is overridden to always oppose the ground normal
  34. Body * mMotorcycleBody; ///< The vehicle
  35. Ref<VehicleConstraint> mVehicleConstraint; ///< The vehicle constraint
  36. RMat44 mCameraPivot = RMat44::sIdentity(); ///< The camera pivot, recorded before the physics update to align with the drawn world
  37. // Player input
  38. float mForward = 0.0f;
  39. float mPreviousForward = 1.0f; ///< Keeps track of last motorcycle direction so we know when to brake and when to accelerate
  40. float mRight = 0.0f; ///< Keeps track of the current steering angle
  41. float mBrake = 0.0f;
  42. };