Aether3D Game Engine
MathUtil.hpp
1 #ifndef MATH_UTIL_H
2 #define MATH_UTIL_H
3 
4 #ifndef INCLUDE_VECTOR_H
5 # include <vector>
6 # define INCLUDE_VECTOR_H
7 #endif
8 
9 #ifndef VEC3_H
10 # include "Vec3.hpp"
11 #endif
12 
13 namespace MathUtil
14 {
15  const float deg2rad = 3.1415926535f / 180.0f;
16  const float rad2deg = 180.0f / 3.1415926535f;
17  const float tolerance = 0.00001f;
18  const float pi = 3.1415926535f;
19 
25  bool AlmostEquals( float f1, float f2 );
26 
32  unsigned short ConvertF32ToF16( float valueToConvert );
33 
41  void GetMinMax( const std::vector< Vec3 >& points, Vec3& outMin, Vec3& outMax );
42 
50  void GetCorners( const Vec3& min, const Vec3& max, std::vector< Vec3 >& outCorners );
51 
53  float Floor( float f );
54 
56  float Ceil( float f );
57 
59  float Round( float f );
60 
69  float Lerp( float start, float end, float amount );
70 
78  float Random( float aMin, float aMax );
79 
90  float Remap( float value, float oldMin, float oldMax, float newMin, float newMax );
91 
99  bool IsNaN( float f );
100 
107  bool IsPowerOfTwo( unsigned i );
108 
109  template< typename T >
110  T Min2( T t1, T t2 )
111  {
112  return t1 < t2 ? t1 : t2;
113  }
114 
115  template< typename T >
116  T Max2( T t1, T t2 )
117  {
118  return t1 > t2 ? t1 : t2;
119  }
120 
130  float IntersectRayAABB( const Vec3& origin, const Vec3& target, const Vec3& min, const Vec3& max );
131 
141  bool IntersectSphereAndAABB( const Vec3& sphereOrigin, float sphereRadius, const Vec3& aabbMin, const Vec3& aabbMax );
142 
152  bool IntersectAABBandAABB( const Vec3& aabb1Min, const Vec3& aabb1Max, const Vec3& aabb2Min, const Vec3& aabb2Max );
153 }
154 #endif
3-component vector.
Definition: Vec3.hpp:22
Definition: MathUtil.hpp:13