X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fvmath.h;h=3cdbedf7fc4353ccf494b2a456d508ec2304975a;hp=d8c6be231ff452f0636b43970453ad5142c5a3e6;hb=45f6f46fe758d15aafccdb69ae837fc7d84ee466;hpb=6c5e65928b425dd6a7f5192841e1d4ef9d90789a diff --git a/src/vmath.h b/src/vmath.h index d8c6be2..3cdbedf 100644 --- a/src/vmath.h +++ b/src/vmath.h @@ -1,6 +1,8 @@ #ifndef VMATH_H_ #define VMATH_H_ +#include + #ifdef __GNUC__ #define INLINE __inline @@ -11,6 +13,7 @@ #define INLINE #endif +typedef struct { float x, y; } vec2_t; typedef struct { float x, y, z; } vec3_t; typedef struct { float x, y, z, w; } vec4_t; @@ -26,11 +29,38 @@ static INLINE vec3_t v3_cons(float x, float y, float z) return res; } +static INLINE void v3_negate(vec3_t *v) +{ + v->x = -v->x; + v->y = -v->y; + v->z = -v->z; +} + static INLINE float v3_dot(vec3_t v1, vec3_t v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } +static INLINE vec3_t v3_cross(vec3_t v1, vec3_t v2) +{ + vec3_t res; + res.x = v1.y * v2.z - v1.z * v2.y; + res.y = v1.z * v2.x - v1.x * v2.z; + res.z = v1.x * v2.y - v1.y * v2.x; + return res; +} + +static INLINE void v3_normalize(vec3_t *v) +{ + float mag = sqrt(v->x * v->x + v->y * v->y + v->z * v->z); + if(mag != 0.0f) { + float s = 1.0f / mag; + v->x *= s; + v->y *= s; + v->z *= s; + } +} + /* quaternion functions */ static INLINE quat_t quat_cons(float s, float x, float y, float z) { @@ -96,4 +126,19 @@ static INLINE quat_t quat_rotate(quat_t q, float angle, float x, float y, float return quat_mul(q, rq); } +static INLINE void mat4_transpose(float *mat) +{ + int i, j; + + for(i=0; i<4; i++) { + for(j=0; j