polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

util.h (1186B)


      1 
      2 #ifndef PA_UTIL_H
      3 #define PA_UTIL_H
      4 
      5 #include "gl.h"
      6 #include "vec3.h"
      7 #include "mat4.h"
      8 #include <assert.h>
      9 #include <string.h>
     10 
     11 #define check_gl() {                                    \
     12         unsigned int e = glGetError();                  \
     13         if (e != GL_NO_ERROR) {                         \
     14             printf("Got error from OpenGL: %d\n", e);   \
     15             assert(0);                                  \
     16         }                                               \
     17     }
     18 
     19 #define STRIZE_DETAIL(x) #x
     20 #define STRIZE(x) STRIZE_DETAIL(x)
     21 
     22 #define UP_VEC V3(0.0, 0.0, 1.0)
     23 #define PI 3.14159265
     24 #define TAU 6.2831853
     25 
     26 #define RAD(x) ((x)*TAU/360.0)
     27 
     28 #define EPSILON 0.0001
     29 #define ARRAY_SIZE(x) ((int)(sizeof(x) / sizeof((x)[0])))
     30 #define min(a,b) (a < b ? a : b)
     31 #define max(a,b) (a > b ? a : b)
     32 #define streq(a,b) (strcmp(a,b) == 0)
     33 #define contains(a,b) (strstr(a,b) != NULL)
     34 #define memeq(a,b,n1,n2) (memcmp(a,b,min(n1, n2)) == 0)
     35 #define approxeq(a, b) (fabs(a-b) < EPSILON)
     36 
     37 void look_at(vec3 *eye, vec3 *target, vec3 *up, mat4 *dest);
     38 int clampi(int a, int mina, int maxa);
     39 double clamp(double a, double mina, double maxa);
     40 
     41 double rand_0to1();
     42 
     43 #endif /* PA_UTIL_H */