blob: 1285f3d7f2d41678adc19096cdec5321317a84e0 (
plain)
1
2
3
4
5
6
7
8
9
10
|
#include "math_util.h"
float baryCentric(Vec3 *p1, Vec3 *p2, Vec3 *p3, Vec2 *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;
}
|