master
ブランチ master
VulkanExample / dep / include / glm / gtx / matrix_query.inl
3.4 KB、119行 生 Blame 履歴
1/// @ref gtx_matrix_query
2
3namespace glm
4{
5 template<typename T, qualifier Q>
6 GLM_FUNC_QUALIFIER bool isNull(mat<2, 2, T, Q> const& m, T const& epsilon)
7 {
8 bool result = true;
9 for(length_t i = 0; result && i < m.length() ; ++i)
10 result = isNull(m[i], epsilon);
11 return result;
12 }
13
14 template<typename T, qualifier Q>
15 GLM_FUNC_QUALIFIER bool isNull(mat<3, 3, T, Q> const& m, T const& epsilon)
16 {
17 bool result = true;
18 for(length_t i = 0; result && i < m.length() ; ++i)
19 result = isNull(m[i], epsilon);
20 return result;
21 }
22
23 template<typename T, qualifier Q>
24 GLM_FUNC_QUALIFIER bool isNull(mat<4, 4, T, Q> const& m, T const& epsilon)
25 {
26 bool result = true;
27 for(length_t i = 0; result && i < m.length() ; ++i)
28 result = isNull(m[i], epsilon);
29 return result;
30 }
31
32 template<length_t C, length_t R, typename T, qualifier Q>
33 GLM_FUNC_QUALIFIER bool isIdentity(mat<C, R, T, Q> const& m, T const& epsilon)
34 {
35 bool result = true;
36 for(length_t i = 0; result && i < m.length(); ++i)
37 {
38 for(length_t j = 0; result && j < glm::min(i, m[0].length()); ++j)
39 result = abs(m[i][j]) <= epsilon;
40 if(result && i < m[0].length())
41 result = abs(m[i][i] - 1) <= epsilon;
42 for(length_t j = i + 1; result && j < m[0].length(); ++j)
43 result = abs(m[i][j]) <= epsilon;
44 }
45 return result;
46 }
47
48 template<typename T, qualifier Q>
49 GLM_FUNC_QUALIFIER bool isNormalized(mat<2, 2, T, Q> const& m, T const& epsilon)
50 {
51 bool result(true);
52 for(length_t i = 0; result && i < m.length(); ++i)
53 result = isNormalized(m[i], epsilon);
54 for(length_t i = 0; result && i < m.length(); ++i)
55 {
56 typename mat<2, 2, T, Q>::col_type v;
57 for(length_t j = 0; j < m.length(); ++j)
58 v[j] = m[j][i];
59 result = isNormalized(v, epsilon);
60 }
61 return result;
62 }
63
64 template<typename T, qualifier Q>
65 GLM_FUNC_QUALIFIER bool isNormalized(mat<3, 3, T, Q> const& m, T const& epsilon)
66 {
67 bool result(true);
68 for(length_t i = 0; result && i < m.length(); ++i)
69 result = isNormalized(m[i], epsilon);
70 for(length_t i = 0; result && i < m.length(); ++i)
71 {
72 typename mat<3, 3, T, Q>::col_type v;
73 for(length_t j = 0; j < m.length(); ++j)
74 v[j] = m[j][i];
75 result = isNormalized(v, epsilon);
76 }
77 return result;
78 }
79
80 template<typename T, qualifier Q>
81 GLM_FUNC_QUALIFIER bool isNormalized(mat<4, 4, T, Q> const& m, T const& epsilon)
82 {
83 bool result(true);
84 for(length_t i = 0; result && i < m.length(); ++i)
85 result = isNormalized(m[i], epsilon);
86 for(length_t i = 0; result && i < m.length(); ++i)
87 {
88 typename mat<4, 4, T, Q>::col_type v;
89 for(length_t j = 0; j < m.length(); ++j)
90 v[j] = m[j][i];
91 result = isNormalized(v, epsilon);
92 }
93 return result;
94 }
95
96 template<length_t C, length_t R, typename T, qualifier Q>
97 GLM_FUNC_QUALIFIER bool isOrthogonal(mat<C, R, T, Q> const& m, T const& epsilon)
98 {
99 bool result = true;
100 for(length_t i(0); result && i < m.length(); ++i)
101 {
102 result = isNormalized(m[i], epsilon);
103 for(length_t j(i + 1); result && j < m.length(); ++j)
104 result = abs(dot(m[i], m[j])) <= epsilon;
105 }
106
107 if(result)
108 {
109 mat<C, R, T, Q> tmp = transpose(m);
110 for(length_t i(0); result && i < m.length(); ++i)
111 {
112 result = isNormalized(tmp[i], epsilon);
113 for(length_t j(i + 1); result && j < m.length(); ++j)
114 result = abs(dot(tmp[i], tmp[j])) <= epsilon;
115 }
116 }
117 return result;
118 }
119}//namespace glm