CUGL 1.1
Cornell University Game Library
CUMathBase.h
1 //
2 // CUMathBase.h
3 // CUGL
4 //
5 // Created by Walker White on 5/30/16.
6 // Copyright © 2016 Game Design Initiative at Cornell. All rights reserved.
7 //
8 
9 // TODO: COMMENT THIS FILE
10 #ifndef __CU_MATH_BASE_H__
11 #define __CU_MATH_BASE_H__
12 #include <cugl/base/CUBase.h>
13 #include <string>
14 #include <math.h>
15 
16 #if defined (__WINDOWS__)
17  #define M_PI_2 1.57079632679489661923f // pi/2
18  #define M_PI_4 0.785398163397448309616f // pi/4
19 #endif
20 
21 
23 #define CU_MATH_DEG_TO_RAD(x) ((x) * 0.0174532925f)
24 
25 #define CU_MATH_RAD_TO_DEG(x) ((x)* 57.29577951f)
26 
27 #define CU_MATH_APPROX(x,y,t) ( -(t) < (x)-(y) && (x)-(y) < (t) )
28 
30 #define CU_MATH_FLOAT_SMALL 1.0e-37f
31 
32 #define CU_MATH_EPSILON 1.0e-7f
33 
34 // Define the vectorization support
35 #if defined (__ANDROID__) && defined (__arm64__)
36  #define CU_MATH_VECTOR_NEON64
37 #elif defined (__ANDROID__)
38  #define CU_MATH_VECTOR_ANDROID
39 #elif defined (__MACOSX__)
40  // vecLib is essentially useless on iOS
41  #define CU_MATH_VECTOR_APPLE
42 #elif defined (__IPHONE__)
43  #define CU_MATH_VECTOR_IOS
44 #elif defined (__SSE__)
45  // TODO: There is apparently an alignment error here
46  // I do not know enough SSE to debug this right now
47  // #define CU_MATH_VECTOR_SSE
48 #endif
49 
61 inline float clampf(float value, float min, float max) {
62  return value < min ? min : value < max? value : max;
63 }
64 
76 inline GLubyte clampb(GLuint value, GLubyte min, GLubyte max) {
77  return static_cast<GLubyte>(value < min ? min : value < max? value : max);
78 }
79 
87 int nextPOT(int x);
88 
89 #endif /* CU_MATH_BASE_H */