diff --git a/include/light/light2.hh b/include/light/light2.hh index bd5bc36e..6641727d 100644 --- a/include/light/light2.hh +++ b/include/light/light2.hh @@ -45,9 +45,6 @@ #include #include -std::pair RotationAboutLineSegment(glm::vec3 p0, glm::vec3 p1, - glm::vec3 face0Norm, glm::vec3 face1Norm); - glm::mat4x4 WorldToTexSpace(const bsp2_t *bsp, const bsp2_dface_t *f); glm::mat4x4 TexSpaceToWorld(const bsp2_t *bsp, const bsp2_dface_t *f); diff --git a/light/light2.cc b/light/light2.cc index 2ac2514b..2b8d4a97 100644 --- a/light/light2.cc +++ b/light/light2.cc @@ -76,21 +76,6 @@ glm::mat4x4 WorldToTexSpace(const bsp2_t *bsp, const bsp2_dface_t *f) return T; } -// Rotates face1Norm about the line segment p0 <-> p1 so it is aligned with face0Norm -pair RotationAboutLineSegment(glm::vec3 p0, glm::vec3 p1, - glm::vec3 face0Norm, glm::vec3 face1Norm) -{ - // Get rotation angle. Quaternion rotates face1Norm to face0Norm - const glm::quat rotationQuat = glm::rotation(face1Norm, face0Norm); - - // Any point on the line p0-p1 will work, so just use p0 - const glm::mat4x4 toOrigin = glm::translate(-p0); - const glm::mat4x4 fromOrigin = glm::translate(p0); - - const glm::mat4x4 composed = fromOrigin * glm::toMat4(rotationQuat) * toOrigin; - return make_pair(true, composed); -} - glm::mat4x4 TexSpaceToWorld(const bsp2_t *bsp, const bsp2_dface_t *f) { const glm::mat4x4 T = WorldToTexSpace(bsp, f); diff --git a/light/test_light.cc b/light/test_light.cc index ba96e1c3..121516bd 100644 --- a/light/test_light.cc +++ b/light/test_light.cc @@ -15,114 +15,6 @@ static glm::vec4 extendTo4(const glm::vec3 &v) { return glm::vec4(v[0], v[1], v[2], 1.0); } -TEST(light, RotationAboutLineSegment) { - using namespace glm; - - const vec3 up = vec3(0,0,1); - const vec3 right = vec3(1,0,0); - - const vec3 p0 = vec3(64,64,0); - const vec3 p1 = vec3(64,-64,0); - - // +z - // - // -x ____p0 +x - // | ^ rotation - // | __/ - // | - // - // -z - - // Rotates the face "right" about the p0-p1 edge - const auto res = RotationAboutLineSegment(p0, p1, up, right); - ASSERT_TRUE(res.first); - - // Test the endpoints of the line segment don't move when rotated - ASSERT_EQ(vec4(64, 64, 0, 1), res.second * vec4(64, 64, 0, 1)); - ASSERT_EQ(vec4(64, -64, 0, 1), res.second * vec4(64, -64, 0, 1)); - - // This point moves - ASSERT_EQ(vec4(65, 0, 0, 1), res.second * vec4(64, 0, -1, 1)); -} - -TEST(light, RotationAboutLineSegment2) { - using namespace glm; - - const vec3 up = vec3(0,0,1); - const vec3 dnleft = glm::normalize(vec3(-1,0,-1)); - - const vec3 p0 = vec3(64,64,0); - const vec3 p1 = vec3(64,-64,0); - - // +z - // - // \ ___ - // \ / \ - // \ | - // -x ____p0 V rotation +x - // | - // | - // | - // - // -z - - // Rotates the face "dnleft" about the p0-p1 edge - const auto res = RotationAboutLineSegment(p0, p1, up, dnleft); - ASSERT_TRUE(res.first); - - // Test the endpoints of the line segment don't move when rotated - ASSERT_EQ(vec4(64, 64, 0, 1), res.second * vec4(64, 64, 0, 1)); - ASSERT_EQ(vec4(64, -64, 0, 1), res.second * vec4(64, -64, 0, 1)); - - // This point moves - const vec4 actual = res.second * vec4(0, 0, 64, 1); - EXPECT_FLOAT_EQ(64 + (64 * sqrt(2)), actual[0]); - EXPECT_FLOAT_EQ(0, actual[1]); - EXPECT_TRUE(fabs(actual[2]) < 0.001); - EXPECT_FLOAT_EQ(1, actual[3]); -} - -TEST(light, RotationAboutLineSegment3) { - using namespace glm; - - const vec3 up = vec3(0,0,1); - const vec3 plusYminusX = glm::normalize(vec3(-1,+1,0)); - - const vec3 p0 = vec3(0,-64,0); - const vec3 p1 = vec3(128,64,0); - const vec3 p2_folded = vec3(64, 0, 0.5f*length(p1 - p0)); - const vec3 p2_unfolded = vec3(128,-64,0); - - // after unfolding: - // - // +y - // ------ p1 - // | /| - // -x | / | +x - // | /Q | - // |/___| - // p0 p2 (test point) - // -y - // - // before unfolding: - // - the Q face is pointing upwards (normal is `plusYminusX`) - // - p2 is half way between p0 and p1, and raised up along the Z axis - - // Rotates the face "plusYminusX" about the p0-p1 edge - const auto res = RotationAboutLineSegment(p0, p1, up, plusYminusX); - ASSERT_TRUE(res.first); - - // Test the endpoints of the line segment don't move when rotated - ASSERT_EQ(extendTo4(p0), res.second * extendTo4(p0)); - ASSERT_EQ(extendTo4(p1), res.second * extendTo4(p1)); - - // This point moves - const vec4 p2_unfolded_actual = res.second * extendTo4(p2_folded); - for (int i=0; i<4; i++) { - EXPECT_LT(fabs(extendTo4(p2_unfolded)[i] - p2_unfolded_actual[i]), 0.001f); - } -} - TEST(mathlib, MakeCDF) { std::vector pdfUnnormzlied { 25, 50, 25 }; @@ -265,50 +157,6 @@ TEST(mathlib, PointInPolygon_ColinearPointHandling) { checkBox(edges, poly); } -TEST(mathlib, RotTest4) { - const vector contrib { - vec3(-1943.306030, -567.731140, 140.192612), - vec3(-1979.382324, -596.117676, 48.000000), - vec3(-1968.000000, -672.000000, 48.000000), - vec3(-1918.430298, -672.000000, 161.302124) - }; - const auto contribEdges = GLM_MakeInwardFacingEdgePlanes(contrib); - const auto contribNormal = GLM_FaceNormal(contrib); - - const vector ref { - vec3(-1856.000000, -543.676758, 149.279465), - vec3(-1888.000000, -549.721191, 145.486862), - vec3(-1943.306030, -567.731140, 140.192612), - vec3(-1918.430298, -672.000000, 161.302124), - vec3(-1910.796021, -704.000000, 167.780609), - vec3(-1856.000000, -704.000000, 176.000000) - }; - const auto refEdges = GLM_MakeInwardFacingEdgePlanes(ref); - const auto refNormal = GLM_FaceNormal(ref); - - const vec3 contribPoint(-1942.951660, -575.428223, 138.363464); - - EXPECT_TRUE(GLM_EdgePlanes_PointInside(contribEdges, contribPoint)); - EXPECT_FALSE(GLM_EdgePlanes_PointInside(refEdges, contribPoint)); - - - const auto res = RotationAboutLineSegment(contrib.at(3), contrib.at(0), refNormal, contribNormal); - ASSERT_TRUE(res.first); - - const vec3 rotated = vec3(res.second * extendTo4(contribPoint)); - - cout << to_string(rotated) << endl; - - EXPECT_FALSE(GLM_EdgePlanes_PointInside(refEdges, rotated)); - - /* - dist inside 9.36064 - - rotated pos vec4(-1925.450439, -571.562317, 143.509521, 1.000000) - */ - -} - TEST(mathlib, ClosestPointOnPolyBoundary) { // clockwise const vector poly {