Created
March 14, 2016 16:38
-
-
Save antonijn/96d9a1d034e3fea95609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec4 mat4_col(const mat4 *m, int c) | |
{ | |
vec4 res; | |
res.x = m->frows[0][c]; | |
res.y = m->frows[1][c]; | |
res.z = m->frows[2][c]; | |
res.w = m->frows[3][c]; | |
return res; | |
} | |
mat4 mat4_transpose(const mat4 *m) | |
{ | |
mat4 res; | |
int i, j; | |
for (i = 0; i < 4; ++i) | |
for (j = 0; j < 4; ++j) | |
res.frows[i][j] = m->frows[j][i]; | |
return res; | |
} | |
mat4 mat4_mul(const mat4 *l, const mat4 *r) | |
{ | |
/* rows act as columns */ | |
mat4 res; | |
int i; | |
for (i = 0; i < 4; ++i) | |
res.rows[i] = mat4_vecmul(l, mat4_col(r, i)); | |
return mat4_transpose(&res); | |
} | |
vec4 mat4_vecmul(const mat4 *l, vec4 r) | |
{ | |
vec4 res; | |
res.x = vec4_dot(l->rows[0], r); | |
res.y = vec4_dot(l->rows[1], r); | |
res.z = vec4_dot(l->rows[2], r); | |
res.w = vec4_dot(l->rows[3], r); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment