mathlib: GLM_InterpolateNormal: quick hack to fix build of testlight

This commit is contained in:
Eric Wasylishen 2021-10-08 19:31:06 -06:00
parent 100d364edf
commit 76d0dae890
3 changed files with 17 additions and 4 deletions

View File

@ -599,6 +599,17 @@ std::pair<int, qvec3f> GLM_ClosestPointOnPolyBoundary(const std::vector<qvec3f>
std::pair<bool, qvec3f> GLM_InterpolateNormal(
const std::vector<qvec3f> &points, const std::vector<face_normal_t> &normals, const qvec3f &point)
{
std::vector<qvec3f> normalvecs;
for (auto& normal : normals) {
normalvecs.push_back(normal.normal);
}
return GLM_InterpolateNormal(points, normalvecs, point);
}
std::pair<bool, qvec3f> GLM_InterpolateNormal(
const std::vector<qvec3f> &points, const std::vector<qvec3f> &normals, const qvec3f &point)
{
Q_assert(points.size() == normals.size());
@ -608,14 +619,14 @@ std::pair<bool, qvec3f> GLM_InterpolateNormal(
// Step through the triangles, being careful to handle zero-size ones
const qvec3f &p0 = points.at(0);
const qvec3f &n0 = normals.at(0).normal;
const qvec3f &n0 = normals.at(0);
const int N = points.size();
for (int i = 2; i < N; i++) {
const qvec3f &p1 = points.at(i - 1);
const qvec3f &n1 = normals.at(i - 1).normal;
const qvec3f &n1 = normals.at(i - 1);
const qvec3f &p2 = points.at(i);
const qvec3f &n2 = normals.at(i).normal;
const qvec3f &n2 = normals.at(i);
const auto edgeplanes = GLM_MakeInwardFacingEdgePlanes({p0, p1, p2});
if (edgeplanes.size() != 3)

View File

@ -304,6 +304,8 @@ std::pair<int, qvec3f> GLM_ClosestPointOnPolyBoundary(const std::vector<qvec3f>
/// Returns `true` and the interpolated normal if `point` is in the polygon, otherwise returns false.
std::pair<bool, qvec3f> GLM_InterpolateNormal(
const std::vector<qvec3f> &points, const std::vector<face_normal_t> &normals, const qvec3f &point);
std::pair<bool, qvec3f> GLM_InterpolateNormal(
const std::vector<qvec3f> &points, const std::vector<qvec3f> &normals, const qvec3f &point);
std::vector<qvec3f> GLM_ShrinkPoly(const std::vector<qvec3f> &poly, const float amount);
/// Returns (front part, back part)
std::pair<std::vector<qvec3f>, std::vector<qvec3f>> GLM_ClipPoly(const std::vector<qvec3f> &poly, const qvec4f &plane);

View File

@ -282,7 +282,7 @@ TEST(mathlib, DistAbovePlane)
TEST(mathlib, InterpolateNormalsDegenerate)
{
EXPECT_FALSE(GLM_InterpolateNormal({}, {}, qvec3f(0, 0, 0)).first);
EXPECT_FALSE(GLM_InterpolateNormal({}, std::vector<qvec3f>{}, qvec3f(0, 0, 0)).first);
EXPECT_FALSE(GLM_InterpolateNormal({qvec3f(0, 0, 0)}, {qvec3f(0, 0, 1)}, qvec3f(0, 0, 0)).first);
EXPECT_FALSE(
GLM_InterpolateNormal({qvec3f(0, 0, 0), qvec3f(10, 0, 0)}, {qvec3f(0, 0, 1), qvec3f(0, 0, 1)}, qvec3f(0, 0, 0))