9#ifndef XCMATH_FUNCTION_HPP
10#define XCMATH_FUNCTION_HPP
52template <
class _Tp,
size_t _length = 3,
size_t _dim = 4>
53 requires((_length == 3 || _length == 4) && (_dim == 4 || _dim == 3))
59 _Tp c = std::cos(angle);
60 _Tp s = std::sin(angle);
62 res[0][0] = c + t * _axis[0] * _axis[0];
63 res[0][1] = t * _axis[0] * _axis[1] - s * _axis[2];
64 res[0][2] = t * _axis[0] * _axis[2] + s * _axis[1];
66 res[1][0] = t * _axis[0] * _axis[1] + s * _axis[2];
67 res[1][1] = c + t * _axis[1] * _axis[1];
68 res[1][2] = t * _axis[1] * _axis[2] - s * _axis[0];
70 res[2][0] = t * _axis[0] * _axis[2] - s * _axis[1];
71 res[2][1] = t * _axis[1] * _axis[2] + s * _axis[0];
72 res[2][2] = c + t * _axis[2] * _axis[2];
85template <
class _Tp,
class _MTp = _Tp,
size_t _dim = 3>
86 requires(std::is_floating_point_v<_Tp> && (_dim == 3 || _dim == 4))
87mat<_MTp, _dim, _dim>
rotate(const
mat<_MTp, _dim, _dim>& m, _Tp angle) {
90 res[1][1] = res[0][0] = std::cos(angle);
91 res[0][1] = -(res[1][0] = std::sin(angle));
107template <
class _Tp,
class _ATp = _Tp,
size_t _dim = 3>
108 requires(std::is_floating_point_v<_Tp> && std::is_floating_point_v<_ATp>)
123template <
class _Tp,
size_t _len = 4,
size_t _vlen = 3>
124 requires((_len == 4 || _len == 3) && _vlen == _len - 1)
126 const
vec<_Tp, _vlen>& v) {
128 res[0][_vlen] += v[0];
129 res[1][_vlen] += v[1];
130 if constexpr (_len == 4) res[2][_vlen] += v[2];
143template <
class _Tp,
size_t _len = 4>
144 requires(_len == 4 || _len == 3)
147 return translate(m, v(slice_to<_len - 1>));
157template <
class _Tp,
class _ATp = _Tp,
size_t _dim = 4>
158 requires(std::is_floating_point_v<_Tp> && std::is_floating_point_v<_ATp> &&
159 (_dim == 4 || _dim == 3))
160constexpr
mat<_Tp, _dim, _dim>
scale(const
mat<_Tp, _dim, _dim>& m,
161 const
vec<_ATp, _dim - 1>& v) {
165 if constexpr (_dim == 4) res[2][2] *= v[2];
178template <
class _Tp,
class _STp,
size_t _dim = 4>
179 requires(std::is_arithmetic_v<_STp> && (_dim == 4 || _dim == 3))
180constexpr
mat<_Tp, _dim, _dim>
scale(const
mat<_Tp, _dim, _dim>& m,
static constexpr mat< _Tp, _rows, _cols > eye()
Create an identity matrix
constexpr vec< _Tp, _length > normalize() const
Create unit vector in same direction
Declaration of vector, matrix, quaternion, and complex classes
Compiler-specific type information handling for MSVC
constexpr long double PI
Pi constant
constexpr T radians(T degrees)
Convert degrees to radians
constexpr mat< _Tp, _len, _len > translate(const mat< _Tp, _len, _len > &m, const vec< _Tp, _vlen > &v)
Apply translation for matrix
constexpr T degrees(T radians)
Convert radians to degrees
mat< _Tp, _dim, _dim > rotate(const mat< _Tp, _dim, _dim > &m, _Tp angle, const vec< _Tp, _length > &axis)
Apply rotation for transform or rotation matrix around an axis
constexpr mat< _Tp, _dim, _dim > scale(const mat< _Tp, _dim, _dim > &m, const vec< _ATp, _dim - 1 > &v)
Apply translation to a matrix