X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=vec.h;h=15de4845c5f87843f4c8a37390d33e385b4b0ae8;hb=bc662e293c854e1bdc9d46e9a410fe220247e6d4;hp=48635238202c5de1a437161028112bf1085352c1;hpb=34efcdbb29b75754fef5066c5999671bc2d2fb12;p=chaz%2Frasterize diff --git a/vec.h b/vec.h index 4863523..15de484 100644 --- a/vec.h +++ b/vec.h @@ -64,6 +64,16 @@ vec_t vec_new(scal_t x, scal_t y, scal_t z) #define VEC_ZERO_FREE vec_new2(S(0.0), S(0.0), S(0.0), S(0.0)) +/* + * Get a pointer to the vector data. + */ +INLINE_MAYBE +const scal_t* vec_data(const vec_t* v) +{ + return &v->x; +} + + /* * Print the vector to stdout. */ @@ -260,6 +270,24 @@ vec_t vec_interp(vec_t v1, vec_t v2, vec_t v3, scal_t b[3]) v1.z * b[0] + v2.z * b[1] + v3.z * b[2]); } +/* + * Interpolate smoothly between three texture coordinates with barycentric + * coordinates and perspective correction. + */ +INLINE_MAYBE +vec_t vec_tinterp(vec_t v1, vec_t v2, vec_t v3, scal_t b[3]) +{ + scal_t denom = (S(1.0) / v1.w) * b[0] + + (S(1.0) / v2.w) * b[1] + + (S(1.0) / v3.w) * b[2]; + return vec_new(scal_clamp(((v1.x / v1.w) * b[0] + + (v2.x / v2.w) * b[1] + + (v3.x / v3.w) * b[2]) / denom, S(0.0), S(1.0)), + scal_clamp(((v1.y / v1.w) * b[0] + + (v2.y / v2.w) * b[1] + + (v3.y / v3.w) * b[2]) / denom, S(0.0), S(1.0)), + S(0.0)); +} #endif // _VEC_H_