matrix: perspective construction takes a Z-range

This commit is contained in:
Danny Robson 2015-12-02 10:03:25 +11:00
parent d232f1c871
commit 65bf7af24e
2 changed files with 5 additions and 4 deletions

View File

@ -307,14 +307,14 @@ matrix<S,T>::ortho2D (T left, T right,
//-----------------------------------------------------------------------------
template <size_t S, typename T>
matrix4<T>
matrix<S,T>::perspective (T fov, T aspect, T near, T far)
matrix<S,T>::perspective (T fov, T aspect, range<T> Z)
{
T f = std::tan (fov / 2);
T tx = 1 / (f * aspect);
T ty = 1 / f;
T z1 = (far + near) / (near - far);
T z2 = (2 * far * near) / (near - far);
T z1 = (Z.max + Z.min) / (Z.min - Z.max);
T z2 = (2 * Z.max * Z.min) / (Z.min - Z.max);
return { {
{ tx, 0, 0, 0 },

View File

@ -18,6 +18,7 @@
#define __UTIL_MATRIX_HPP
#include "point.hpp"
#include "range.hpp"
#include <iostream>
@ -65,7 +66,7 @@ namespace util {
// Perspective matrices
static matrix<4,T> ortho (T left, T right, T bottom, T top, T near, T far);
static matrix<4,T> ortho2D (T left, T right, T bottom, T top);
static matrix<4,T> perspective (T fov, T aspect, T near, T far);
static matrix<4,T> perspective (T fov, T aspect, range<T> Z);
static matrix<4,T> look_at (point<3,T> eye, point<3,T> centre, vector<3,T> up);
// Affine matrices