Pyrogenesis  trunk
CameraController.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef INCLUDED_CAMERACONTROLLER
19 #define INCLUDED_CAMERACONTROLLER
20 
22 #include "graphics/SmoothedValue.h"
23 
25 {
27 public:
28  CCameraController(CCamera& camera);
29  ~CCameraController() override;
30 
31  void LoadConfig() override;
32 
33  InReaction HandleEvent(const SDL_Event_* ev) override;
34 
35  CVector3D GetCameraPivot() const override;
36  CVector3D GetCameraPosition() const override;
37  CVector3D GetCameraRotation() const override;
38  float GetCameraZoom() const override;
39 
40  void SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom) override;
41  void MoveCameraTarget(const CVector3D& target) override;
42  void ResetCameraTarget(const CVector3D& target) override;
43  void FollowEntity(entity_id_t entity, bool firstPerson) override;
44  entity_id_t GetFollowedEntity() override;
45 
46  void Update(const float deltaRealTime) override;
47  void SetViewport(const SViewPort& vp) override;
48 
49  bool GetConstrainCamera() const override
50  {
51  return m_ConstrainCamera;
52  }
53 
54  void SetConstrainCamera(bool constrain) override
55  {
56  m_ConstrainCamera = constrain;
57  }
58 
59 private:
60  CVector3D GetSmoothPivot(CCamera &camera) const;
61  void ResetCameraAngleZoom();
62  void SetupCameraMatrixSmooth(CMatrix3D* orientation);
63  void SetupCameraMatrixSmoothRot(CMatrix3D* orientation);
64  void SetupCameraMatrixNonSmooth(CMatrix3D* orientation);
65  void FocusHeight(bool smooth);
66 
67  /**
68  * Set projection of current camera using near, far, and FOV values
69  */
70  void SetCameraProjection();
71 
72  /**
73  * Whether the camera movement should be constrained by min/max limits
74  * and terrain avoidance.
75  */
77 
78  /**
79  * Entity for the camera to follow, or INVALID_ENTITY if none.
80  */
82 
83  /**
84  * Whether to follow FollowEntity in first-person mode.
85  */
87 
88  // Settings
91  // How close the mouse pointer should be to a view edge to move the camera.
108  float m_ViewFOV;
109  float m_ViewNear;
110  float m_ViewFar;
112  float m_HeightMin;
113 
114  // Camera Controls State
119  CSmoothedValue m_RotateX; // inclination around x axis (relative to camera)
120  CSmoothedValue m_RotateY; // rotation around y (vertical) axis
121 };
122 
123 #endif // INCLUDED_CAMERACONTROLLER
bool m_ConstrainCamera
Whether the camera movement should be constrained by min/max limits and terrain avoidance.
Definition: CameraController.h:76
int m_ViewScrollMouseDetectDistance
Definition: CameraController.h:92
bool m_FollowFirstPerson
Whether to follow FollowEntity in first-person mode.
Definition: CameraController.h:86
bool GetConstrainCamera() const override
Definition: CameraController.h:49
InReaction HandleEvent(const SDL_Event_ *ev) override
Definition: CameraController.cpp:614
float m_ViewScrollSpeedModifier
Definition: CameraController.h:90
void LoadConfig() override
Definition: CameraController.cpp:104
Definition: Camera.h:33
camera controller interface.
Definition: ICameraController.h:33
CVector3D GetCameraRotation() const override
Definition: CameraController.cpp:421
entity_id_t m_FollowEntity
Entity for the camera to follow, or INVALID_ENTITY if none.
Definition: CameraController.h:81
float m_ViewDragSpeed
Definition: CameraController.h:101
CVector3D GetCameraPosition() const override
Definition: CameraController.cpp:416
Definition: CameraController.h:24
void FocusHeight(bool smooth)
Definition: CameraController.cpp:554
CSmoothedValue m_RotateY
Definition: CameraController.h:120
Definition: Vector3D.h:30
~CCameraController() override
CVector3D GetCameraPivot() const override
Definition: CameraController.cpp:411
Definition: libsdl.h:52
float m_HeightSmoothness
Definition: CameraController.h:111
float m_ViewRotateYSpeed
Definition: CameraController.h:97
float m_ViewZoomSpeed
Definition: CameraController.h:102
Definition: Matrix3D.h:33
void ResetCameraTarget(const CVector3D &target) override
Definition: CameraController.cpp:472
NONCOPYABLE(CCameraController)
void SetupCameraMatrixSmoothRot(CMatrix3D *orientation)
Definition: CameraController.cpp:538
CCameraController(CCamera &camera)
Definition: CameraController.cpp:52
float m_ViewRotateXMax
Definition: CameraController.h:95
CSmoothedValue m_PosY
Definition: CameraController.h:116
InReaction
Definition: input.h:34
void SetCamera(const CVector3D &pos, float rotX, float rotY, float zoom) override
Definition: CameraController.cpp:432
float m_ViewFOV
Definition: CameraController.h:108
CVector3D GetSmoothPivot(CCamera &camera) const
Definition: CameraController.cpp:406
Definition: Camera.h:41
float m_ViewScrollSpeed
Definition: CameraController.h:89
void SetConstrainCamera(bool constrain) override
Definition: CameraController.h:54
CSmoothedValue m_PosX
Definition: CameraController.h:115
float m_ViewRotateXMin
Definition: CameraController.h:94
float m_ViewZoomSpeedWheel
Definition: CameraController.h:103
CSmoothedValue m_RotateX
Definition: CameraController.h:119
void FollowEntity(entity_id_t entity, bool firstPerson) override
Definition: CameraController.cpp:496
float m_ViewRotateSpeedModifier
Definition: CameraController.h:100
void ResetCameraAngleZoom()
Definition: CameraController.cpp:512
void SetViewport(const SViewPort &vp) override
Definition: CameraController.cpp:153
float m_ViewRotateXSpeed
Definition: CameraController.h:93
float m_ViewFar
Definition: CameraController.h:110
float m_ViewNear
Definition: CameraController.h:109
float GetCameraZoom() const override
Definition: CameraController.cpp:427
float m_ViewZoomMax
Definition: CameraController.h:105
float m_ViewZoomSpeedModifier
Definition: CameraController.h:107
void SetupCameraMatrixNonSmooth(CMatrix3D *orientation)
Definition: CameraController.cpp:546
void SetCameraProjection()
Set projection of current camera using near, far, and FOV values.
Definition: CameraController.cpp:507
float m_ViewRotateXDefault
Definition: CameraController.h:96
float m_HeightMin
Definition: CameraController.h:112
entity_id_t GetFollowedEntity() override
Definition: CameraController.cpp:502
float m_ViewZoomMin
Definition: CameraController.h:104
float m_ViewRotateYSpeedWheel
Definition: CameraController.h:98
void Update(const float deltaRealTime) override
Definition: CameraController.cpp:159
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
CSmoothedValue m_Zoom
Definition: CameraController.h:118
float m_ViewZoomDefault
Definition: CameraController.h:106
float m_ViewRotateYDefault
Definition: CameraController.h:99
A value with exponential decay towards the target value.
Definition: SmoothedValue.h:26
CSmoothedValue m_PosZ
Definition: CameraController.h:117
void SetupCameraMatrixSmooth(CMatrix3D *orientation)
Definition: CameraController.cpp:530
void MoveCameraTarget(const CVector3D &target) override
Definition: CameraController.cpp:450