diff --git a/common/mathlib.cc b/common/mathlib.cc index c56c20fa..a4129e3b 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -599,6 +599,17 @@ std::pair GLM_ClosestPointOnPolyBoundary(const std::vector std::pair GLM_InterpolateNormal( const std::vector &points, const std::vector &normals, const qvec3f &point) +{ + std::vector normalvecs; + for (auto& normal : normals) { + normalvecs.push_back(normal.normal); + } + + return GLM_InterpolateNormal(points, normalvecs, point); +} + +std::pair GLM_InterpolateNormal( + const std::vector &points, const std::vector &normals, const qvec3f &point) { Q_assert(points.size() == normals.size()); @@ -608,14 +619,14 @@ std::pair 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) diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index 21dd3f72..53baa1f6 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -304,6 +304,8 @@ std::pair GLM_ClosestPointOnPolyBoundary(const std::vector /// Returns `true` and the interpolated normal if `point` is in the polygon, otherwise returns false. std::pair GLM_InterpolateNormal( const std::vector &points, const std::vector &normals, const qvec3f &point); +std::pair GLM_InterpolateNormal( + const std::vector &points, const std::vector &normals, const qvec3f &point); std::vector GLM_ShrinkPoly(const std::vector &poly, const float amount); /// Returns (front part, back part) std::pair, std::vector> GLM_ClipPoly(const std::vector &poly, const qvec4f &plane); diff --git a/light/test_light.cc b/light/test_light.cc index c2ceb6e7..2a8de6d0 100644 --- a/light/test_light.cc +++ b/light/test_light.cc @@ -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(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))