VehicleSixDOFTest.h 1.7 KB

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