MotorcycleTest.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // This test shows how a motorcycle could be made with the vehicle constraint.
  8. /// Note: The motor cycle controller is still in development and may need a lot of tweaks/hacks to work properly!
  9. class MotorcycleTest : public VehicleTest
  10. {
  11. public:
  12. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, MotorcycleTest)
  13. // Destructor
  14. virtual ~MotorcycleTest() override;
  15. // See: Test
  16. virtual void Initialize() override;
  17. virtual void ProcessInput(const ProcessInputParams &inParams) override;
  18. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  19. virtual void SaveInputState(StateRecorder &inStream) const override;
  20. virtual void RestoreInputState(StateRecorder &inStream) override;
  21. virtual void GetInitialCamera(CameraState &ioState) const override;
  22. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override { return mCameraPivot; }
  23. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  24. private:
  25. void UpdateCameraPivot();
  26. static inline bool sOverrideFrontSuspensionForcePoint = false; ///< If true, the front suspension force point is overridden
  27. static inline bool sOverrideRearSuspensionForcePoint = false; ///< If true, the rear suspension force point is overridden
  28. static inline bool sEnableLeanController = true; ///< If true, the lean controller is enabled
  29. Body * mMotorcycleBody; ///< The vehicle
  30. Ref<VehicleConstraint> mVehicleConstraint; ///< The vehicle constraint
  31. RMat44 mCameraPivot = RMat44::sIdentity(); ///< The camera pivot, recorded before the physics update to align with the drawn world
  32. // Player input
  33. float mForward = 0.0f;
  34. float mPreviousForward = 1.0f; ///< Keeps track of last motorcycle direction so we know when to brake and when to accelerate
  35. float mRight = 0.0f; ///< Keeps track of the current steering angle
  36. float mBrake = 0.0f;
  37. };