77#include <nbl/builtin/hlsl/mpl.hlsl>
88#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
99#include <nbl/builtin/hlsl/concepts.hlsl>
10+ #include <nbl/builtin/hlsl/math/linalg/basic.hlsl>
1011
1112namespace nbl
1213{
@@ -17,83 +18,6 @@ namespace math
1718namespace linalg
1819{
1920
20- /// Builds a rotation 3 * 3 matrix created from an axis vector and an angle.
21- ///
22- /// @param angle Rotation angle expressed in radians.
23- /// @param axis Rotation axis, must be normalized.
24- ///
25- /// @tparam T A floating-point scalar type
26- template <typename T>
27- matrix <T, 3 , 3 > rotation_mat (T angle, const vector <T, 3 > axis)
28- {
29- const T a = angle;
30- const T c = cos (a);
31- const T s = sin (a);
32-
33- vector <T, 3 > temp = hlsl::promote<vector <T, 3 > >((T (1.0 ) - c) * axis);
34-
35- matrix <T, 3 , 3 > rotation;
36- rotation[0 ][0 ] = c + temp[0 ] * axis[0 ];
37- rotation[0 ][1 ] = temp[1 ] * axis[0 ] - s * axis[2 ];
38- rotation[0 ][2 ] = temp[2 ] * axis[0 ] + s * axis[1 ];
39-
40- rotation[1 ][0 ] = temp[0 ] * axis[1 ] + s * axis[2 ];
41- rotation[1 ][1 ] = c + temp[1 ] * axis[1 ];
42- rotation[1 ][2 ] = temp[2 ] * axis[1 ] - s * axis[0 ];
43-
44- rotation[2 ][0 ] = temp[0 ] * axis[2 ] - s * axis[1 ];
45- rotation[2 ][1 ] = temp[1 ] * axis[2 ] + s * axis[0 ];
46- rotation[2 ][2 ] = c + temp[2 ] * axis[2 ];
47-
48- return rotation;
49- }
50-
51- namespace impl
52- {
53- template<uint16_t MOut, uint16_t MIn , typename T>
54- struct zero_expand_helper
55- {
56- static vector <T, MOut> __call (const vector <T, MIn > inVec)
57- {
58- return vector <T, MOut>(inVec, vector <T, MOut - MIn >(0 ));
59- }
60- };
61- template<uint16_t M, typename T>
62- struct zero_expand_helper<M,M,T>
63- {
64- static vector <T, M> __call (const vector <T, M> inVec)
65- {
66- return inVec;
67- }
68- };
69- }
70-
71- template<uint16_t MOut, uint16_t MIn , typename T NBL_FUNC_REQUIRES (MOut >= MIn )
72- vector <T, MOut> zero_expand (vector <T, MIn > inVec)
73- {
74- return impl::zero_expand_helper<MOut, MIn , T>::__call (inVec);
75- }
76-
77- template <uint16_t NOut, uint16_t MOut, uint16_t NIn, uint16_t MIn , typename T NBL_FUNC_REQUIRES (NOut >= NIn && MOut >= MIn )
78- matrix <T, NOut, MOut> promote_affine (const matrix <T, NIn, MIn > inMatrix)
79- {
80- matrix <T, NOut, MOut> retval;
81-
82- using out_row_t = hlsl::vector <T, MOut>;
83-
84- NBL_UNROLL for (uint32_t row_i = 0 ; row_i < NIn; row_i++)
85- {
86- retval[row_i] = zero_expand<MOut, MIn >(inMatrix[row_i]);
87- }
88- NBL_UNROLL for (uint32_t row_i = NIn; row_i < NOut; row_i++)
89- {
90- retval[row_i] = promote<out_row_t>(0.0 );
91- if (row_i < MOut)
92- retval[row_i][row_i] = T (1.0 );
93- }
94- return retval;
95- }
96-
9721// /Arek: glm:: for normalize till dot product is fixed (ambiguity with glm namespace + linker issues)
9822template<typename T>
9923inline matrix <T, 3 , 4 > lhLookAt (
@@ -131,19 +55,6 @@ inline matrix<T, 3, 4> rhLookAt(
13155 return r;
13256}
13357
134- template<typename T, int16_t N, int16_t M, int16_t VecN>
135- inline void setTranslation (NBL_REF_ARG (matrix <T, N, M>) outMat, NBL_CONST_REF_ARG (vector <T, VecN>) translation)
136- {
137- // TODO: not sure if it will be compatible with hlsl
138- static_assert (M > 0 && N > 0 );
139- static_assert (M >= VecN);
140-
141- NBL_CONSTEXPR int16_t indexOfTheLastRowComponent = M - 1 ;
142-
143- for (int i = 0 ; i < VecN; ++i)
144- outMat[i][indexOfTheLastRowComponent] = translation[i];
145- }
146-
14758}
14859}
14960}
0 commit comments