TankTest.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/Vehicle/VehicleConstraint.h>
  7. #include <Jolt/Physics/Constraints/HingeConstraint.h>
  8. // This test shows how a tank could be made with the vehicle constraint.
  9. class TankTest : public VehicleTest
  10. {
  11. public:
  12. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, TankTest)
  13. // Destructor
  14. virtual ~TankTest() 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 SaveState(StateRecorder &inStream) const override;
  20. virtual void RestoreState(StateRecorder &inStream) 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;
  25. private:
  26. Body * mTankBody; ///< The body of the tank
  27. Body * mTurretBody; ///< The body of the turret of the tank
  28. Body * mBarrelBody; ///< The body of the barrel of the tank
  29. Ref<VehicleConstraint> mVehicleConstraint; ///< The vehicle constraint
  30. Ref<HingeConstraint> mTurretHinge; ///< Hinge connecting tank body and turret
  31. Ref<HingeConstraint> mBarrelHinge; ///< Hinge connecting tank turret and barrel
  32. float mReloadTime = 0.0f; ///< How long it still takes to reload the main gun
  33. RVec3 mCameraPivot = RVec3::sZero(); ///< The camera pivot, recorded before the physics update to align with the drawn world
  34. // Player input
  35. float mForward = 0.0f;
  36. float mPreviousForward = 1.0f; ///< Keeps track of last car direction so we know when to brake and when to accelerate
  37. float mLeftRatio = 0.0f;
  38. float mRightRatio = 0.0f;
  39. float mBrake = 0.0f;
  40. float mTurretHeading = 0.0f;
  41. float mBarrelPitch = 0.0f;
  42. bool mFire = false;
  43. };