VehicleSixDOFTest.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/Vehicle/VehicleTest.h>
  6. #include <Jolt/Physics/Constraints/SixDOFConstraint.h>
  7. class VehicleSixDOFTest : public VehicleTest
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, VehicleSixDOFTest)
  11. // Description of the test
  12. virtual const char * GetDescription() const override
  13. {
  14. return "Shows how a car could be made with a SixDOFConstraint.\n"
  15. "Use the arrow keys to drive.";
  16. }
  17. // See: Test
  18. virtual void Initialize() override;
  19. virtual void ProcessInput(const ProcessInputParams &inParams) override;
  20. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  21. virtual void SaveInputState(StateRecorder &inStream) const override;
  22. virtual void RestoreInputState(StateRecorder &inStream) override;
  23. virtual void GetInitialCamera(CameraState &ioState) const override;
  24. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override { return mCameraPivot; }
  25. private:
  26. static constexpr float cMaxSteeringAngle = DegreesToRadians(30);
  27. using EAxis = SixDOFConstraintSettings::EAxis;
  28. void UpdateCameraPivot();
  29. enum class EWheel : int
  30. {
  31. LeftFront,
  32. RightFront,
  33. LeftRear,
  34. RightRear,
  35. Num,
  36. };
  37. static inline bool sIsFrontWheel(EWheel inWheel) { return inWheel == EWheel::LeftFront || inWheel == EWheel::RightFront; }
  38. static inline bool sIsLeftWheel(EWheel inWheel) { return inWheel == EWheel::LeftFront || inWheel == EWheel::LeftRear; }
  39. Body * mCarBody;
  40. Ref<SixDOFConstraint> mWheels[int(EWheel::Num)];
  41. RMat44 mCameraPivot = RMat44::sIdentity(); ///< The camera pivot, recorded before the physics update to align with the drawn world
  42. // Player input
  43. float mSteeringAngle = 0.0f;
  44. float mSpeed = 0.0f;
  45. };