Adds a perspective matrix, refracts a matrix projection setup to prepare for an isometric view.

Reviewed By: wraitii
Differential Revision: https://code.wildfiregames.com/D971
This was SVN commit r20377.
This commit is contained in:
Vladislav Belov 2017-10-29 23:41:59 +00:00
parent cd1b40f295
commit 38d09ce35c
3 changed files with 36 additions and 27 deletions

View File

@ -54,27 +54,19 @@ void CCamera::SetProjection(float nearp, float farp, float fov)
m_FarPlane = farp;
m_FOV = fov;
float aspect = (float)m_ViewPort.m_Width/(float)m_ViewPort.m_Height;
float f = 1.0f/tanf(m_FOV/2);
m_ProjMat.SetZero ();
m_ProjMat._11 = f/aspect;
m_ProjMat._22 = f;
m_ProjMat._33 = -(m_FarPlane+m_NearPlane)/(m_NearPlane-m_FarPlane);
m_ProjMat._34 = 2*m_FarPlane*m_NearPlane/(m_NearPlane-m_FarPlane);
m_ProjMat._43 = 1.0f;
const float aspect = static_cast<float>(m_ViewPort.m_Width) / static_cast<float>(m_ViewPort.m_Height);
m_ProjMat.SetPerspective(m_FOV, aspect, m_NearPlane, m_FarPlane);
}
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);
float aspect = (float)m_ViewPort.m_Width/(float)m_ViewPort.m_Height;
float f = 1.0f/tanf(m_FOV/2);
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._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);
}
//Updates the frustum planes. Should be called

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,7 +36,7 @@ void CMatrix3D::SetIdentity ()
}
//Sets the zero matrix
void CMatrix3D::SetZero ()
void CMatrix3D::SetZero()
{
_11=0.0f; _12=0.0f; _13=0.0f; _14=0.0f;
_21=0.0f; _22=0.0f; _23=0.0f; _24=0.0f;
@ -44,15 +44,30 @@ void CMatrix3D::SetZero ()
_41=0.0f; _42=0.0f; _43=0.0f; _44=0.0f;
}
void CMatrix3D::SetOrtho (float l, float r, float b, float t, float n, float f)
void CMatrix3D::SetOrtho(float left, float right, float bottom, float top, float near, float far)
{
// Based on OpenGL spec
*this = CMatrix3D(
2/(r-l), 0, 0, -(r+l)/(r-l),
0, 2/(t-b), 0, -(t+b)/(t-b),
0, 0, -2/(f-n), -(f+n)/(f-n),
0, 0, 0, 1
);
SetZero();
_11 = 2 / (right - left);
_22 = 2 / (top - bottom);
_33 = -2 / (far - near);
_44 = 1;
_14 = -(right + left) / (right - left);
_24 = -(top + bottom) / (top - bottom);
_34 = -(far + near) / (far - near);
}
void CMatrix3D::SetPerspective(float fov, float aspect, float near, float far)
{
const float f = 1.f / tanf(fov / 2.f);
SetZero();
_11 = f / aspect;
_22 = f;
_33 = -(far + near) / (near - far);
_34 = 2 * far * near / (near - far);
_43 = 1;
}
//The following clear the matrix and set the

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -182,7 +182,9 @@ public:
// set this matrix to the zero matrix
void SetZero();
// set this matrix to the orthogonal projection matrix (as with glOrtho)
void SetOrtho(float l, float r, float b, float t, float n, float f);
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);
// concatenate arbitrary matrix onto this matrix
void Concatenate(const CMatrix3D& m)