20 #ifndef ANTKEEPER_MATH_PROJECTION_HPP
21 #define ANTKEEPER_MATH_PROJECTION_HPP
42 return T{2} * std::atan(std::tan(v * T{0.5}) * r);
58 return T{2} * std::atan(std::tan(h * T{0.5}) / r);
74 [[nodiscard]] constexpr
mat4<T> ortho(T left, T right, T bottom, T top, T near, T far) noexcept
78 {T{2} / (right - left), T{0}, T{0}, T{0}},
79 {T{0}, T{2} / (top - bottom), T{0}, T{0}},
80 {T{0}, T{0}, T{-2} / (far - near), T{0}},
81 {-((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((far + near) / (far - near)), T{1}}
100 [[nodiscard]] constexpr std::tuple<mat4<T>,
mat4<T>>
ortho_inv(T left, T right, T bottom, T top, T near, T far) noexcept
106 {T{2} / (right - left), T{0}, T{0}, T{0}},
107 {T{0}, T{2} / (top - bottom), T{0}, T{0}},
108 {T{0}, T{0}, T{-2} / (far - near), T{0}},
109 {-((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((far + near) / (far - near)), T{1}}
114 {(right - left) / T{2}, T{0}, T{0}, T{0}},
115 {T{0}, (top - bottom) / T{2}, T{0}, T{0}},
116 {T{0}, T{0}, (-far + near) / T{2}, T{0}},
117 {(right + left) / T{2}, (bottom + top) / T{2}, (-far - near) / T{2}, T{1}}
139 {T{2} / (right - left), T{0}, T{0}, T{0}},
140 {T{0}, T{2} / (top - bottom), T{0}, T{0}},
141 {T{0}, T{0}, T{-1} / (far - near), T{0}},
142 {-((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -near / (far - near), T{1}}
161 [[nodiscard]] constexpr std::tuple<mat4<T>,
mat4<T>>
ortho_half_z_inv(T left, T right, T bottom, T top, T near, T far) noexcept
167 {T{2} / (right - left), T{0}, T{0}, T{0}},
168 {T{0}, T{2} / (top - bottom), T{0}, T{0}},
169 {T{0}, T{0}, T{-1} / (far - near), T{0}},
170 {-((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -near / (far - near), T{1}}
175 {(right - left) / T{2}, T{0}, T{0}, T{0}},
176 {T{0}, (top - bottom) / T{2}, T{0}, T{0}},
177 {T{0}, T{0}, -far + near, T{0}},
178 {(right + left) / T{2}, (bottom + top) / T{2}, -near, T{1}}
197 const T f = std::cos(half_fov) / std::sin(half_fov);
201 {f / aspect_ratio, T{0}, T{0}, T{0}},
202 {T{0}, f, T{0}, T{0}},
203 {T{0}, T{0}, (far + near) / (near - far), T{-1}},
204 {T{0}, T{0}, (T{2} * far * near) / (near - far), T{0}}
224 const T f = std::cos(half_fov) / std::sin(half_fov);
230 {f / aspect_ratio, T{0}, T{0}, T{0}},
231 {T{0}, f, T{0}, T{0}},
232 {T{0}, T{0}, (far + near) / (near - far), T{-1}},
233 {T{0}, T{0}, (T{2} * far * near) / (near - far), T{0}}
238 {aspect_ratio / f, T{0}, T{0}, T{0}},
239 {T{0}, T{1} / f, T{0}, T{0}},
240 {T{0}, T{0}, T{0}, (near - far) / (T{2} * near * far)},
241 {T{0}, T{0}, T{-1}, (near + far) / (T{2} * near * far)}
260 const T f = std::cos(half_fov) / std::sin(half_fov);
264 {f / aspect_ratio, T{0}, T{0}, T{0}},
265 {T{0}, f, T{0}, T{0}},
266 {T{0}, T{0}, far / (near - far), T{-1}},
267 {T{0}, T{0}, -(far * near) / (far - near), T{0}}
287 const T f = std::cos(half_fov) / std::sin(half_fov);
293 {f / aspect_ratio, T{0}, T{0}, T{0}},
294 {T{0}, f, T{0}, T{0}},
295 {T{0}, T{0}, far / (near - far), T{-1}},
296 {T{0}, T{0}, -(far * near) / (far - near), T{0}}
301 {aspect_ratio / f, T{0}, T{0}, T{0}},
302 {T{0}, T{1} / f, T{0}, T{0}},
303 {T{0}, T{0}, T{0}, T{1} / far - T{1} / near},
304 {T{0}, T{0}, T{-1}, T{1} / near}
322 const T f = std::cos(half_fov) / std::sin(half_fov);
326 {f / aspect_ratio, T{0}, T{0}, T{0}},
327 {T{0}, f, T{0}, T{0}},
328 {T{0}, T{0}, T{0}, T{-1}},
329 {T{0}, T{0}, near, T{0}}
348 const T f = std::cos(half_fov) / std::sin(half_fov);
354 {f / aspect_ratio, T{0}, T{0}, T{0}},
355 {T{0}, f, T{0}, T{0}},
356 {T{0}, T{0}, T{0}, T{-1}},
357 {T{0}, T{0}, near, T{0}}
362 {aspect_ratio / f, T{0}, T{0}, T{0}},
363 {T{0}, T{1} / f, T{0}, T{0}},
364 {T{0}, T{0}, T{0}, T{1} / near},
365 {T{0}, T{0}, T{-1}, T{0}}
Mathematical functions and data types.
constexpr std::tuple< mat4< T >, mat4< T > > ortho_inv(T left, T right, T bottom, T top, T near, T far) noexcept
Constructs an orthographic projection matrix which will transform the near and far clipping planes to...
T vertical_fov(T h, T r)
Calculates a vertical FoV given a horizontal FoV and aspect ratio.
constexpr mat4< T > ortho_half_z(T left, T right, T bottom, T top, T near, T far) noexcept
Constructs an orthographic projection matrix which will transform the near and far clipping planes to...
constexpr std::tuple< mat4< T >, mat4< T > > ortho_half_z_inv(T left, T right, T bottom, T top, T near, T far) noexcept
Constructs an orthographic projection matrix which will transform the near and far clipping planes to...
mat4< T > perspective_half_z(T vertical_fov, T aspect_ratio, T near, T far)
Constructs a perspective projection matrix which will transform the near and far clipping planes to [...
constexpr mat4< T > ortho(T left, T right, T bottom, T top, T near, T far) noexcept
Constructs an orthographic projection matrix which will transform the near and far clipping planes to...
T horizontal_fov(T v, T r)
Calculates a horizontal FoV given a vertical FoV and aspect ratio.
std::tuple< mat4< T >, mat4< T > > perspective_inv(T vertical_fov, T aspect_ratio, T near, T far)
Constructs a perspective projection matrix which will transform the near and far clipping planes to [...
mat4< T > perspective(T vertical_fov, T aspect_ratio, T near, T far)
Constructs a perspective projection matrix which will transform the near and far clipping planes to [...
mat4< T > inf_perspective_half_z_reverse(T vertical_fov, T aspect_ratio, T near)
Constructs a perspective projection matrix, with an infinite far plane, which will transform the near...
std::tuple< mat4< T >, mat4< T > > perspective_half_z_inv(T vertical_fov, T aspect_ratio, T near, T far)
Constructs a perspective projection matrix which will transform the near and far clipping planes to [...
std::tuple< mat4< T >, mat4< T > > inf_perspective_half_z_reverse_inv(T vertical_fov, T aspect_ratio, T near)
Constructs a perspective projection matrix, with an infinite far plane, which will transform the near...
n by m column-major matrix.