Home | History | Annotate | Download | only in gtx
      1 ///////////////////////////////////////////////////////////////////////////////////////////////////
      2 // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
      3 ///////////////////////////////////////////////////////////////////////////////////////////////////
      4 // Created : 2007-03-05
      5 // Updated : 2007-03-05
      6 // Licence : This source is under MIT License
      7 // File    : glm/gtx/matrix_query.inl
      8 ///////////////////////////////////////////////////////////////////////////////////////////////////
      9 // Dependency:
     10 // - GLM core
     11 ///////////////////////////////////////////////////////////////////////////////////////////////////
     12 
     13 namespace glm
     14 {
     15 	template<typename T, precision P>
     16 	GLM_FUNC_QUALIFIER bool isNull(detail::tmat2x2<T, P> const & m, T const & epsilon)
     17 	{
     18 		bool result = true;
     19 		for(length_t i = 0; result && i < 2 ; ++i)
     20 			result = isNull(m[i], epsilon);
     21 		return result;
     22 	}
     23 
     24 	template<typename T, precision P>
     25 	GLM_FUNC_QUALIFIER bool isNull(detail::tmat3x3<T, P> const & m, T const & epsilon)
     26 	{
     27 		bool result = true;
     28 		for(length_t i = 0; result && i < 3 ; ++i)
     29 			result = isNull(m[i], epsilon);
     30 		return result;
     31 	}
     32 
     33 	template<typename T, precision P>
     34 	GLM_FUNC_QUALIFIER bool isNull(detail::tmat4x4<T, P> const & m, T const & epsilon)
     35 	{
     36 		bool result = true;
     37 		for(length_t i = 0; result && i < 4 ; ++i)
     38 			result = isNull(m[i], epsilon);
     39 		return result;
     40 	}
     41 
     42 	template<typename T, precision P, template <typename, precision> class matType>
     43 	GLM_FUNC_QUALIFIER bool isIdentity(matType<T, P> const & m, T const & epsilon)
     44 	{
     45 		bool result = true;
     46 		for(length_t i(0); result && i < m[0].length(); ++i)
     47 		{
     48 			for(length_t j(0); result && j < i ; ++j)
     49 				result = abs(m[i][j]) <= epsilon;
     50 			if(result)
     51 				result = abs(m[i][i] - 1) <= epsilon;
     52 			for(length_t j(i + 1); result && j < m.length(); ++j)
     53 				result = abs(m[i][j]) <= epsilon;
     54 		}
     55 		return result;
     56 	}
     57 
     58 	template<typename T, precision P>
     59 	GLM_FUNC_QUALIFIER bool isNormalized(detail::tmat2x2<T, P> const & m, T const & epsilon)
     60 	{
     61 		bool result(true);
     62 		for(length_t i(0); result && i < m.length(); ++i)
     63 			result = isNormalized(m[i], epsilon);
     64 		for(length_t i(0); result && i < m.length(); ++i)
     65 		{
     66 			typename detail::tmat2x2<T, P>::col_type v;
     67 			for(length_t j(0); j < m.length(); ++j)
     68 				v[j] = m[j][i];
     69 			result = isNormalized(v, epsilon);
     70 		}
     71 		return result;
     72 	}
     73 
     74 	template<typename T, precision P>
     75 	GLM_FUNC_QUALIFIER bool isNormalized(detail::tmat3x3<T, P> const & m, T const & epsilon)
     76 	{
     77 		bool result(true);
     78 		for(length_t i(0); result && i < m.length(); ++i)
     79 			result = isNormalized(m[i], epsilon);
     80 		for(length_t i(0); result && i < m.length(); ++i)
     81 		{
     82 			typename detail::tmat3x3<T, P>::col_type v;
     83 			for(length_t j(0); j < m.length(); ++j)
     84 				v[j] = m[j][i];
     85 			result = isNormalized(v, epsilon);
     86 		}
     87 		return result;
     88 	}
     89 
     90 	template<typename T, precision P>
     91 	GLM_FUNC_QUALIFIER bool isNormalized(detail::tmat4x4<T, P> const & m, T const & epsilon)
     92 	{
     93 		bool result(true);
     94 		for(length_t i(0); result && i < m.length(); ++i)
     95 			result = isNormalized(m[i], epsilon);
     96 		for(length_t i(0); result && i < m.length(); ++i)
     97 		{
     98 			typename detail::tmat4x4<T, P>::col_type v;
     99 			for(length_t j(0); j < m.length(); ++j)
    100 				v[j] = m[j][i];
    101 			result = isNormalized(v, epsilon);
    102 		}
    103 		return result;
    104 	}
    105 
    106 	template<typename T, precision P, template <typename, precision> class matType>
    107 	GLM_FUNC_QUALIFIER bool isOrthogonal(matType<T, P> const & m, T const & epsilon)
    108 	{
    109 		bool result(true);
    110 		for(length_t i(0); result && i < m.length() - 1; ++i)
    111 		for(length_t j(i + 1); result && j < m.length(); ++j)
    112 			result = areOrthogonal(m[i], m[j], epsilon);
    113 
    114 		if(result)
    115 		{
    116 			matType<T, P> tmp = transpose(m);
    117 			for(length_t i(0); result && i < m.length() - 1 ; ++i)
    118 			for(length_t j(i + 1); result && j < m.length(); ++j)
    119 				result = areOrthogonal(tmp[i], tmp[j], epsilon);
    120 		}
    121 		return result;
    122 	}
    123 }//namespace glm
    124