From c3a70d6f7ee78fc7904626516daf001c9fcd359e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 18 Nov 2018 14:00:21 +0100 Subject: [PATCH] Add interpolation helper --- s3l.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/s3l.h b/s3l.h index e22673e..f88b927 100644 --- a/s3l.h +++ b/s3l.h @@ -48,6 +48,25 @@ typedef struct int16_t minorDiff; } S3L_BresenhamState; +/** + Returns a value interpolated between the three triangle vertices based on + barycentric coordinates. +*/ + +static inline S3L_Unit S3L_interpolateBarycentric( + S3L_Unit value0, S3L_Unit value1, S3L_Unit value2, + S3L_Unit barycentric0, S3L_Unit barycentric1, S3L_Unit barycentric2) +{ + return + ( + (value0 * barycentric0) + + (value1 * barycentric1) + + (value2 * barycentric2) + ) / S3L_FRACTIONS_PER_UNIT; +} + +// general helper functions: + static inline int16_t S3L_abs(int16_t value) { return value >= 0 ? value : -1 * value; @@ -68,7 +87,7 @@ static inline S3L_Unit S3L_wrap(S3L_Unit value, S3L_Unit mod) return value >= 0 ? (value % mod) : (mod + (value % mod) - 1); } -static inline S3L_nonZero(S3L_Unit value) +static inline S3L_Unit S3L_nonZero(S3L_Unit value) { return value != 0 ? value : 1; }