26 template <
typename T,
size_t N>
38 void load_args(
size_t&
i)
51 template <
typename... Args>
52 void load_args(
size_t&
i,
T arg, Args... args)
55 load_args(
i, args...);
67 for (
size_t i = 0;
i <
N; ++
i)
89 template <
typename... Args>
92 if constexpr (
sizeof...(args) == 0)
94 else if constexpr (
sizeof...(args) == 1)
99 load_args(
i, args...);
113 template <
typename OT,
size_t ON>
117 for (;
i <
N &&
i < ON; ++
i)
175 template <
typename O>
178 for (
size_t i = 0;
i <
N; ++
i)
180 if constexpr (std::is_same_v<O, T>)
182 else if constexpr (std::is_same_v<O, vec<T, N>>)
185 throw std::runtime_error(
"Unsupported O type");
201 template <
typename O>
204 for (
size_t i = 0;
i <
N; ++
i)
206 if constexpr (std::is_same_v<O, T>)
208 else if constexpr (std::is_same_v<O, vec<T, N>>)
211 throw std::runtime_error(
"Unsupported O type");
227 template <
typename O>
230 for (
size_t i = 0;
i <
N; ++
i)
232 if constexpr (std::is_same_v<O, T>)
234 else if constexpr (std::is_same_v<O, vec<T, N>>)
237 throw std::runtime_error(
"Unsupported O type");
253 template <
typename O>
256 for (
size_t i = 0;
i <
N; ++
i)
258 if constexpr (std::is_same_v<O, T>)
260 else if constexpr (std::is_same_v<O, vec<T, N>>)
263 throw std::runtime_error(
"Unsupported O type");
277 template <
typename O>
280 auto new_vec = *
this;
281 return (new_vec *= other);
293 template <
typename O>
296 auto new_vec = *
this;
297 return (new_vec /= other);
309 template <
typename O>
312 auto new_vec = *
this;
313 return (new_vec += other);
325 template <
typename O>
328 auto new_vec = *
this;
329 return (new_vec -= other);
341 auto new_vec = *
this;
342 for (
size_t i = 0;
i <
N; ++
i)
357 for (
size_t i = 0;
i <
N; ++
i)
361 return std::sqrt(sum);
375 for (
size_t i = 0;
i <
N; ++
i)
383 template <
typename T,
size_t N>
389 using Base::operator=;
390 using Base::operator+=;
391 using Base::operator-=;
392 using Base::operator*=;
393 using Base::operator/=;
394 using Base::operator+;
395 using Base::operator-;
396 using Base::operator*;
397 using Base::operator/;
398 using Base::operator[];
402 template <
typename... Args>
405 template <
typename OT,
size_t ON>
429 template <typename
T,
size_t C,
size_t R>
450 auto sizebytes =
sizeof(
T) *
C *
R;
451 memset(
matrix, 0, sizebytes);
454 for (
size_t c = 0;
c <
C &&
c <
R;
c++)
509 static_assert(
C == 4 &&
R == 4 &&
N == 3,
"translate requires a 4x4 matrix and 3D vector");
519 static_assert(
C == 4 &&
R == 4 &&
N == 3,
"translate requires a 4x4 matrix and 3D vector");
538 for (
size_t l = 0;
l <
N; ++
l)
550 for (
size_t l = 0;
l <
N; ++
l)
576 static_assert(
N == 2 ||
N == 3,
"Rotation axis must be 2D or 3D");
577 constexpr size_t D =
N;
579 T c = std::cos(angle);
580 T s = std::sin(angle);
584 if constexpr (
N == 2)
604 if constexpr (
N == 2)
606 r00 =
c; r01 = -
s; r02 = 0;
607 r10 =
s; r11 =
c; r12 = 0;
608 r20 = 0; r21 = 0; r22 = 1;
612 r00 =
x *
x * ic +
c;
613 r01 =
x *
y * ic -
z *
s;
614 r02 =
x *
z * ic +
y *
s;
616 r10 =
y *
x * ic +
z *
s;
617 r11 =
y *
y * ic +
c;
618 r12 =
y *
z * ic -
x *
s;
620 r20 =
z *
x * ic -
y *
s;
621 r21 =
z *
y * ic +
x *
s;
622 r22 =
z *
z * ic +
c;
626 for (
size_t cidx = 0; cidx <
C; ++cidx)
630 T vx = (
D > 0) ? col[0] :
T(0);
631 T vy = (
D > 1) ? col[1] :
T(0);
632 T vz = (
D > 2) ? col[2] :
T(0);
634 if constexpr (
N == 2)
636 col[0] = vx * r00 + vy * r01;
637 col[1] = vx * r10 + vy * r11;
641 col[0] = vx * r00 + vy * r01 + vz * r02;
642 col[1] = vx * r10 + vy * r11 + vz * r12;
643 col[2] = vx * r20 + vy * r21 + vz * r22;
654 static_assert(
N == 2 ||
N == 3,
"Rotation axis must be 2D or 3D");
655 constexpr size_t D =
N;
659 T c = std::cos(angle);
660 T s = std::sin(angle);
664 if constexpr (
N == 2)
684 if constexpr (
N == 2)
686 r00 =
c; r01 = -
s; r02 = 0;
687 r10 =
s; r11 =
c; r12 = 0;
688 r20 = 0; r21 = 0; r22 = 1;
692 r00 =
x *
x * ic +
c;
693 r01 =
x *
y * ic -
z *
s;
694 r02 =
x *
z * ic +
y *
s;
696 r10 =
y *
x * ic +
z *
s;
697 r11 =
y *
y * ic +
c;
698 r12 =
y *
z * ic -
x *
s;
700 r20 =
z *
x * ic -
y *
s;
701 r21 =
z *
y * ic +
x *
s;
702 r22 =
z *
z * ic +
c;
706 for (
size_t cidx = 0; cidx <
C; ++cidx)
710 T vx = (
D > 0) ? col[0] :
T(0);
711 T vy = (
D > 1) ? col[1] :
T(0);
712 T vz = (
D > 2) ? col[2] :
T(0);
714 if constexpr (
N == 2)
716 col[0] = vx * r00 + vy * r01;
717 col[1] = vx * r10 + vy * r11;
721 col[0] = vx * r00 + vy * r01 + vz * r02;
722 col[1] = vx * r10 + vy * r11 + vz * r12;
723 col[2] = vx * r20 + vy * r21 + vz * r22;
748 static_assert(
N == 2 ||
N == 3,
"Rotation axis must be 2D or 3D");
773 static_assert(
C ==
R,
"Inverse only defined for square matrices");
774 constexpr size_t N =
C;
779 for (
size_t i = 0;
i <
N; ++
i)
782 if (std::abs(pivot) < std::numeric_limits<T>::epsilon())
784 size_t swap_row =
i + 1;
785 while (swap_row <
N && std::abs(copy.
matrix[swap_row][
i]) < std::numeric_limits<T>::epsilon())
788 assert(
false &&
"Matrix is singular and cannot be inverted");
789 for (
size_t k = 0;
k <
N; ++
k)
797 T inv_pivot = (
T)1 / pivot;
798 for (
size_t j = 0;
j <
N; ++
j)
804 for (
size_t row = 0; row <
N; ++row)
809 for (
size_t col = 0; col <
N; ++col)
832 template <
size_t C2,
size_t R2>
835 static_assert(
C == R2,
"Matrix multiplication dimension mismatch");
840 for (
size_t c = 0;
c < C2;
c++)
842 for (
size_t r = 0;
r <
R;
r++)
845 for (
size_t k = 0;
k <
C;
k++)
854 static_assert(C2 ==
C &&
R == R2,
"operator*= requires output size equals current matrix size");
856 memcpy(
matrix, temp,
sizeof(temp));
871 template <
size_t C2,
size_t R2>
881 for (
size_t i = 0;
i <
C; ++
i)
883 for (
size_t j = 0;
j <
R; ++
j)
885 result[
j][
i] = (*this)[
i][
j];
925 T f_len = std::sqrt(
f[0]*
f[0] +
f[1]*
f[1] +
f[2]*
f[2]);
929 T up_len = std::sqrt(up[0]*up[0] + up[1]*up[1] + up[2]*up[2]);
933 f[1] * up_n[2] -
f[2] * up_n[1],
934 f[2] * up_n[0] -
f[0] * up_n[2],
935 f[0] * up_n[1] -
f[1] * up_n[0]
937 T s_len = std::sqrt(
s[0]*
s[0] +
s[1]*
s[1] +
s[2]*
s[2]);
941 s[1] *
f[2] -
s[2] *
f[1],
942 s[2] *
f[0] -
s[0] *
f[2],
943 s[0] *
f[1] -
s[1] *
f[0]
947 result[0][0] =
s[0]; result[1][0] =
s[1]; result[2][0] =
s[2];
948 result[0][1] =
u[0]; result[1][1] =
u[1]; result[2][1] =
u[2];
949 result[0][2] = -
f[0]; result[1][2] = -
f[1]; result[2][2] = -
f[2];
950 result[3][0] = - (
s[0]*eye[0] +
s[1]*eye[1] +
s[2]*eye[2]);
951 result[3][1] = - (
u[0]*eye[0] +
u[1]*eye[1] +
u[2]*eye[2]);
952 result[3][2] = + (
f[0]*eye[0] +
f[1]*eye[1] +
f[2]*eye[2]);
959 assert(std::abs(aspect - std::numeric_limits<T>::epsilon()) >
static_cast<T>(0));
961 T const tanHalfFovy = tan(fovy /
static_cast<T>(2));
964 result[0][0] =
static_cast<T>(1) / (aspect * tanHalfFovy);
965 result[1][1] =
static_cast<T>(1) / (tanHalfFovy);
966 result[2][2] = zFar / (zNear - zFar);
967 result[2][3] = -
static_cast<T>(1);
968 result[3][2] = -(zFar * zNear) / (zFar - zNear);
975 assert(std::abs(aspect - std::numeric_limits<T>::epsilon()) >
static_cast<T>(0));
977 T const tanHalfFovy = tan(fovy /
static_cast<T>(2));
980 result[0][0] =
static_cast<T>(1) / (aspect * tanHalfFovy);
981 result[1][1] =
static_cast<T>(1) / (tanHalfFovy);
982 result[2][2] = - (zFar + zNear) / (zFar - zNear);
983 result[2][3] = -
static_cast<T>(1);
984 result[3][2] = - (
static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
991 assert(std::abs(aspect - std::numeric_limits<T>::epsilon()) >
static_cast<T>(0));
993 T const tanHalfFovy = tan(fovy /
static_cast<T>(2));
996 result[0][0] =
static_cast<T>(1) / (aspect * tanHalfFovy);
997 result[1][1] =
static_cast<T>(1) / (tanHalfFovy);
998 result[2][2] = zFar / (zFar - zNear);
999 result[2][3] =
static_cast<T>(1);
1000 result[3][2] = -(zFar * zNear) / (zFar - zNear);
1004 template<
typename T>
1007 assert(std::abs(aspect - std::numeric_limits<T>::epsilon()) >
static_cast<T>(0));
1009 T const tanHalfFovy = tan(fovy /
static_cast<T>(2));
1012 result[0][0] =
static_cast<T>(1) / (aspect * tanHalfFovy);
1013 result[1][1] =
static_cast<T>(1) / (tanHalfFovy);
1014 result[2][2] = (zFar + zNear) / (zFar - zNear);
1015 result[2][3] =
static_cast<T>(1);
1016 result[3][2] = - (
static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
1043 template<
typename T>
1050#if defined(RENDERER_VULKAN)
1052#elif defined(RENDERER_GL)
1059 template<
typename T>
1062 T const range = tan(fovy /
static_cast<T>(2)) * zNear;
1063 T const left = -range * aspect;
1064 T const right = range * aspect;
1065 T const bottom = -range;
1066 T const top = range;
1069 result[0][0] = (
static_cast<T>(2) * zNear) / (right - left);
1070 result[1][1] = (
static_cast<T>(2) * zNear) / (top - bottom);
1071 result[2][2] = -
static_cast<T>(1);
1072 result[2][3] = -
static_cast<T>(1);
1073 result[3][2] = -
static_cast<T>(2) * zNear;
1077 template<
typename T>
1080 T const range = tan(fovy /
static_cast<T>(2)) * zNear;
1081 T const left = -range * aspect;
1082 T const right = range * aspect;
1083 T const bottom = -range;
1084 T const top = range;
1087 result[0][0] = (
static_cast<T>(2) * zNear) / (right - left);
1088 result[1][1] = (
static_cast<T>(2) * zNear) / (top - bottom);
1089 result[2][2] = -
static_cast<T>(1);
1090 result[2][3] = -
static_cast<T>(1);
1091 result[3][2] = - zNear;
1095 template<
typename T>
1098 T const range = tan(fovy /
static_cast<T>(2)) * zNear;
1099 T const left = -range * aspect;
1100 T const right = range * aspect;
1101 T const bottom = -range;
1102 T const top = range;
1105 result[0][0] = (
static_cast<T>(2) * zNear) / (right - left);
1106 result[1][1] = (
static_cast<T>(2) * zNear) / (top - bottom);
1107 result[2][2] =
static_cast<T>(1);
1108 result[2][3] =
static_cast<T>(1);
1109 result[3][2] = -
static_cast<T>(2) * zNear;
1113 template<
typename T>
1116 T const range = tan(fovy /
static_cast<T>(2)) * zNear;
1117 T const left = -range * aspect;
1118 T const right = range * aspect;
1119 T const bottom = -range;
1120 T const top = range;
1123 result[0][0] = (
static_cast<T>(2) * zNear) / (right - left);
1124 result[1][1] = (
static_cast<T>(2) * zNear) / (top - bottom);
1125 result[2][2] =
static_cast<T>(1);
1126 result[2][3] =
static_cast<T>(1);
1127 result[3][2] = - zNear;
1152 template<
typename T>
1155#if defined(RENDERER_VULKAN)
1157#elif defined(RENDERER_GL)
1184 template<
typename T>
1188 result[0][0] = (
T)2 / (right - left);
1189 result[1][1] = (
T)2 / (top - bottom);
1190 result[2][2] = -(
T)1 / (zfar - znear);
1191 result[3][0] = -(right + left) / (right - left);
1192 result[3][1] = -(top + bottom) / (top - bottom);
1193 result[3][2] = -(znear) / (zfar - znear);
1207 template<
typename T>
1210 return degrees *
T(0.01745329251994329576923690768489);
1222 template<
typename T>
1225 return radians *
T(57.295779513082320876798154814105);
1242 inline static std::random_device _randomDevice = {};
1247 inline static std::mt19937 _mt19937 = std::mt19937(_randomDevice());
1254 inline static void reseed_mt19937_with_current_time()
1256 auto now = std::chrono::high_resolution_clock::now();
1257 auto duration = now.time_since_epoch();
1258 auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
1259 std::uint32_t new_seed =
static_cast<std::uint32_t
>(nanos & 0xFFFFFFFF);
1260 _mt19937.seed(new_seed);
1280 template <
typename T>
1281 static const T value(
const T min,
const T max,
const size_t seed = (std::numeric_limits<size_t>::max)())
1283 std::mt19937* mt19937Pointer =
nullptr;
1285 if (seed != (std::numeric_limits<size_t>::max)())
1288 mt19937Pointer =
new std::mt19937(seed);
1293 reseed_mt19937_with_current_time();
1294 mt19937Pointer = &Random::_mt19937;
1297 if constexpr (std::is_floating_point<T>::value)
1299 std::uniform_real_distribution<T> distrib(min, max);
1300 auto value = distrib(*mt19937Pointer);
1302 if (seed != (std::numeric_limits<size_t>::max)())
1304 delete mt19937Pointer;
1305 mt19937Pointer =
nullptr;
1310 else if constexpr (std::is_integral<T>::value)
1312 std::uniform_int_distribution<T> distrib(min, max);
1313 auto value = distrib(*mt19937Pointer);
1315 if (seed != (std::numeric_limits<size_t>::max)())
1317 delete mt19937Pointer;
1318 mt19937Pointer =
nullptr;
1324 throw std::runtime_error(
"Type is not supported by Random::value");
1339 template <
typename T>
1340 static const T value(
const T min,
const T max, std::mt19937& mt19937)
1342 if constexpr (std::is_floating_point<T>::value)
1344 std::uniform_real_distribution<T> distrib(min, max);
1345 return distrib(mt19937);
1347 else if constexpr (std::is_integral<T>::value)
1349 std::uniform_int_distribution<T> distrib(min, max);
1350 return distrib(mt19937);
1352 throw std::runtime_error(
"Type is not supported by Random::value");
1366 template <
typename T>
1368 const size_t seed = (std::numeric_limits<size_t>::max)())
1370 auto rangesSize = ranges.size();
1371 auto rangesData = ranges.data();
1377 auto& range = rangesData[rangeIndex];
1391 template <
typename T>
1394 auto rangesSize = ranges.size();
1395 auto rangesData = ranges.data();
1401 auto& range = rangesData[rangeIndex];
1414 template <
typename T,
size_t N>
1448 template <
typename T>
1454 using Base::operator=;
1455 using Base::operator+=;
1456 using Base::operator-=;
1457 using Base::operator*=;
1458 using Base::operator/=;
1459 using Base::operator+;
1460 using Base::operator-;
1461 using Base::operator*;
1462 using Base::operator/;
1463 using Base::operator[];
1503 template <typename... Args>
1504 quat(Args&&... args) :
Base(std::forward<Args>(args)...) { }
1544 for (
size_t i = 0;
i < 4; ++
i)
1546 return conj / norm_sq;
1559 return vec<T, 3>(result[1], result[2], result[3]);
1588 T half_angle = angle *
T(0.5);
1589 T s = std::sin(half_angle);
1590 return quat<T>(std::cos(half_angle), axis[0] *
s, axis[1] *
s, axis[2] *
s);
1602 out_angle =
T(2) * std::acos(norm_q[0]);
1603 T s = std::sqrt(
T(1) - norm_q[0] * norm_q[0]);
1610 out_axis =
vec<T, 3>(norm_q[1] /
s, norm_q[2] /
s, norm_q[3] /
s);
1622 T xx =
x *
x, yy =
y *
y, zz =
z *
z;
1623 T xy =
x *
y, xz =
x *
z, yz =
y *
z;
1624 T wx =
w *
x, wy =
w *
y, wz =
w *
z;
1627 m[0][0] =
T(1) -
T(2) * (yy + zz);
1628 m[0][1] =
T(2) * (xy - wz);
1629 m[0][2] =
T(2) * (xz + wy);
1632 m[1][0] =
T(2) * (xy + wz);
1633 m[1][1] =
T(1) -
T(2) * (xx + zz);
1634 m[1][2] =
T(2) * (yz - wx);
1637 m[2][0] =
T(2) * (xz - wy);
1638 m[2][1] =
T(2) * (yz + wx);
1639 m[2][2] =
T(1) -
T(2) * (xx + yy);
1656 template <
typename T>
1675 result[0][0] =
T(1) -
T(2) * (yy + zz);
1676 result[0][1] =
T(2) * (xy - wz);
1677 result[0][2] =
T(2) * (xz + wy);
1678 result[1][0] =
T(2) * (xy + wz);
1679 result[1][1] =
T(1) -
T(2) * (xx + zz);
1680 result[1][2] =
T(2) * (yz - wx);
1681 result[2][0] =
T(2) * (xz - wy);
1682 result[2][1] =
T(2) * (yz + wx);
1683 result[2][2] =
T(1) -
T(2) * (xx + yy);
1695 template <
typename T>
1702 for (
int i = 0;
i < 4; ++
i)
1703 dot += q1[
i] * q2[
i];
1711 const T DOT_THRESHOLD =
T(0.9995);
1712 if (dot > DOT_THRESHOLD)
1714 quat<T> result = q1 + (q2 - q1) *
t;
1718 T theta_0 = std::acos(dot);
1719 T theta = theta_0 *
t;
1720 T sin_theta = std::sin(theta);
1721 T sin_theta_0 = std::sin(theta_0);
1723 T s0 = std::cos(theta) - dot * sin_theta / sin_theta_0;
1724 T s1 = sin_theta / sin_theta_0;
1726 return (q1 * s0 + q2 * s1).normalize();
1736 template <
typename T>
1739 T half = angle *
T(0.5);
1740 T s = std::sin(half);
1741 return quat<T>(std::cos(half), axis[0] *
s, axis[1] *
s, axis[2] *
s);
1750 template <
typename T>
1755 for (
size_t i = 0;
i < 3; ++
i)
1756 for (
size_t j = 0;
j < 3; ++
j)
Definition DirectZ.hpp:39
mat< T, 3, 3 > quat_to_mat3(const quat< T > &q)
Definition math.hpp:1657
@ a
Definition D7Stream.hpp:22
@ u
Definition D7Stream.hpp:21
@ T
Definition D7Stream.hpp:19
mat< T, 4, 4 > perspectiveLH_ZO(T fovy, T aspect, T zNear, T zFar)
Definition math.hpp:989
T radians(T degrees)
Converts an angle from degrees to radians.
Definition math.hpp:1208
mat< T, 4, 4 > perspectiveRH_ZO(T fovy, T aspect, T zNear, T zFar)
Definition math.hpp:957
mat< T, 4, 4 > lookAt(const vec< T, 3 > &eye, const vec< T, 3 > ¢er, const vec< T, 3 > &up)
Constructs a right-handed view matrix simulating a camera "look at" transform.
Definition math.hpp:922
quat< T > quat_from_axis_angle(const vec< T, 3 > &axis, T angle)
Constructs a quaternion from an axis-angle representation.
Definition math.hpp:1737
mat< T, 4, 4 > infinitePerspective(T fovy, T aspect, T zNear)
Creates an infinite perspective projection matrix.
Definition math.hpp:1153
mat< T, 4, 4 > orthographic(T left, T right, T bottom, T top, T znear, T zfar)
Creates an orthographic projection matrix.
Definition math.hpp:1185
T degrees(T radians)
Converts an angle from radians to degrees.
Definition math.hpp:1223
mat< T, 4, 4 > perspective(T fovy, T aspect, T zNear, T zFar)
Creates a perspective projection matrix suitable for rendering 3D scenes.
Definition math.hpp:1044
quat< T > slerp(const quat< T > &a, const quat< T > &b, T t)
Spherical linear interpolation between two quaternions.
Definition math.hpp:1696
mat< T, 4, 4 > infinitePerspectiveRH_ZO(T fovy, T aspect, T zNear)
Definition math.hpp:1078
mat< T, 4, 4 > quat_to_mat4(const quat< T > &q)
Converts a quaternion to a 4x4 rotation matrix.
Definition math.hpp:1751
mat< T, 4, 4 > infinitePerspectiveRH_NO(T fovy, T aspect, T zNear)
Definition math.hpp:1060
mat< T, 4, 4 > perspectiveRH_NO(T fovy, T aspect, T zNear, T zFar)
Definition math.hpp:973
mat< T, 4, 4 > perspectiveLH_NO(T fovy, T aspect, T zNear, T zFar)
Definition math.hpp:1005
mat< T, 4, 4 > infinitePerspectiveLH_ZO(T fovy, T aspect, T zNear)
Definition math.hpp:1114
mat< T, 4, 4 > infinitePerspectiveLH_NO(T fovy, T aspect, T zNear)
Definition math.hpp:1096
@ s
Definition Window.hpp:180
@ C
Definition Window.hpp:130
@ l
Definition Window.hpp:173
@ j
Definition Window.hpp:171
@ y
Definition Window.hpp:186
@ c
Definition Window.hpp:163
@ r
Definition Window.hpp:179
@ m
Definition Window.hpp:174
@ q
Definition Window.hpp:178
@ i
Definition Window.hpp:170
@ k
Definition Window.hpp:172
@ N
Definition Window.hpp:141
@ f
Definition Window.hpp:167
@ b
Definition Window.hpp:164
@ x
Definition Window.hpp:185
@ v
Definition Window.hpp:183
@ e
Definition Window.hpp:166
@ R
Definition Window.hpp:145
@ t
Definition Window.hpp:181
@ w
Definition Window.hpp:184
@ O
Definition Window.hpp:142
@ D
Definition Window.hpp:131
@ z
Definition Window.hpp:187
AABB()=default
Default constructor.
vec< T, N > max
Definition math.hpp:1418
AABB(vec< T, N > min, vec< T, N > max)
Construct an AABB with specified minimum and maximum corners.
Definition math.hpp:1433
vec< T, N > min
Definition math.hpp:1417
Utility class for generating random values with optional seeding and support for multiple numeric typ...
Definition math.hpp:1236
static const T value(const T min, const T max, const size_t seed=(std::numeric_limits< size_t >::max)())
Generate a uniformly distributed random value in [min, max].
Definition math.hpp:1281
static const T valueFromRandomRange(const std::vector< std::pair< T, T > > &ranges, const size_t seed=(std::numeric_limits< size_t >::max)())
Generate a uniformly distributed random value from multiple specified ranges.
Definition math.hpp:1367
static const T value(const T min, const T max, std::mt19937 &mt19937)
Generate a uniformly distributed random value in [min, max] using a provided mt19937 engine.
Definition math.hpp:1340
static const T valueFromRandomRange(const std::vector< std::pair< T, T > > &ranges, std::mt19937 &mt19937)
Generate a uniformly distributed random value from multiple specified ranges using external mt19937 e...
Definition math.hpp:1392
color_vec(color_vec &&) noexcept=default
color_vec(Args &&... args)
Definition math.hpp:403
color_vec(const color_vec &)=default
vec< T, N > Base
Definition math.hpp:386
color_vec & operator=(const color_vec &)=default
color_vec(const vec< OT, ON > &other)
Definition math.hpp:406
A generic fixed-size matrix template supporting common matrix operations.
Definition math.hpp:431
mat & rotateAround(T angle, const vec< T, N > &axis, const vec< T, N > &point)
Rotates the matrix around a specified pivot point.
Definition math.hpp:746
const vec< T, R > & operator[](size_t i) const
Provides access to the column vector at index i (const).
Definition math.hpp:491
mat & operator=(const mat &other)
Copy assignment operator.
Definition math.hpp:466
mat< T, C, R > inverse() const
Computes the inverse of a square matrix.
Definition math.hpp:771
mat< T, C2, R > operator*(const mat< T, C2, R2 > &rhs) const
Returns a new matrix which is the product of this matrix and rhs.
Definition math.hpp:872
static mat translate_static(const vec< T, N > &v)
Definition math.hpp:516
static mat rotate_static(T angle, const vec< T, N > &axis)
Definition math.hpp:652
T matrix[C][R]
Raw matrix storage, column-major order.
Definition math.hpp:437
vec< T, R > & operator[](size_t i)
Provides access to the column vector at index i (non-const).
Definition math.hpp:480
static mat scale_static(const vec< T, N > &v)
Definition math.hpp:547
mat & scale(const vec< T, N > &v)
Applies a component-wise scale to the matrix columns.
Definition math.hpp:536
mat & rotate(T angle, const vec< T, N > &axis)
Rotates the matrix in-place around the specified axis by the given angle.
Definition math.hpp:574
constexpr mat< T, R, C > transpose()
Definition math.hpp:878
mat & translate(const vec< T, N > &v)
Applies a translation to a 4x4 matrix by adding a vector to its position component.
Definition math.hpp:507
mat(T initial=T())
Constructs a matrix initialized to zero with optional diagonal initialization.
Definition math.hpp:448
mat< T, C, R > & operator*=(const mat< T, C2, R2 > &rhs)
Performs in-place multiplication by another matrix.
Definition math.hpp:833
A quaternion class for representing rotations in 3D space.
Definition math.hpp:1450
vec< T, 4 > Base
Definition math.hpp:1451
quat(const quat &)=default
Copy constructor.
quat(T w, T x, T y, T z)
Construct quaternion from explicit components.
Definition math.hpp:1513
mat< T, 4, 4 > to_mat4() const
Converts the quaternion to a 4x4 rotation matrix.
Definition math.hpp:1619
quat()=default
Default constructor. Components are uninitialized.
void to_axis_angle(vec< T, 3 > &out_axis, T &out_angle) const
Converts the quaternion to axis-angle representation.
Definition math.hpp:1599
quat< T > inverse() const
Returns the inverse of the quaternion.
Definition math.hpp:1540
vec< T, 3 > rotate(const vec< T, 3 > &v) const
Rotates a 3D vector using this quaternion.
Definition math.hpp:1555
T data[N]
Underlying array storing vector components.
Definition math.hpp:76
vec normalize() const
Returns a normalized (unit length) copy of the vector.
Definition math.hpp:371
quat< T > conjugate() const
Returns the conjugate of the quaternion.
Definition math.hpp:1528
quat & operator=(const quat &)=default
Copy assignment operator.
static quat< T > from_axis_angle(const vec< T, 3 > &axis, T angle)
Constructs a quaternion from an axis-angle representation.
Definition math.hpp:1586
quat(quat &&) noexcept=default
Move constructor.
quat< T > operator*(const quat< T > &rhs) const
Quaternion multiplication.
Definition math.hpp:1570
Template struct representing an N-dimensional vector of type T.
Definition math.hpp:28
vec & operator+=(const O &other)
Compound addition-assignment operator.
Definition math.hpp:228
vec operator/(const O &other) const
Division operator returning a new vector.
Definition math.hpp:294
vec operator-() const
Unary negation operator.
Definition math.hpp:339
vec operator-(const O &other) const
Subtraction operator returning a new vector.
Definition math.hpp:326
vec & operator-=(const O &other)
Compound subtraction-assignment operator.
Definition math.hpp:254
vec & operator/=(const O &other)
Compound division-assignment operator.
Definition math.hpp:202
T length() const
Computes the Euclidean length (magnitude) of the vector.
Definition math.hpp:354
vec operator*(const O &other) const
Multiplication operator returning a new vector.
Definition math.hpp:278
vec(const vec< OT, ON > &other)
Copy constructor to convert from vectors of different types and/or sizes.
Definition math.hpp:114
vec & operator=(const vec &other)
Assignment operator for component-wise copy.
Definition math.hpp:132
const T & operator[](size_t i) const
Index operator for const access to vector components.
Definition math.hpp:159
vec operator+(const O &other) const
Addition operator returning a new vector.
Definition math.hpp:310
T & operator[](size_t i)
Index operator for non-const access to vector components.
Definition math.hpp:146
T data[N]
Underlying array storing vector components.
Definition math.hpp:76
vec normalize() const
Returns a normalized (unit length) copy of the vector.
Definition math.hpp:371
vec(Args... args)
Variadic constructor to initialize vector components.
Definition math.hpp:90
vec & operator*=(const O &other)
Compound multiplication-assignment operator.
Definition math.hpp:176