4 #include "../Matrix/MatrixImpl.hpp" 5 #include "../Vector.hpp" 11 template <
class T,
int Dim,
bool Packed>
13 static_assert(!std::is_integral_v<T>);
17 : fovX(fovX), ratios(ratios), nearPlane(nearPlane), farPlane(farPlane), projNearPlane(projNearPlane), projFarPlane(projFarPlane) {}
20 template <
class U, eMatrixOrder Order, eMatrixLayout Layout,
bool MPacked>
28 template <
class U,
int Rows,
int Columns, eMatrixOrder Order, eMatrixLayout Layout,
bool MPacked>
30 assert((nearPlane < 0 && farPlane < nearPlane) || (0 < nearPlane && nearPlane < farPlane));
38 auto absFovX = std::abs(fovX);
43 T C = nearPlane < T(0) ? T(-1) : T(1);
44 T A = C * (f * F - n * N) / (F - N);
45 T B = C * F * N * (n - f) / (F - N);
46 Vector<T, Dim - 1, Packed> adjRatios = ratios(0) / ratios;
47 T w = tan(T(0.5) * absFovX);
49 for (
int i = 0; i < adjRatios.Dimension(); ++i) {
50 m(i, i) = adjRatios(i);
61 const Vector<T, Dim - 1, Packed> ratios;
64 const T projNearPlane = 0;
65 const T projFarPlane = 1;
77 template <
class T,
int DimMinus1,
bool Packed>
79 using NonIntegral = std::conditional_t<std::is_integral_v<T>, float, T>;
92 auto Perspective(T fov, T nearPlane, T farPlane, T projNearPlane = T(0), T projFarPlane = T(1)) {
106 auto Perspective(T fov, T aspectRatio, T nearPlane, T farPlane, T projNearPlane = T(0), T projFarPlane = T(1)) {
PerspectiveBuilder & operator=(const PerspectiveBuilder &)=delete
PerspectiveBuilder(T fovX, const Vector< T, Dim - 1, Packed > &ratios, T nearPlane, T farPlane, T projNearPlane=0, T projFarPlane=1)
Definition: PerspectiveBuilder.hpp:16
auto Perspective(T fovX, const Vector< T, DimMinus1, Packed > &ratios, T nearPlane, T farPlane, T projNearPlane=T(0), T projFarPlane=T(1))
Creates a perspective projection matrix.
Definition: PerspectiveBuilder.hpp:78
Definition: Approx.hpp:11
constexpr int ColumnCount() const
Returns the number of columns of the matrix.
Definition: MatrixImpl.hpp:27
Definition: Definitions.hpp:63
constexpr int RowCount() const
Returns the number of rows of the matrix.
Definition: MatrixImpl.hpp:31
Definition: PerspectiveBuilder.hpp:12
auto Zero()
Creates a matrix with all elements zero.
Definition: ZeroBuilder.hpp:34