VehicleTrack.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/ObjectStream/SerializableObject.h>
  5. #include <Jolt/Core/LinearCurve.h>
  6. #include <Jolt/Core/StreamIn.h>
  7. #include <Jolt/Core/StreamOut.h>
  8. #include <Jolt/Physics/StateRecorder.h>
  9. JPH_NAMESPACE_BEGIN
  10. /// On which side of the vehicle the track is located (for steering)
  11. enum class ETrackSide : uint
  12. {
  13. Left = 0,
  14. Right = 1,
  15. Num = 2
  16. };
  17. /// Generic properties for tank tracks
  18. class VehicleTrackSettings
  19. {
  20. public:
  21. JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(VehicleTrackSettings)
  22. /// Saves the contents in binary form to inStream.
  23. void SaveBinaryState(StreamOut &inStream) const;
  24. /// Restores the contents in binary form to inStream.
  25. void RestoreBinaryState(StreamIn &inStream);
  26. uint mDrivenWheel; ///< Which wheel on the track is connected to the engine
  27. Array<uint> mWheels; ///< Indices of wheels that are inside this track, should include the driven wheel too
  28. float mInertia = 10.0f; ///< Moment of inertia (kg m^2) of the track and its wheels as seen on the driven wheel
  29. float mAngularDamping = 0.5f; ///< Damping factor of track and its wheels: dw/dt = -c * w as seen on the driven wheel
  30. float mMaxBrakeTorque = 15000.0f; ///< How much torque (Nm) the brakes can apply on the driven wheel
  31. float mDifferentialRatio = 6.0f; ///< Ratio between rotation speed of gear box and driven wheel of track
  32. };
  33. /// Runtime data for tank tracks
  34. class VehicleTrack : public VehicleTrackSettings
  35. {
  36. public:
  37. /// Saving state for replay
  38. void SaveState(StateRecorder &inStream) const;
  39. void RestoreState(StateRecorder &inStream);
  40. float mAngularVelocity = 0.0f; ///< Angular velocity of the driven wheel, will determine the speed of the entire track
  41. };
  42. using VehicleTracks = VehicleTrack[(int)ETrackSide::Num];
  43. JPH_NAMESPACE_END