Line data Source code
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 :
21 : #include "graphics/ICameraController.h"
22 : #include "graphics/SmoothedValue.h"
23 :
24 0 : class CCameraController : public ICameraController
25 : {
26 : NONCOPYABLE(CCameraController);
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 0 : bool GetConstrainCamera() const override
50 : {
51 0 : return m_ConstrainCamera;
52 : }
53 :
54 0 : void SetConstrainCamera(bool constrain) override
55 : {
56 0 : m_ConstrainCamera = constrain;
57 0 : }
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 : */
76 : bool m_ConstrainCamera;
77 :
78 : /**
79 : * Entity for the camera to follow, or INVALID_ENTITY if none.
80 : */
81 : entity_id_t m_FollowEntity;
82 :
83 : /**
84 : * Whether to follow FollowEntity in first-person mode.
85 : */
86 : bool m_FollowFirstPerson;
87 :
88 : // Settings
89 : float m_ViewScrollSpeed;
90 : float m_ViewScrollSpeedModifier;
91 : // How close the mouse pointer should be to a view edge to move the camera.
92 : int m_ViewScrollMouseDetectDistance;
93 : float m_ViewRotateXSpeed;
94 : float m_ViewRotateXMin;
95 : float m_ViewRotateXMax;
96 : float m_ViewRotateXDefault;
97 : float m_ViewRotateYSpeed;
98 : float m_ViewRotateYSpeedWheel;
99 : float m_ViewRotateYDefault;
100 : float m_ViewRotateSpeedModifier;
101 : float m_ViewDragSpeed;
102 : float m_ViewZoomSpeed;
103 : float m_ViewZoomSpeedWheel;
104 : float m_ViewZoomMin;
105 : float m_ViewZoomMax;
106 : float m_ViewZoomDefault;
107 : float m_ViewZoomSpeedModifier;
108 : float m_ViewFOV;
109 : float m_ViewNear;
110 : float m_ViewFar;
111 : float m_HeightSmoothness;
112 : float m_HeightMin;
113 :
114 : // Camera Controls State
115 : CSmoothedValue m_PosX;
116 : CSmoothedValue m_PosY;
117 : CSmoothedValue m_PosZ;
118 : CSmoothedValue m_Zoom;
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
|