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