X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fvmath.h;fp=src%2Fvmath.h;h=6d1add9a1d89b850b93f60e9e29fe84254b7f1c6;hp=7e35cc80a4f88e41ad0466dbc30c938e59cd3d39;hb=b546d1a5227ee3a263447e279434842d230f700a;hpb=9239019c0f966fc604f9283b62ceef35cc808962 diff --git a/src/vmath.h b/src/vmath.h index 7e35cc8..6d1add9 100644 --- a/src/vmath.h +++ b/src/vmath.h @@ -29,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) {