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 >
54 equals( T arg0, U arg1)
56 return fabs( arg0 - arg1 ) < std::numeric_limits< float >::epsilon();
63 template<
size_t M,
size_t N,
typename T >
64 inline matrix< M, N, T >
65 create_translation(
const vector< M - 1, T > &arg )
67 matrix< M, N, T > ret;
69 ret.set_translation( arg );
74 template<
typename T >
75 inline matrix< 4, 4, T >
78 return create_translation< 4, 4 >(arg);
81 template<
size_t M,
size_t N,
typename T >
83 apply_translation( matrix< M, N, T > &m, T t0, T t1, T t2 )
85 m *= create_translation< M, N, T >( vector< M - 1, T >( t0, t1, t2 ) );
88 template<
size_t M,
size_t N,
typename T >
89 inline matrix< M, N, T >
90 create_rotation( T angle,
const vector< M - 1, T > &axis )
92 matrix< M, N, T > ret;
94 ret.rotate( angle, axis );
99 template<
typename T >
100 inline matrix< 4, 4, T >
103 return create_rotation< 4, 4 >( angle, axis );
106 template<
size_t M,
size_t N,
typename T >
108 apply_rotation( matrix< M, N, T > &m, T angle, T t0, T t1, T t2 )
110 m *= create_rotation< M, N, T >( angle, vector< M - 1, T >( t0, t1, t2 ) );
113 template<
size_t M,
size_t N,
typename T >
114 inline matrix< M, N, T >
115 create_scaling(
const vector< N - 1, T > &arg )
117 matrix< M, N, T > ret;
124 template<
typename T >
125 inline matrix< 4, 4, T >
129 return create_scaling< 4, 4 >(arg);
132 template<
typename T >
133 inline matrix< 4, 4, T >
134 create_scaling( T arg )
143 template<
size_t M,
typename T >
144 inline void zero( vector< M, T > &arg )
146 std::fill( arg.begin(), arg.end(), 0 );
149 template<
size_t M,
typename T >
150 vector< M, T > min(
const vector< M, T > &arg0,
const vector< M, T > &arg1 )
154 for(
size_t i = 0; i < M; ++i )
155 ret[i] = std::min( arg0[i], arg1[i] );
160 template<
size_t M,
typename T >
161 vector< M, T > max(
const vector< M, T > &arg0,
const vector< M, T > &arg1 )
165 for(
size_t i = 0; i < M; ++i )
166 ret[i] = std::max( arg0[i], arg1[i] );
171 template<
size_t M,
typename T >
173 manhattan(
const vector< M, T > &arg )
176 for(
size_t i = 0; i < M; ++i )
178 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