CUGL
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 "../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 
29 #define CU_MATH_FLOAT_SMALL 1.0e-37f
30 #define CU_MATH_EPSILON 1.0e-7f
31 
32 // Define the vectorization support
33 #if defined (__ANDROID__) && defined (__arm64__)
34  #define CU_MATH_VECTOR_NEON64
35 #elif defined (__ANDROID__)
36  #define CU_MATH_VECTOR_ANDROID
37 #elif defined (__MACOSX__)
38  // vecLib is essentially useless on iOS
39  #define CU_MATH_VECTOR_APPLE
40 #elif defined (__IPHONE__)
41  #define CU_MATH_VECTOR_IOS
42 #elif defined (__SSE__)
43  #define CU_MATH_VECTOR_SSE
44 #endif
45 
46 
47 
48 inline float clampf(float value, float min, float max) {
49  return value < min ? min : value < max? value : max;
50 }
51 
52 inline GLubyte clampb(GLuint value, GLubyte min, GLubyte max) {
53  return static_cast<GLubyte>(value < min ? min : value < max? value : max);
54 }
55 
56 int nextPOT(int x);
57 
58 #endif /* CU_MATH_BASE_H */