Refactors camera projections - makes projection functions of camera more clear.
Reviewed By: elexis Tested By: Stan Differential Revision: https://code.wildfiregames.com/D2012 This was SVN commit r22404.
This commit is contained in:
parent
ec4d84c72f
commit
8babfe2330
@ -46,7 +46,7 @@ CCamera::CCamera()
|
||||
|
||||
CCamera::~CCamera() = default;
|
||||
|
||||
void CCamera::SetProjection(float nearp, float farp, float fov)
|
||||
void CCamera::SetPerspectiveProjection(float nearp, float farp, float fov)
|
||||
{
|
||||
m_NearPlane = nearp;
|
||||
m_FarPlane = farp;
|
||||
@ -56,7 +56,7 @@ void CCamera::SetProjection(float nearp, float farp, float fov)
|
||||
m_ProjMat.SetPerspective(m_FOV, aspect, m_NearPlane, m_FarPlane);
|
||||
}
|
||||
|
||||
void CCamera::SetProjectionTile(int tiles, int tile_x, int tile_y)
|
||||
void CCamera::SetPerspectiveProjectionTile(int tiles, int tile_x, int tile_y)
|
||||
{
|
||||
const float aspect = static_cast<float>(m_ViewPort.m_Width) / static_cast<float>(m_ViewPort.m_Height);
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#ifndef INCLUDED_CAMERA
|
||||
#define INCLUDED_CAMERA
|
||||
|
||||
#include "Frustum.h"
|
||||
#include "graphics/Frustum.h"
|
||||
#include "maths/BoundingBoxAligned.h"
|
||||
#include "maths/Matrix3D.h"
|
||||
|
||||
@ -42,18 +42,16 @@ class CCamera
|
||||
CCamera();
|
||||
~CCamera();
|
||||
|
||||
// Methods for projection
|
||||
void SetProjection(float nearp, float farp, float fov);
|
||||
void SetProjection(const CMatrix3D& matrix) { m_ProjMat = matrix; }
|
||||
void SetProjectionTile(int tiles, int tile_x, int tile_y);
|
||||
CMatrix3D& GetProjection() { return m_ProjMat; }
|
||||
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 SetPerspectiveProjection(float nearp, float farp, float fov);
|
||||
void SetPerspectiveProjectionTile(int tiles, int tile_x, int tile_y);
|
||||
|
||||
CMatrix3D& GetOrientation() { return m_Orientation; }
|
||||
const CMatrix3D& GetOrientation() const { return m_Orientation; }
|
||||
|
||||
CMatrix3D GetViewProjection() const { return m_ProjMat * m_Orientation.GetInverse(); }
|
||||
|
||||
// Updates the frustum planes. Should be called
|
||||
// everytime the view or projection matrices are
|
||||
// altered.
|
||||
@ -110,10 +108,9 @@ class CCamera
|
||||
// is the view matrix
|
||||
CMatrix3D m_Orientation;
|
||||
|
||||
// Should not be tweaked externally if possible
|
||||
private:
|
||||
CMatrix3D m_ProjMat;
|
||||
|
||||
private:
|
||||
float m_NearPlane;
|
||||
float m_FarPlane;
|
||||
float m_FOV;
|
||||
|
@ -362,7 +362,7 @@ CGameView::CGameView(CGame *pGame):
|
||||
vp.m_Height = g_yres;
|
||||
m->ViewCamera.SetViewPort(vp);
|
||||
|
||||
m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
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.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
}
|
||||
|
||||
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.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation);
|
||||
m->ViewCamera.UpdateFrustum();
|
||||
}
|
||||
@ -1020,7 +1020,7 @@ float CGameView::GetFOV() const
|
||||
|
||||
void CGameView::SetCameraProjection()
|
||||
{
|
||||
m->ViewCamera.SetProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV);
|
||||
}
|
||||
|
||||
InReaction game_view_handler(const SDL_Event_* ev)
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
CVector3D(0.0f, 0.0f, 1.0f),
|
||||
CVector3D(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
camera.SetProjection(1.0f, 101.0f, DEGTORAD(90.0f));
|
||||
camera.SetPerspectiveProjection(1.0f, 101.0f, DEGTORAD(90.0f));
|
||||
camera.UpdateFrustum();
|
||||
|
||||
const float sqrt2 = sqrtf(2.0f) / 2.0f;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -372,7 +372,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles)
|
||||
for (int tile_x = 0; tile_x < tiles; ++tile_x)
|
||||
{
|
||||
// Adjust the camera to render the appropriate region
|
||||
g_Game->GetView()->GetCamera()->SetProjectionTile(tiles, tile_x, tile_y);
|
||||
g_Game->GetView()->GetCamera()->SetPerspectiveProjectionTile(tiles, tile_x, tile_y);
|
||||
|
||||
RenderLogger(false);
|
||||
RenderGui(false);
|
||||
@ -406,7 +406,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles)
|
||||
SViewPort vp = { 0, 0, g_xres, g_yres };
|
||||
g_Game->GetView()->GetCamera()->SetViewPort(vp);
|
||||
g_Game->GetView()->SetCameraProjection();
|
||||
g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0);
|
||||
g_Game->GetView()->GetCamera()->SetPerspectiveProjectionTile(1, 0, 0);
|
||||
}
|
||||
|
||||
if (tex_write(&t, filename) == INFO::OK)
|
||||
|
@ -1142,10 +1142,10 @@ void CRenderer::ComputeReflectionCamera(CCamera& camera, const CBoundingBoxAlign
|
||||
vp.m_X = 0;
|
||||
vp.m_Y = 0;
|
||||
camera.SetViewPort(vp);
|
||||
camera.SetProjection(m_ViewCamera.GetNearPlane(), m_ViewCamera.GetFarPlane(), fov);
|
||||
camera.SetPerspectiveProjection(m_ViewCamera.GetNearPlane(), m_ViewCamera.GetFarPlane(), fov);
|
||||
CMatrix3D scaleMat;
|
||||
scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);
|
||||
camera.m_ProjMat = scaleMat * camera.m_ProjMat;
|
||||
camera.SetProjection(scaleMat * camera.GetProjection());
|
||||
|
||||
CVector4D camPlane(0, 1, 0, -wm.m_WaterHeight + 0.5f);
|
||||
SetObliqueFrustumClipping(camera, camPlane);
|
||||
@ -1178,10 +1178,10 @@ void CRenderer::ComputeRefractionCamera(CCamera& camera, const CBoundingBoxAlign
|
||||
vp.m_X = 0;
|
||||
vp.m_Y = 0;
|
||||
camera.SetViewPort(vp);
|
||||
camera.SetProjection(m_ViewCamera.GetNearPlane(), m_ViewCamera.GetFarPlane(), fov);
|
||||
camera.SetPerspectiveProjection(m_ViewCamera.GetNearPlane(), m_ViewCamera.GetFarPlane(), fov);
|
||||
CMatrix3D scaleMat;
|
||||
scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);
|
||||
camera.m_ProjMat = scaleMat * camera.m_ProjMat;
|
||||
camera.SetProjection(scaleMat * camera.GetProjection());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -85,7 +85,7 @@ void AtlasViewActor::Render()
|
||||
SViewPort vp = { 0, 0, g_xres, g_yres };
|
||||
CCamera& camera = GetCamera();
|
||||
camera.SetViewPort(vp);
|
||||
camera.SetProjection(2.f, 512.f, DEGTORAD(20.f));
|
||||
camera.SetPerspectiveProjection(2.f, 512.f, DEGTORAD(20.f));
|
||||
camera.UpdateFrustum();
|
||||
|
||||
m_ActorViewer->Render();
|
||||
@ -221,7 +221,8 @@ void AtlasViewGame::Render()
|
||||
SViewPort vp = { 0, 0, g_xres, g_yres };
|
||||
CCamera& camera = GetCamera();
|
||||
camera.SetViewPort(vp);
|
||||
camera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV());
|
||||
CGameView* gameView = g_Game->GetView();
|
||||
camera.SetPerspectiveProjection(gameView->GetNear(), gameView->GetFar(), gameView->GetFOV());
|
||||
camera.UpdateFrustum();
|
||||
|
||||
::Render();
|
||||
|
Loading…
Reference in New Issue
Block a user