polyadvent

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

mat_util.c (905B)


      1 
      2 #include "mat_util.h"
      3 
      4 mat4 *mat4_create_transform(float *pos, float *scale, float *rot, mat4 *dest) {
      5   dest[0] = scale[0] * rot[0];
      6   dest[1] = scale[0] * rot[1];
      7   dest[2] = scale[0] * rot[2];
      8   dest[3] = 0;
      9 
     10   dest[4] = scale[1] * rot[3];
     11   dest[5] = scale[1] * rot[4];
     12   dest[6] = scale[1] * rot[5];
     13   dest[7] = 0;
     14 
     15   dest[8] = scale[2] * rot[6];
     16   dest[9] = scale[2] * rot[7];
     17   dest[10] = scale[2] * rot[8];
     18   dest[11] = 0;
     19 
     20   dest[12] = pos[0];
     21   dest[13] = pos[1];
     22   dest[14] = pos[2];
     23   dest[15] = 1;
     24 
     25   return dest;
     26 }
     27 
     28 vec3 *vec3_forward_amt(quat *orientation, float *dir, float *dest)
     29 {
     30     float q[4] = {0};
     31     quat_inverse(orientation, q);
     32     quat_multiply_vec3(q, dir, dest);
     33     return dest;
     34 }
     35 
     36 vec3 *vec3_forward(vec3 *v, quat *orientation, float *dir, float *dest) {
     37     float movement[3] = {0};
     38     vec3_add(v, vec3_forward_amt(orientation, dir, movement), dest);
     39     return dest;
     40 }