33 #ifndef __VMML__UTIL__HPP__
34 #define __VMML__UTIL__HPP__
46 #define M_PI_F 3.14159265358979323846f
47 #define M_PI_2_F 1.57079632679489661923f
48 #define M_PI_3_F 1.04719755119659774615f
49 #define M_PI_4_F 0.78539816339744830962f
52 template<
typename T,
typename U >
bool equals( T arg0, U arg1)
54 return std::abs( arg0 - arg1 ) < std::numeric_limits< float >::epsilon();
61 template<
size_t M,
size_t N,
typename T >
62 inline matrix< M, N, T >
63 create_translation(
const vector< M - 1, T > &arg )
65 matrix< M, N, T > ret;
67 ret.set_translation( arg );
72 template<
typename T >
73 inline matrix< 4, 4, T >
76 return create_translation< 4, 4 >(arg);
79 template<
size_t M,
size_t N,
typename T >
81 apply_translation( matrix< M, N, T > &m, T t0, T t1, T t2 )
83 m *= create_translation< M, N, T >( vector< M - 1, T >( t0, t1, t2 ) );
86 template<
size_t M,
size_t N,
typename T >
87 inline matrix< M, N, T >
88 create_rotation( T angle,
const vector< M - 1, T > &axis )
90 matrix< M, N, T > ret;
92 ret.rotate( angle, axis );
97 template<
typename T >
98 inline matrix< 4, 4, T >
101 return create_rotation< 4, 4 >( angle, axis );
104 template<
size_t M,
size_t N,
typename T >
106 apply_rotation( matrix< M, N, T > &m, T angle, T t0, T t1, T t2 )
108 m *= create_rotation< M, N, T >( angle, vector< M - 1, T >( t0, t1, t2 ) );
111 template<
size_t M,
size_t N,
typename T >
112 inline matrix< M, N, T >
113 create_scaling(
const vector< N - 1, T > &arg )
115 matrix< M, N, T > ret;
122 template<
typename T >
123 inline matrix< 4, 4, T >
127 return create_scaling< 4, 4 >(arg);
130 template<
typename T >
131 inline matrix< 4, 4, T >
132 create_scaling( T arg )
141 template<
size_t M,
typename T >
142 inline void zero( vector< M, T > &arg )
144 std::fill( arg.begin(), arg.end(), 0 );
147 template<
size_t M,
typename T >
148 vector< M, T > min(
const vector< M, T > &arg0,
const vector< M, T > &arg1 )
152 for(
size_t i = 0; i < M; ++i )
153 ret[i] = std::min( arg0[i], arg1[i] );
158 template<
size_t M,
typename T >
159 vector< M, T > max(
const vector< M, T > &arg0,
const vector< M, T > &arg1 )
163 for(
size_t i = 0; i < M; ++i )
164 ret[i] = std::max( arg0[i], arg1[i] );
169 template<
size_t M,
typename T >
171 manhattan(
const vector< M, T > &arg )
174 for(
size_t i = 0; i < M; ++i )
176 ret += std::abs(arg[i]);
heavily inspired by boost::enable_if http://www.boost.org, file: boost/utility/enable_if.hpp, Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine