From 659bf68cc79bb7b56653f46829bcf7c8a2b7167e Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Thu, 22 Aug 2019 20:49:58 +0000 Subject: [PATCH] Cleanup Camera and CGameView, removes a not needed method and refactors classes. Commented By: Stan Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D2195 This was SVN commit r22755. --- source/graphics/Camera.cpp | 13 +++++++++++-- source/graphics/Camera.h | 1 + source/graphics/GameView.cpp | 23 +++++++++-------------- source/graphics/GameView.h | 3 +-- source/tools/atlas/GameInterface/View.cpp | 3 +-- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/source/graphics/Camera.cpp b/source/graphics/Camera.cpp index a17ab50191..5b6462a1e4 100644 --- a/source/graphics/Camera.cpp +++ b/source/graphics/Camera.cpp @@ -35,9 +35,10 @@ #include "renderer/WaterManager.h" CCamera::CCamera() + : m_NearPlane(0.0f), m_FarPlane(0.0f), m_FOV(0.0f) { - // set viewport to something anything should handle, but should be initialised - // to window size before use + // Set viewport to something anything should handle, but should be initialised + // to window size before use. m_ViewPort.m_X = 0; m_ViewPort.m_Y = 0; m_ViewPort.m_Width = 800; @@ -46,6 +47,14 @@ CCamera::CCamera() CCamera::~CCamera() = default; +void CCamera::SetProjectionFromCamera(const CCamera& camera) +{ + m_NearPlane = camera.m_NearPlane; + m_FarPlane = camera.m_FarPlane; + m_FOV = camera.m_FOV; + m_ProjMat = camera.m_ProjMat; +} + void CCamera::SetPerspectiveProjection(float nearp, float farp, float fov) { m_NearPlane = nearp; diff --git a/source/graphics/Camera.h b/source/graphics/Camera.h index 70faa75add..fbe31b040f 100644 --- a/source/graphics/Camera.h +++ b/source/graphics/Camera.h @@ -51,6 +51,7 @@ class CCamera const CMatrix3D& GetProjection() const { return m_ProjMat; } CMatrix3D GetViewProjection() const { return m_ProjMat * m_Orientation.GetInverse(); } void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; } + void SetProjectionFromCamera(const CCamera& camera); void SetPerspectiveProjection(float nearp, float farp, float fov); void SetPerspectiveProjectionTile(int tiles, int tile_x, int tile_y); diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index c11cf0cbd9..bed78b555f 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -362,7 +362,7 @@ CGameView::CGameView(CGame *pGame): vp.m_Height = g_yres; m->ViewCamera.SetViewPort(vp); - m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); + SetCameraProjection(); SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); m->ViewCamera.UpdateFrustum(); @@ -380,7 +380,7 @@ CGameView::~CGameView() void CGameView::SetViewport(const SViewPort& vp) { m->ViewCamera.SetViewPort(vp); - m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); + SetCameraProjection(); } CObjectManager& CGameView::GetObjectManager() @@ -884,7 +884,7 @@ void CGameView::Update(const float deltaRealTime) m->RotateY.Wrap(-(float)M_PI, (float)M_PI); // Update the camera matrix - m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); + SetCameraProjection(); SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); m->ViewCamera.UpdateFrustum(); } @@ -910,13 +910,13 @@ float CGameView::GetCameraZoom() const return m->Zoom.GetValue(); } -void CGameView::SetCamera(CVector3D Pos, float RotX, float RotY, float zoom) +void CGameView::SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom) { - m->PosX.SetValue(Pos.X); - m->PosY.SetValue(Pos.Y); - m->PosZ.SetValue(Pos.Z); - m->RotateX.SetValue(RotX); - m->RotateY.SetValue(RotY); + m->PosX.SetValue(pos.X); + m->PosY.SetValue(pos.Y); + m->PosZ.SetValue(pos.Z); + m->RotateX.SetValue(rotX); + m->RotateY.SetValue(rotY); m->Zoom.SetValue(zoom); FocusHeight(m, false); @@ -1013,11 +1013,6 @@ float CGameView::GetFar() const return m->ViewFar; } -float CGameView::GetFOV() const -{ - return m->ViewFOV; -} - void CGameView::SetCameraProjection() { m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 870380b0d0..2351ad9e89 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -63,9 +63,8 @@ public: float GetCameraZoom() const; float GetNear() const; float GetFar() const; - float GetFOV() const; - void SetCamera(CVector3D Pos, float RotX, float RotY, float Zoom); + void SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom); void MoveCameraTarget(const CVector3D& target); void ResetCameraTarget(const CVector3D& target); void CameraFollow(entity_id_t entity, bool firstPerson); diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 9a1318ed68..928da509f8 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -226,8 +226,7 @@ void AtlasViewGame::Render() SViewPort vp = { 0, 0, g_xres, g_yres }; CCamera& camera = GetCamera(); camera.SetViewPort(vp); - CGameView* gameView = g_Game->GetView(); - camera.SetPerspectiveProjection(gameView->GetNear(), gameView->GetFar(), gameView->GetFOV()); + camera.SetProjectionFromCamera(*g_Game->GetView()->GetCamera()); camera.UpdateFrustum(); ::Render();