10inline auto degrees(
float radian) ->
float {
11 return radian *
static_cast<float>(180 / std::numbers::pi);
15 return degrees *
static_cast<float>(std::numbers::pi / 180);
18auto translate(Mat4f mat, Vec4f offset) -> Mat4f;
19auto translate(Mat4f mat, Vec3f offset) -> Mat4f;
21auto look_at(
const Vec3f& position,
const Vec3f& target,
const Vec3f& world_up)
24auto rotate(
const Mat4f& matrix,
float rotation,
const Vec3f& axis) -> Mat4f;
27inline auto ortho(T left, T right, T bottom, T top) {
30 res.
at(0, 0) =
static_cast<T
>(2) / (right - left);
31 res.
at(1, 1) =
static_cast<T
>(2) / (top - bottom);
32 res.
at(2, 2) = -
static_cast<T
>(1);
33 res.
at(3, 0) = -(right + left) / (right - left);
34 res.
at(3, 1) = -(top + bottom) / (top - bottom);
40inline auto ortho(T left, T right, T bottom, T top, T z_near, T z_far) {
43 res.
at(0, 0) =
static_cast<T
>(2) / (right - left);
44 res.
at(1, 1) =
static_cast<T
>(2) / (top - bottom);
45 res.
at(2, 2) =
static_cast<T
>(1) / (z_far - z_near);
46 res.
at(3, 0) = -(right + left) / (right - left);
47 res.
at(3, 1) = -(top + bottom) / (top - bottom);
48 res.
at(3, 2) = -z_near / (z_far - z_near);
57inline auto perspective(T fov_y, T aspect, T z_near, T z_far) {
58 const float focal_length = 1.0f / std::tan(fov_y / 2.0f);
60 const float x = focal_length / aspect;
61 const float y = -focal_length;
62 const float a = z_near / (z_far - z_near);
63 const float b = z_far * a;
static constexpr auto identity()
Definition matrix.hpp:18
auto at(std::size_t col, std::size_t row) -> T &
Definition matrix.hpp:69
Definition geometry.hpp:8
auto degrees(float radian) -> float
Definition geometry.hpp:10
auto perspective(T fov_y, T aspect, T z_near, T z_far)
Definition geometry.hpp:57
auto radians(float degrees) -> float
Definition geometry.hpp:14
auto ortho(T left, T right, T bottom, T top)
Definition geometry.hpp:27
auto look_at(const Vec3f &position, const Vec3f &target, const Vec3f &world_up) -> Mat4f
Definition geometry.cpp:10
auto translate(Mat4f mat, Vec4f offset) -> Mat4f
Definition geometry.cpp:34
auto rotate(const Mat4f &matrix, float rotation, const Vec3f &axis) -> Mat4f
Definition geometry.cpp:49