LCOV - code coverage report
Current view: top level - source/graphics - CameraController.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 5 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 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             : #include "lib/code_annotation.h"
      24             : #include "ps/Input.h"
      25             : #include "simulation2/system/Entity.h"
      26             : 
      27             : #include <memory>
      28             : 
      29             : class CCamera;
      30             : class CConfigDBHook;
      31             : class CMatrix3D;
      32             : class CVector3D;
      33             : union SDL_Event;
      34             : 
      35             : class CCameraController : public ICameraController
      36             : {
      37             :     NONCOPYABLE(CCameraController);
      38             : public:
      39             :     CCameraController(CCamera& camera);
      40             :     ~CCameraController() override;
      41             : 
      42             :     void LoadConfig() override;
      43             : 
      44             :     Input::Reaction HandleEvent(const SDL_Event& ev) override;
      45             : 
      46             :     CVector3D GetCameraPivot() const override;
      47             :     CVector3D GetCameraPosition() const override;
      48             :     CVector3D GetCameraRotation() const override;
      49             :     float GetCameraZoom() const override;
      50             : 
      51             :     void SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom) override;
      52             :     void MoveCameraTarget(const CVector3D& target) override;
      53             :     void ResetCameraTarget(const CVector3D& target) override;
      54             :     void FollowEntity(entity_id_t entity, bool firstPerson) override;
      55             :     entity_id_t GetFollowedEntity() override;
      56             : 
      57             :     void Update(const float deltaRealTime) override;
      58             :     void SetViewport(const SViewPort& vp) override;
      59             : 
      60           0 :     bool GetConstrainCamera() const override
      61             :     {
      62           0 :         return m_ConstrainCamera;
      63             :     }
      64             : 
      65           0 :     void SetConstrainCamera(bool constrain) override
      66             :     {
      67           0 :         m_ConstrainCamera = constrain;
      68           0 :     }
      69             : 
      70             : private:
      71             :     CVector3D GetSmoothPivot(CCamera &camera) const;
      72             :     void ResetCameraAngleZoom();
      73             :     void ToggleBirdsEyeView();
      74             :     void SetupCameraMatrixSmooth(CMatrix3D* orientation);
      75             :     void SetupCameraMatrixSmoothRot(CMatrix3D* orientation);
      76             :     void SetupCameraMatrixNonSmooth(CMatrix3D* orientation);
      77             :     void FocusHeight(bool smooth);
      78             : 
      79             :     /**
      80             :      * Set projection of current camera using near, far, and FOV values
      81             :      */
      82             :     void SetCameraProjection();
      83             : 
      84             :     /**
      85             :     * Whether the camera movement should be constrained by min/max limits
      86             :     * and terrain avoidance.
      87             :     */
      88             :     bool m_ConstrainCamera;
      89             : 
      90             :     /**
      91             :     * Entity for the camera to follow, or INVALID_ENTITY if none.
      92             :     */
      93             :     entity_id_t m_FollowEntity;
      94             : 
      95             :     /**
      96             :     * Whether to follow FollowEntity in first-person mode.
      97             :     */
      98             :     bool m_FollowFirstPerson;
      99             : 
     100             :     /**
     101             :     * Whether the camera is in bird's eye view mode.
     102             :     */
     103             :     bool m_BirdsEyeView;
     104             : 
     105             :     // Settings
     106             :     float m_ViewScrollSpeed;
     107             :     float m_ViewScrollSpeedModifier;
     108             :     // How close the mouse pointer should be to a view edge to move the camera.
     109             :     int m_ViewScrollMouseDetectDistance;
     110             :     float m_ViewRotateXSpeed;
     111             :     float m_ViewRotateXMin;
     112             :     float m_ViewRotateXMax;
     113             :     float m_ViewRotateXDefault;
     114             :     float m_ViewRotateYSpeed;
     115             :     float m_ViewRotateYSpeedWheel;
     116             :     float m_ViewRotateYDefault;
     117             :     float m_ViewRotateSpeedModifier;
     118             :     float m_ViewDragSpeed;
     119             :     bool m_ViewDragInverted;
     120             :     float m_ViewZoomSpeed;
     121             :     float m_ViewZoomSpeedWheel;
     122             :     float m_ViewZoomMin;
     123             :     float m_ViewZoomMax;
     124             :     float m_ViewZoomDefault;
     125             :     float m_ViewZoomSpeedModifier;
     126             :     float m_ViewFOV;
     127             :     float m_ViewNear;
     128             :     float m_ViewFar;
     129             :     float m_HeightSmoothness;
     130             :     float m_HeightMin;
     131             : 
     132             :     // Camera Controls State
     133             :     CSmoothedValue m_PosX;
     134             :     CSmoothedValue m_PosY;
     135             :     CSmoothedValue m_PosZ;
     136             :     CSmoothedValue m_Zoom;
     137             :     CSmoothedValue m_RotateX; // inclination around x axis (relative to camera)
     138             :     CSmoothedValue m_RotateY; // rotation around y (vertical) axis
     139             : 
     140             :     std::unique_ptr<CConfigDBHook> m_ViewDragInvertedConfigHook;
     141             :     std::unique_ptr<CConfigDBHook> m_ViewDragSpeedConfigHook;
     142             : };
     143             : 
     144             : #endif // INCLUDED_CAMERACONTROLLER

Generated by: LCOV version 1.16