FollowCamera.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "CameraComponent.h"
  10. class FollowCamera : public CameraComponent
  11. {
  12. public:
  13. FollowCamera(class Actor* owner);
  14. void Update(float deltaTime) override;
  15. void SnapToIdeal();
  16. void SetHorzDist(float dist) { mHorzDist = dist; }
  17. void SetVertDist(float dist) { mVertDist = dist; }
  18. void SetTargetDist(float dist) { mTargetDist = dist; }
  19. void SetSpringConstant(float spring) { mSpringConstant = spring; }
  20. private:
  21. Vector3 ComputeCameraPos() const;
  22. // Actual position of camera
  23. Vector3 mActualPos;
  24. // Velocity of actual camera
  25. Vector3 mVelocity;
  26. // Horizontal follow distance
  27. float mHorzDist;
  28. // Vertical follow distance
  29. float mVertDist;
  30. // Target distance
  31. float mTargetDist;
  32. // Spring constant (higher is more stiff)
  33. float mSpringConstant;
  34. };