Index: source/graphics/Camera.h =================================================================== --- source/graphics/Camera.h +++ source/graphics/Camera.h @@ -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 @@ 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 @@ // 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; Index: source/graphics/Camera.cpp =================================================================== --- source/graphics/Camera.cpp +++ source/graphics/Camera.cpp @@ -46,7 +46,7 @@ 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 @@ 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(m_ViewPort.m_Width) / static_cast(m_ViewPort.m_Height); Index: source/graphics/GameView.cpp =================================================================== --- source/graphics/GameView.cpp +++ source/graphics/GameView.cpp @@ -362,7 +362,7 @@ 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 @@ 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() @@ -887,7 +887,7 @@ 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(); } @@ -1023,7 +1023,7 @@ 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) Index: source/graphics/tests/test_Camera.h =================================================================== --- source/graphics/tests/test_Camera.h +++ source/graphics/tests/test_Camera.h @@ -42,7 +42,7 @@ 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; Index: source/ps/Util.cpp =================================================================== --- source/ps/Util.cpp +++ source/ps/Util.cpp @@ -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 @@ 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 @@ 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) Index: source/renderer/Renderer.cpp =================================================================== --- source/renderer/Renderer.cpp +++ source/renderer/Renderer.cpp @@ -1145,10 +1145,10 @@ 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); @@ -1181,10 +1181,10 @@ 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()); } /////////////////////////////////////////////////////////////////////////////////////////////////// Index: source/tools/atlas/GameInterface/View.cpp =================================================================== --- source/tools/atlas/GameInterface/View.cpp +++ source/tools/atlas/GameInterface/View.cpp @@ -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 @@ 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 @@ 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();