X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=vec.h;fp=vec.h;h=48635238202c5de1a437161028112bf1085352c1;hp=614e31dfec4c0e68bdbcb5b08ae0be7399ef4ef7;hb=34efcdbb29b75754fef5066c5999671bc2d2fb12;hpb=aca1bceb5ab7dd87e910f0b8c5dba784ab6e8290 diff --git a/vec.h b/vec.h index 614e31d..4863523 100644 --- a/vec.h +++ b/vec.h @@ -57,10 +57,11 @@ vec_t vec_new(scal_t x, scal_t y, scal_t z) return vec_new2(x, y, z, S(1.0)); } -#define VEC_ZERO vec_new(S(0.0), S(0.0), S(0.0)) -#define VEC_ORTHO_X vec_new(S(1.0), S(0.0), S(0.0)) -#define VEC_ORTHO_Y vec_new(S(0.0), S(1.0), S(0.0)) -#define VEC_ORTHO_Z vec_new(S(0.0), S(0.0), S(1.0)) +#define VEC_ZERO vec_new(S(0.0), S(0.0), S(0.0)) +#define VEC_ORTHO_X vec_new(S(1.0), S(0.0), S(0.0)) +#define VEC_ORTHO_Y vec_new(S(0.0), S(1.0), S(0.0)) +#define VEC_ORTHO_Z vec_new(S(0.0), S(0.0), S(1.0)) +#define VEC_ZERO_FREE vec_new2(S(0.0), S(0.0), S(0.0), S(0.0)) /* @@ -155,6 +156,15 @@ vec_t vec_add(vec_t a, vec_t b) return a; } +/* + * Add three vectors together. + */ +INLINE_MAYBE +vec_t vec_add2(vec_t a, vec_t b, vec_t c) +{ + return vec_add(vec_add(a, b), c); +} + /* * Subtract a vector from another vector. */ @@ -239,5 +249,18 @@ vec_t vec_homodiv(vec_t v) } +/* + * Interpolate smoothly between three vectors with barycentric coordinates. + */ +INLINE_MAYBE +vec_t vec_interp(vec_t v1, vec_t v2, vec_t v3, scal_t b[3]) +{ + return vec_new(v1.x * b[0] + v2.x * b[1] + v3.x * b[2], + v1.y * b[0] + v2.y * b[1] + v3.y * b[2], + v1.z * b[0] + v2.z * b[1] + v3.z * b[2]); +} + + + #endif // _VEC_H_