4#include "math/bounding_box.hpp"
39 return Transform(
Mat4(
53 return Transform(
Mat4(
66 static constexpr Transform
scale(
const Vec3& s)
noexcept {
67 return Transform(
Mat4(
83 return Transform(
Mat4(
99 return Transform(
Mat4(
115 return Transform(
Mat4(
131 const Vec3 a = axis.normalized();
134 const Float omc = 1.0f - c;
141 return Transform(
Mat4(
142 c + ax * ax * omc, ax * ay * omc - az * s, ax * az * omc + ay * s, 0,
143 ay * ax * omc + az * s, c + ay * ay * omc, ay * az * omc - ax * s, 0,
144 az * ax * omc - ay * s, az * ay * omc + ax * s, c + az * az * omc, 0,
159 static constexpr Transform
look_at(
const Pt3& eye,
const Pt3& target,
const Vec3& up)
noexcept {
160 const Vec3 f = (target - eye).normalized();
164 return Transform(
Mat4(
165 s.
x(), s.
y(), s.
z(), -s.
dot(eye.to_vector()),
166 u.
x(), u.
y(), u.
z(), -u.
dot(eye.to_vector()),
167 -f.
x(), -f.
y(), -f.
z(), f.
dot(eye.to_vector()),
186 const Float tan_half_fovy =
tan(fov_y_rad / 2.0);
187 return Transform(
Mat4(
188 1.0 / (aspect_ratio * tan_half_fovy), 0, 0, 0,
189 0, 1.0 / (tan_half_fovy), 0, 0,
190 0, 0, z_far / (z_far - z_near), -z_far * z_near / (z_far - z_near),
211 return Transform(
Mat4(
212 2.0 / (right - left), 0, 0, -(right + left) / (right - left),
213 0, 2.0 / (top - bottom), 0, -(top + bottom) / (top - bottom),
214 0, 0, 1.0 / (z_far - z_near), -z_near / (z_far - z_near),
223 constexpr Transform() noexcept = default;
224 constexpr Transform(const
Mat4& mat) : m_mat(mat) {}
226 constexpr const Mat4& mat()
const {
return m_mat; }
228 constexpr Transform& operator*=(
const Transform& rhs)
noexcept {
229 m_mat = m_mat * rhs.m_mat;
233 constexpr Transform operator*(
const Transform& rhs)
const noexcept {
234 return Transform(m_mat * rhs.m_mat);
243 return (m_mat *
Homo3(point)).to_point();
252 return (m_mat *
Homo3(vec)).to_vector();
261 auto result = (m_mat.inversed().transposed() *
Homo3(normal)).to_vector();
265 constexpr Ray3 operator*(
const Ray3& ray)
const noexcept {
267 *
this * ray.origin(),
268 *
this * ray.direction()
272 constexpr Bound3 operator*(
const Bound3& bound)
const noexcept {
273 return Bound3 {*
this * bound.min(), *
this * bound.max()};;
constexpr T & x() noexcept
Accesses the first component (x-axis).
Definition vector.hpp:88
constexpr T & z() noexcept
Accesses the third component (z-axis).
Definition vector.hpp:92
constexpr T dot(const Vector &rhs) const noexcept
Calculates the dot product of this vector and another.
Definition vector.hpp:330
constexpr Vector cross(const Vector &rhs) const noexcept
Calculates the cross product of this vector and another.
Definition vector.hpp:342
constexpr Vector normalized() const
Returns a new vector that is a normalized version of this one.
Definition vector.hpp:294
constexpr T & y() noexcept
Accesses the second component (y-axis).
Definition vector.hpp:90
Defines a class for N-dimensional homogeneous coordinates.
Defines a generic, RxC-dimensional, constexpr-friendly matrix class and its views.
The namespace for math library implementation.
Definition bounding_box.hpp:9
float Float
The primary floating-point type used throughout the math library.
Definition global.hpp:29
Vector< Float, 3 > Vec3
A 3-dimensional vector of type Float.
Definition vector.hpp:565
Homogeneous< Float, 3 > Homo3
A 3-dimensional homogeneous coordinate using the library's default Float type.
Definition homogeneous.hpp:226
constexpr T cos(T x)
Calculates the cosine of an angle with constexpr support.
Definition function.hpp:252
Point< Float, 3 > Pt3
A 3-dimensional point of type Float.
Definition point.hpp:274
Normal< Float, 3 > Normal3
A 3-dimensional vector of type Float.
Definition vector.hpp:579
Ray< Float, 3 > Ray3
A 3-dimensional ray of type Float, commonly used in 3D graphics.
Definition ray.hpp:109
Matrix< Float, 4, 4 > Mat4
A 4x4 matrix of type Float.
Definition matrix.hpp:811
constexpr T sin(T x)
Calculates the sine of an angle with constexpr support.
Definition function.hpp:216
constexpr T tan(T x)
Calculates the tangent of an angle with constexpr support.
Definition function.hpp:271
BoundingBox< Float, 3 > Bound3
3D bounding box
Definition bounding_box.hpp:221
Defines a generic, N-dimensional Point class and its geometric operations.
Defines a generic, N-dimensional geometric Ray class.
Defines a generic, N-dimensional, constexpr-friendly vector class.