matrix: perspective construction takes a Z-range
This commit is contained in:
parent
d232f1c871
commit
65bf7af24e
@ -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 },
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user