TankTest.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. class TankTest : public VehicleTest
  9. {
  10. public:
  11. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, TankTest)
  12. // Description of the test
  13. virtual const char * GetDescription() const override
  14. {
  15. return "Shows how a tank could be made with a vehicle constraint.\n"
  16. "Use the arrow keys to drive. Shift to brake. Enter to fire.";
  17. }
  18. // Destructor
  19. virtual ~TankTest() override;
  20. // See: Test
  21. virtual void Initialize() override;
  22. virtual void ProcessInput(const ProcessInputParams &inParams) override;
  23. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  24. virtual void SaveState(StateRecorder &inStream) const override;
  25. virtual void RestoreState(StateRecorder &inStream) override;
  26. virtual void SaveInputState(StateRecorder &inStream) const override;
  27. virtual void RestoreInputState(StateRecorder &inStream) override;
  28. virtual void GetInitialCamera(CameraState &ioState) const override;
  29. virtual RMat44 GetCameraPivot(float inCameraHeading, float inCameraPitch) const override;
  30. private:
  31. Body * mTankBody; ///< The body of the tank
  32. Body * mTurretBody; ///< The body of the turret of the tank
  33. Body * mBarrelBody; ///< The body of the barrel of the tank
  34. Ref<VehicleConstraint> mVehicleConstraint; ///< The vehicle constraint
  35. Ref<HingeConstraint> mTurretHinge; ///< Hinge connecting tank body and turret
  36. Ref<HingeConstraint> mBarrelHinge; ///< Hinge connecting tank turret and barrel
  37. float mReloadTime = 0.0f; ///< How long it still takes to reload the main gun
  38. RVec3 mCameraPivot = RVec3::sZero(); ///< The camera pivot, recorded before the physics update to align with the drawn world
  39. // Player input
  40. float mForward = 0.0f;
  41. float mPreviousForward = 1.0f; ///< Keeps track of last car direction so we know when to brake and when to accelerate
  42. float mLeftRatio = 0.0f;
  43. float mRightRatio = 0.0f;
  44. float mBrake = 0.0f;
  45. float mTurretHeading = 0.0f;
  46. float mBarrelPitch = 0.0f;
  47. bool mFire = false;
  48. };