polyadvent

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

util.h (1259B)


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