diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
| commit | 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch) | |
| tree | 428986b49c32e21d3f7a3c2dfa41858ae0153209 /07-july/src/math/math_util.c | |
Initial commit
Diffstat (limited to '07-july/src/math/math_util.c')
| -rw-r--r-- | 07-july/src/math/math_util.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/07-july/src/math/math_util.c b/07-july/src/math/math_util.c new file mode 100644 index 0000000..f58e447 --- /dev/null +++ b/07-july/src/math/math_util.c @@ -0,0 +1,10 @@ +#include "math_util.h" + +float baryCentric(vec3_t *p1, vec3_t *p2, vec3_t *p3, vec2_t *pos) +{ + float det = (p2->z - p3->z) * (p1->x - p3->x) + (p3->x - p2->x) * (p1->z - p3->z); + float l1 = ((p2->z - p3->z) * (pos->x - p3->x) + (p3->x - p2->x) * (pos->y - p3->z)) / det; + float l2 = ((p3->z - p1->z) * (pos->x - p3->x) + (p1->x - p3->x) * (pos->y - p3->z)) / det; + float l3 = 1.0f - l1 - l2; + return l1 * p1->y + l2 * p2->y + l3 * p3->y; +} |
