1
0
forked from 0ad/0ad

Cleanup Camera code for projections.

Reviewd By: wraitii
Tested By: Stan
Differential Revision: https://code.wildfiregames.com/D1514
This was SVN commit r22033.
This commit is contained in:
Vladislav Belov 2019-01-05 22:40:56 +00:00
parent 24812b06d7
commit 276050bcad
4 changed files with 25 additions and 20 deletions

View File

@ -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
@ -44,9 +44,7 @@ CCamera::CCamera()
m_ViewPort.m_Height = 600;
}
CCamera::~CCamera()
{
}
CCamera::~CCamera() = default;
void CCamera::SetProjection(float nearp, float farp, float fov)
{
@ -61,17 +59,13 @@ void CCamera::SetProjection(float nearp, float farp, float fov)
void CCamera::SetProjectionTile(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);
const float f = 1.f / tanf(m_FOV / 2.f);
m_ProjMat._11 = tiles * f / aspect;
m_ProjMat._22 = tiles * f;
m_ProjMat._13 = -(1 - tiles + 2 * tile_x);
m_ProjMat._23 = -(1 - tiles + 2 * tile_y);
m_ProjMat.SetPerspectiveTile(m_FOV, aspect, m_NearPlane, m_FarPlane, tiles, tile_x, tile_y);
}
//Updates the frustum planes. Should be called
//everytime the view or projection matrices are
//altered.
// Updates the frustum planes. Should be called
// everytime the view or projection matrices are
// altered.
void CCamera::UpdateFrustum(const CBoundingBoxAligned& scissor)
{
CMatrix3D MatFinal;

View File

@ -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
@ -64,13 +64,12 @@ class CCamera
void SetViewPort(const SViewPort& viewport);
const SViewPort& GetViewPort() const { return m_ViewPort; }
// getters
float GetNearPlane() const { return m_NearPlane; }
float GetFarPlane() const { return m_FarPlane; }
float GetFOV() const { return m_FOV; }
// return four points in camera space at given distance from camera
void GetCameraPlanePoints(float dist,CVector3D pts[4]) const;
// Returns four points in camera space at given distance from camera
void GetCameraPlanePoints(float dist, CVector3D pts[4]) const;
// Build a ray passing through the screen coordinate (px, py) and the camera
/////////////////////////////////////////////////////////////////////////////////////////
@ -123,4 +122,4 @@ class CCamera
CFrustum m_ViewFrustum;
};
#endif
#endif // INCLUDED_CAMERA

View File

@ -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
@ -70,6 +70,17 @@ void CMatrix3D::SetPerspective(float fov, float aspect, float near, float far)
_43 = 1;
}
void CMatrix3D::SetPerspectiveTile(float fov, float aspect, float near, float far, int tiles, int tile_x, int tile_y)
{
const float f = 1.f / tanf(fov / 2.f);
SetPerspective(fov, aspect, near, far);
_11 = tiles * f / aspect;
_22 = tiles * f;
_13 = -(1 - tiles + 2 * tile_x);
_23 = -(1 - tiles + 2 * tile_y);
}
//The following clear the matrix and set the
//rotation of each of the 3 axes

View File

@ -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
@ -185,6 +185,7 @@ public:
void SetOrtho(float left, float right, float bottom, float top, float near, float far);
// set this matrix to the perspective projection matrix
void SetPerspective(float fov, float aspect, float near, float far);
void SetPerspectiveTile(float fov, float aspect, float near, float far, int tiles, int tile_x, int tile_y);
// concatenate arbitrary matrix onto this matrix
void Concatenate(const CMatrix3D& m)
@ -321,4 +322,4 @@ public:
CVector3D RotateTransposed(const CVector3D& vector) const;
};
#endif
#endif // INCLUDED_MATRIX3D