diff options
Diffstat (limited to '08-august/src/math/math_util.c')
| -rw-r--r-- | 08-august/src/math/math_util.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/08-august/src/math/math_util.c b/08-august/src/math/math_util.c new file mode 100644 index 0000000..f58e447 --- /dev/null +++ b/08-august/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; +} |
