40namespace orrery::viz {
54 [[nodiscard]]
constexpr bool operator==(
const Vec4&)
const =
default;
59 std::array<float, 16> values{};
61 [[nodiscard]]
constexpr float element(std::size_t row, std::size_t column)
const noexcept {
62 return values[(column * 4) + row];
65 [[nodiscard]]
constexpr bool operator==(
const Mat4&)
const =
default;
68[[nodiscard]]
constexpr Mat4 identity() noexcept {
69 return Mat4{{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}};
76 for (std::size_t column = 0; column < 4; ++column) {
77 for (std::size_t row = 0; row < 4; ++row) {
79 for (std::size_t index = 0; index < 4; ++index) {
80 sum += a.element(row, index) * b.element(index, column);
82 product.values[(column * 4) + row] = sum;
88[[nodiscard]]
constexpr Vec4 operator*(
const Mat4& matrix,
const Vec4& vector)
noexcept {
89 const std::array<float, 4> in{vector.x, vector.y, vector.z, vector.w};
90 std::array<float, 4> out{};
91 for (std::size_t row = 0; row < 4; ++row) {
92 for (std::size_t column = 0; column < 4; ++column) {
93 out[row] += matrix.element(row, column) * in[column];
96 return {out[0], out[1], out[2], out[3]};
101 return {
static_cast<float>(point.x),
static_cast<float>(point.y),
static_cast<float>(point.z),
123[[nodiscard]]
Mat4 perspective(
float vertical_field_of_view,
float aspect_ratio,
float near,
Mat4 perspective(float vertical_field_of_view, float aspect_ratio, float near, float far) noexcept
The perspective projection of a symmetric frustum.
constexpr Vec4 homogeneous(core::Vec3 point) noexcept
A point in world space, ready to be transformed.
Definition matrix4.hpp:100
Mat4 look_at(core::Vec3 eye, core::Vec3 centre, core::Vec3 up) noexcept
The view transform of a camera at eye looking at centre.
constexpr Mat4 operator*(const Mat4 &a, const Mat4 &b) noexcept
The transform that applies b and then a, as matrix products conventionally read.
Definition matrix4.hpp:74
A vector in three-dimensional Euclidean space.
Definition vec3.hpp:26
A 4-by-4 transform in column-major order.
Definition matrix4.hpp:58
A point or direction in homogeneous coordinates.
Definition matrix4.hpp:48
A three-component vector for interfaces, not for storage.