TankTest.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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(TankTest)
  13. // Destructor
  14. virtual ~TankTest() override;
  15. // See: Test
  16. virtual void Initialize() override;
  17. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  18. virtual void SaveState(StateRecorder& inStream) const override;
  19. virtual void RestoreState(StateRecorder& inStream) override;
  20. virtual void GetInitialCamera(CameraState &ioState) const override;
  21. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override;
  22. private:
  23. Body * mTankBody; ///< The body of the tank
  24. Body * mTurretBody; ///< The body of the turret of the tank
  25. Body * mBarrelBody; ///< The body of the barrel of the tank
  26. Ref<VehicleConstraint> mVehicleConstraint; ///< The vehicle constraint
  27. Ref<HingeConstraint> mTurretHinge; ///< Hinge connecting tank body and turret
  28. Ref<HingeConstraint> mBarrelHinge; ///< Hinge connecting tank turret and barrel
  29. float mPreviousForward = 1.0f; ///< Keeps track of last car direction so we know when to brake and when to accelerate
  30. float mReloadTime = 0.0f; ///< How long it still takes to reload the main gun
  31. };