glstuff

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 86bd27c721a8a276571dc4396d2262ca710934fb
parent b5ed7965ca22c482dd6833830969a0082fe3cd8e
Author: Brian Swetland <swetland@frotz.net>
Date:   Sun, 20 Jan 2013 09:31:42 -0800

mtx_mul_vec4() for using a mat4 to transform a vec4

Diffstat:
Mutil.c | 12++++++++++++
Mutil.h | 3+++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/util.c b/util.c @@ -46,6 +46,18 @@ void mtx_mul(mat4 m, mat4 a, mat4 b) { memcpy(m, t, sizeof(mat4)); } +void mtx_mul_vec4(vec4 o, mat4 m, vec4 v) { + float a, b, c, d; + a = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0] * v[3]; + b = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1] * v[3]; + c = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2] * v[3]; + d = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3] * v[3]; + o[0] = a; + o[1] = b; + o[2] = c; + o[3] = d; +} + void mtx_identity(mat4 m) { memset(m, 0, sizeof(mat4)); m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0f; diff --git a/util.h b/util.h @@ -18,6 +18,7 @@ typedef float mat4[4][4]; typedef float vec4[4]; +typedef float vec3[3]; /* load the identity matrix */ void mtx_identity(mat4 out); @@ -28,6 +29,8 @@ void mtx_mul(mat4 out, mat4 left, mat4 right); /* avoids a copy, but out and left may not be the same */ void mtx_mul_unsafe(mat4 out, mat4 left, mat4 right); +void mtx_mul_vec4(vec4 out, mat4 left, vec4 right); + /* applies the transform to out */ void mtx_translate(mat4 out, float x, float y, float z); void mtx_rotate_x(mat4 out, float angle);