2
0

FollowCamera.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. TypeID GetType() const override { return TFollowCamera; }
  21. void LoadProperties(const rapidjson::Value& inObj) override;
  22. void SaveProperties(rapidjson::Document::AllocatorType& alloc,
  23. rapidjson::Value& inObj) const override;
  24. private:
  25. Vector3 ComputeCameraPos() const;
  26. // Actual position of camera
  27. Vector3 mActualPos;
  28. // Velocity of actual camera
  29. Vector3 mVelocity;
  30. // Horizontal follow distance
  31. float mHorzDist;
  32. // Vertical follow distance
  33. float mVertDist;
  34. // Target distance
  35. float mTargetDist;
  36. // Spring constant (higher is more stiff)
  37. float mSpringConstant;
  38. };