forked from 0ad/0ad
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.
This commit is contained in:
parent
16b452cf91
commit
659bf68cc7
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user