VehicleTrack.h 1.9 KB

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