Fix issue in function to compute triangle barycentric coordinates

This commit is contained in:
Daniel Chappuis 2016-04-02 02:50:32 +02:00
parent bffbd66c54
commit fcadbed56f
2 changed files with 14 additions and 10 deletions

View File

@ -47,7 +47,7 @@ void reactphysics3d::computeBarycentricCoordinatesInTriangle(const Vector3& a, c
decimal denom = d00 * d11 - d01 * d01;
v = (d11 * d20 - d01 * d21) / denom;
w = (d00 * d21 - d01 * d20) / denom;
u = decimal(1.0) - u - w;
u = decimal(1.0) - v - w;
}
// Clamp a vector such that it is no longer than a given maximum length

View File

@ -107,19 +107,23 @@ class TestMathematicsFunctions : public Test {
Vector3 a(0, 0, 0);
Vector3 b(5, 0, 0);
Vector3 c(0, 0, 5);
Vector3 testPoint(4, 0, 1);
decimal u,v,w;
computeBarycentricCoordinatesInTriangle(a, b, c, a, u, v, w);
test(approxEqual(u, 1.0, 0.0001));
test(approxEqual(v, 0.0, 0.0001));
test(approxEqual(w, 0.0, 0.0001));
test(approxEqual(u, 1.0, 0.000001));
test(approxEqual(v, 0.0, 0.000001));
test(approxEqual(w, 0.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, b, u, v, w);
test(approxEqual(u, 0.0, 0.0001));
test(approxEqual(v, 1.0, 0.0001));
test(approxEqual(w, 0.0, 0.0001));
test(approxEqual(u, 0.0, 0.000001));
test(approxEqual(v, 1.0, 0.000001));
test(approxEqual(w, 0.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, c, u, v, w);
test(approxEqual(u, 0.0, 0.0001));
test(approxEqual(v, 0.0, 0.0001));
test(approxEqual(w, 1.0, 0.0001));
test(approxEqual(u, 0.0, 0.000001));
test(approxEqual(v, 0.0, 0.000001));
test(approxEqual(w, 1.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, testPoint, u, v, w);
test(approxEqual(u + v + w, 1.0, 0.000001));
}
};