CUGL 1.2
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 <cugl/base/CUBase.h>
13 #include <string>
14 #include <math.h>
15 #include <algorithm>
16 
17 #if defined (__WINDOWS__)
18  #define M_PI_2 1.57079632679489661923f // pi/2
19  #define M_PI_4 0.785398163397448309616f // pi/4
20  #define __attribute__(x)
21 #endif
22 
23 
25 #define CU_MATH_DEG_TO_RAD(x) ((x) * 0.0174532925f)
26 
27 #define CU_MATH_RAD_TO_DEG(x) ((x)* 57.29577951f)
28 
29 #define CU_MATH_APPROX(x,y,t) ( -(t) < (x)-(y) && (x)-(y) < (t) )
30 
32 #define CU_MATH_FLOAT_SMALL 1.0e-30f // Set by SSE
33 
34 #define CU_MATH_EPSILON 5.0e-4f // Set by SSE
35 
36 #if defined (__WINDOWS__)
37  #define NOMAXMIN
38 #endif
39 
40 #if defined (__ANDROID__)
41  #include <android/cpu-features.h>
42 #endif
43 
44 // Define the vectorization support
45 // By experimentation, there are only two vectorizations worth supporting
46 #if defined (__arm64__)
47  #define CU_MATH_VECTOR_NEON64
48  #include <arm_neon.h>
49 #elif defined (__SSE__) && defined (__MACOSX__)
50  // Windows vector math has not been properly resolved
51  #define CU_MATH_VECTOR_SSE
52  #include "immintrin.h"
53  #include "smmintrin.h"
54  #include "xmmintrin.h"
55 #endif
56 
68 inline float clampf(float value, float min, float max) {
69  return value < min ? min : value < max? value : max;
70 }
71 
83 inline GLubyte clampb(GLuint value, GLubyte min, GLubyte max) {
84  return static_cast<GLubyte>(value < min ? min : value < max? value : max);
85 }
86 
94 int nextPOT(int x);
95 
96 #endif /* CU_MATH_BASE_H */