opengl

Sample code from LearnOpenGL.com
Log | Files | Refs

glm.h (1789B)


      1 typedef struct vec {
      2 	float *data;
      3 	int size;
      4 } vec;
      5 
      6 // mat is square matrix of which size is size by size.
      7 typedef struct mat {
      8 	float *data; // column major
      9 	int size;
     10 } mat;
     11 
     12 // VecStr() set s the string representation of v and returns the same char*.
     13 char *vecStr(char *s, vec *v);
     14 // VecMake() allocates a vec and copy the data to its data.
     15 // Caller is responsible for freeing the vec by calling vecFree().
     16 vec *vecMake(float *data, int size);
     17 // VecCopy() returns the copy of v. Caller is responsible for freeing
     18 // the resulting vec.
     19 vec *vecCopy(const vec *v);
     20 // VecFree() frees v.
     21 void vecFree(vec* v);
     22 // VecCount() returns the number of vecs allocated and not yes freed.
     23 int vecCount(void);
     24 // VecEq() tests equality of v and w.
     25 int vecEq(vec *v, vec *w);
     26 // VecAdd() adds w to v. w is unchanged. Returns the address of v or NULL if
     27 // an error occurs.
     28 vec *vecAdd(vec *v, const vec *w);
     29 vec *vecSub(vec *v, const vec *w);
     30 // VecSubRev calcurates w - v and stores the result to v and returns v.
     31 vec *vecSubRev(vec *v, const vec *w);
     32 float vecDot(const vec *v, const vec *w);
     33 vec *vecCross(vec *v, const vec *w);
     34 vec *vecNormalize(vec *v);
     35 
     36 char *matStr(char *s, mat *m);
     37 mat *matMake(float *data, int size);
     38 mat *matMakeIdent(int size);
     39 mat *matMakePers(float fov, float aspect, float near, float far);
     40 mat *matMakeOrth(float minx, float maxx, float miny, float maxy, float near,
     41 	float far);
     42 mat *matMakeLookAt(const vec *pos, const vec *target, const vec *up);
     43 mat *matCopy(const mat *m);
     44 void matFree(mat *m);
     45 mat *matDot(mat *m, const mat *n);
     46 int matCount(void);
     47 
     48 float *matDataPtr(mat *m);
     49 
     50 mat *translate(mat *m, const vec *v);
     51 // axis must be an unit vector
     52 mat *rotate(mat *m, float rad, vec *axis);
     53 mat *scale(mat *m, float s);
     54 vec *matVecDot(const mat *m, vec *v);