File include/math/matrix/base.hpp changed (mode: 100644) (index f45d03a..98026a6) |
... |
... |
namespace math |
27 |
27 |
m._[i][j] = type(0); |
m._[i][j] = type(0); |
28 |
28 |
return m; |
return m; |
29 |
29 |
} |
} |
30 |
|
|
|
31 |
30 |
MATR_T template<int other_size, int other_vector_size, typename other_t> |
MATR_T template<int other_size, int other_vector_size, typename other_t> |
32 |
31 |
constexpr inline MATRIX& |
constexpr inline MATRIX& |
33 |
32 |
MATRIX::operator*=(const matrix<other_size, other_vector_size, other_t>& m) { |
MATRIX::operator*=(const matrix<other_size, other_vector_size, other_t>& m) { |
|
... |
... |
namespace math |
46 |
45 |
m._[i][j] += _[i][k] * other._[k][j]; |
m._[i][j] += _[i][k] * other._[k][j]; |
47 |
46 |
return m; |
return m; |
48 |
47 |
} |
} |
49 |
|
/*template<typename type> template<typename other_t> inline |
|
50 |
|
matrix<4, 4, type> matrix<4, 4, type>::operator * (const matrix<4, 4, other_t>& other) const |
|
51 |
|
{ |
|
52 |
|
return {_[0] * other[0][0] + _[1] * other[0][1] + _[2] * other[0][2] + _[3] * other[0][3], |
|
53 |
|
_[0] * other[1][0] + _[1] * other[1][1] + _[2] * other[1][2] + _[3] * other[1][3], |
|
54 |
|
_[0] * other[2][0] + _[1] * other[2][1] + _[2] * other[2][2] + _[3] * other[2][3], |
|
55 |
|
_[0] * other[3][0] + _[1] * other[3][1] + _[2] * other[3][2] + _[3] * other[3][3] }; |
|
56 |
|
}*/ |
|
57 |
|
|
|
58 |
48 |
MATR_T template<typename other_t> |
MATR_T template<typename other_t> |
59 |
49 |
[[nodiscard]] constexpr inline typename MATRIX::vector |
[[nodiscard]] constexpr inline typename MATRIX::vector |
60 |
|
MATRIX::operator *(const math::vector<size, other_t>& vec) const { |
|
61 |
|
static_assert (size == vector_size); |
|
62 |
|
MATRIX::vector result{}; |
|
|
50 |
|
MATRIX::operator *(const math::vector<size, other_t>& vec) const |
|
51 |
|
{ |
|
52 |
|
MATRIX::vector v{}; |
63 |
53 |
for(int i = 0; i < size; i++) |
for(int i = 0; i < size; i++) |
64 |
54 |
for(int k = 0; k < vector_size; k++) |
for(int k = 0; k < vector_size; k++) |
65 |
|
result[i] += (*this)[i][k] * vec._[k]; |
|
66 |
|
return result; |
|
|
55 |
|
v[i] += (*this)[i][k] * vec[k]; |
|
56 |
|
return v; |
67 |
57 |
} |
} |
68 |
58 |
T_NUMERIC_IMPL MATRIX& MATRIX::operator += (const numeric_t& value) { |
T_NUMERIC_IMPL MATRIX& MATRIX::operator += (const numeric_t& value) { |
69 |
59 |
for (int i = 0; i < size; ++i) |
for (int i = 0; i < size; ++i) |
|
... |
... |
namespace math |
86 |
76 |
#undef MATRIX |
#undef MATRIX |
87 |
77 |
#undef MATRIX_OTHER |
#undef MATRIX_OTHER |
88 |
78 |
} |
} |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
File include/math/vector/vector_functions.h changed (mode: 100644) (index 6379980..b42b9b1) |
... |
... |
namespace math |
34 |
34 |
return (l + r) / two<T>; |
return (l + r) / two<T>; |
35 |
35 |
} |
} |
36 |
36 |
|
|
|
37 |
|
template<typename T> [[nodiscard]] constexpr inline |
|
38 |
|
T distance(const vector<3,T> &point1, const vector<3,T> &point2) { |
|
39 |
|
return (point2 - point1).length(); |
|
40 |
|
} |
|
41 |
|
|
37 |
42 |
template<typename T> [[nodiscard]] constexpr inline |
template<typename T> [[nodiscard]] constexpr inline |
38 |
43 |
T distance(const vector<4,T> &plane, const vector<3,T> &point) { |
T distance(const vector<4,T> &plane, const vector<3,T> &point) { |
39 |
44 |
auto normal = plane.template part<0,3>(); |
auto normal = plane.template part<0,3>(); |
|
... |
... |
namespace math |
49 |
54 |
vector<SIZE,T> normalize(const vector<SIZE, T> &v) { |
vector<SIZE,T> normalize(const vector<SIZE, T> &v) { |
50 |
55 |
return v.normalized(); |
return v.normalized(); |
51 |
56 |
} |
} |
|
57 |
|
|
|
58 |
|
template<typename T> [[nodiscard]] constexpr inline |
|
59 |
|
vector<3,T> intersection(const vector<4,T> &plane, const vector<3,T> &ray, |
|
60 |
|
const vector<3,T> &ray_point) { |
|
61 |
|
auto &normal = plane.template part<0,3>(); |
|
62 |
|
float scale = (plane.w - dot(normal, ray_point)) / dot(normal, ray); |
|
63 |
|
return ray_point + ray * scale; |
|
64 |
|
} |
52 |
65 |
} |
} |