From 849f4aa735352704995ffb51bf23dadf795bb119 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 13 Feb 2024 01:36:42 +0000 Subject: Include face handle in intersectRay result --- test/test-geoData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index efe845c..f8437c3 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -114,7 +114,7 @@ BOOST_DATA_TEST_CASE(findRayIntersect, }), p, d, i) { - BOOST_CHECK_EQUAL(fixedTerrtain.intersectRay({p, d}).value(), i); + BOOST_CHECK_EQUAL(fixedTerrtain.intersectRay({p, d})->first, i); } BOOST_AUTO_TEST_CASE(boundaryWalk) -- cgit v1.2.3 From 3770b101cfc5ad37a069850b422f0098ade7fc08 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 22 Feb 2024 01:16:29 +0000 Subject: First cut of terrain deformation This "works" for some definition of works... But it's flawed in many ways, not least the following: * It's glitchy for no obvious reason * It's unreliable; fails if you tweak the parameters * The sides of the modified area are triangulated in the dumbest possible fashion, which results in ill-formed polygons * Probably other things, but... It works, remember... --- test/test-geoData.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index f8437c3..6602b05 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -1,7 +1,12 @@ #define BOOST_TEST_MODULE terrain +#include "game/terrain.h" +#include "test/testMainWindow.h" +#include "test/testRenderOutput.h" #include "testHelpers.h" +#include "ui/applicationBase.h" #include #include +#include #include #include @@ -199,3 +204,58 @@ BOOST_DATA_TEST_CASE(findEntries, { BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh); } + +BOOST_AUTO_TEST_CASE(setTriangle, *boost::unit_test::timeout(5)) +{ + auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100)); + std::array points { + GlobalPosition3D {70100, 123000, 6000}, + GlobalPosition3D {50100, 52300, 6000}, + GlobalPosition3D {191000, 283000, 8000}, + GlobalPosition3D {241000, 123330, -2000}, + }; + BOOST_CHECK_NO_THROW(gd->setHeights(points)); + + ApplicationBase ab; + TestMainWindow tmw; + TestRenderOutput tro {{1792, 1024}}; + + SceneRenderer ss {tro.size, tro.output}; + ss.camera.setView({-90000, -90000, 300000}, glm::normalize(glm::vec3 {1, 1, -1.5F})); + + struct TestTerrain : public SceneProvider { + explicit TestTerrain(std::shared_ptr gd) : terrain(std::move(gd)) { } + + const Terrain terrain; + + void + content(const SceneShader & shader) const override + { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + terrain.render(shader); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + + void + environment(const SceneShader &, const SceneRenderer & sr) const override + { + sr.setAmbientLight({0.1, 0.1, 0.1}); + sr.setDirectionalLight({1, 1, 1}, south + down, *this); + } + + void + lights(const SceneShader &) const override + { + } + + void + shadows(const ShadowMapper & shadowMapper) const override + { + terrain.shadows(shadowMapper); + } + }; + + TestTerrain t {gd}; + BOOST_CHECK_NO_THROW(ss.render(t)); + Texture::save(tro.outImage, "/tmp/geoData.tga"); +} -- cgit v1.2.3 From 848fc7fe1349c36c839b3642f9607ba80ffe4e8e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Feb 2024 01:42:26 +0000 Subject: Make terrain deformation test a data test Easily test multiple deformations and view them from different angles --- test/test-geoData.cpp | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index ac1d668..e1f8fce 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -205,23 +205,41 @@ BOOST_DATA_TEST_CASE(findEntries, BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh); } -BOOST_AUTO_TEST_CASE(setTriangle, *boost::unit_test::timeout(5)) +using DeformTerrainData + = std::tuple, std::vector, const char *>>>; + +template +std::ostream & +operator<<(std::ostream & s, const Ray & ray) +{ + return s << "Ray" << std::make_pair(ray.start, ray.direction); +} + +BOOST_DATA_TEST_CASE(setTriangle, + boost::unit_test::data::make({ + {{ + {70100, 123000, 6000}, + {50100, 52300, 6000}, + {191000, 283000, 8000}, + {241000, 123330, -2000}, + }, + { + {{{20000, 20000, 90000}, glm::normalize(Direction3D {1, 1, -1.5F})}, + "/tmp/geoData0.tga"}, + {{{30000, 164000, 90000}, glm::normalize(Direction3D {1, -1, -1.5F})}, + "/tmp/geoData1.tga"}, + {{{288000, 162000, 90000}, glm::normalize(Direction3D {-1, -1, -1.5F})}, + "/tmp/geoData2.tga"}, + }}, + }), + points, cams) { auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100)); - std::array points { - GlobalPosition3D {70100, 123000, 6000}, - GlobalPosition3D {50100, 52300, 6000}, - GlobalPosition3D {191000, 283000, 8000}, - GlobalPosition3D {241000, 123330, -2000}, - }; BOOST_CHECK_NO_THROW(gd->setHeights(points)); ApplicationBase ab; TestMainWindow tmw; - TestRenderOutput tro {{1792, 1024}}; - - SceneRenderer ss {tro.size, tro.output}; - ss.camera.setView({-90000, -90000, 300000}, glm::normalize(glm::vec3 {1, 1, -1.5F})); + TestRenderOutput tro {{640, 480}}; struct TestTerrain : public SceneProvider { explicit TestTerrain(std::shared_ptr gd) : terrain(std::move(gd)) { } @@ -256,6 +274,10 @@ BOOST_AUTO_TEST_CASE(setTriangle, *boost::unit_test::timeout(5)) }; TestTerrain t {gd}; - BOOST_CHECK_NO_THROW(ss.render(t)); - Texture::save(tro.outImage, "/tmp/geoData.tga"); + SceneRenderer ss {tro.size, tro.output}; + std::for_each(cams.begin(), cams.end(), [&ss, &t, &tro](const auto & cam) { + ss.camera.setView(cam.first.start, cam.first.direction); + BOOST_CHECK_NO_THROW(ss.render(t)); + Texture::save(tro.outImage, cam.second); + }); } -- cgit v1.2.3 From aa07f1bdd607a6dead9cdec59ff950f6e9a5c28c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Feb 2024 23:47:39 +0000 Subject: Load terrain deform fixture data from JSON --- test/test-geoData.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index e1f8fce..36d008b 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -205,34 +205,10 @@ BOOST_DATA_TEST_CASE(findEntries, BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh); } -using DeformTerrainData - = std::tuple, std::vector, const char *>>>; +using DeformTerrainData = std::tuple, + std::vector, std::string>>>; -template -std::ostream & -operator<<(std::ostream & s, const Ray & ray) -{ - return s << "Ray" << std::make_pair(ray.start, ray.direction); -} - -BOOST_DATA_TEST_CASE(setTriangle, - boost::unit_test::data::make({ - {{ - {70100, 123000, 6000}, - {50100, 52300, 6000}, - {191000, 283000, 8000}, - {241000, 123330, -2000}, - }, - { - {{{20000, 20000, 90000}, glm::normalize(Direction3D {1, 1, -1.5F})}, - "/tmp/geoData0.tga"}, - {{{30000, 164000, 90000}, glm::normalize(Direction3D {1, -1, -1.5F})}, - "/tmp/geoData1.tga"}, - {{{288000, 162000, 90000}, glm::normalize(Direction3D {-1, -1, -1.5F})}, - "/tmp/geoData2.tga"}, - }}, - }), - points, cams) +BOOST_DATA_TEST_CASE(deform, loadFixtureJson("geoData/deform/1.json"), points, cams) { auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100)); BOOST_CHECK_NO_THROW(gd->setHeights(points)); @@ -276,8 +252,8 @@ BOOST_DATA_TEST_CASE(setTriangle, TestTerrain t {gd}; SceneRenderer ss {tro.size, tro.output}; std::for_each(cams.begin(), cams.end(), [&ss, &t, &tro](const auto & cam) { - ss.camera.setView(cam.first.start, cam.first.direction); + ss.camera.setView(cam.first.first, glm::normalize(cam.first.second)); BOOST_CHECK_NO_THROW(ss.render(t)); - Texture::save(tro.outImage, cam.second); + Texture::save(tro.outImage, cam.second.c_str()); }); } -- cgit v1.2.3 From 0275b4d1ce7c2ea3dbbe31ebc71db5395722bdc9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 9 Mar 2024 12:05:37 +0000 Subject: Add timeout to deformation unit test --- test/test-geoData.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 36d008b..2d6b1aa 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -208,6 +208,8 @@ BOOST_DATA_TEST_CASE(findEntries, using DeformTerrainData = std::tuple, std::vector, std::string>>>; +BOOST_TEST_DECORATOR(*boost::unit_test::timeout(2)); + BOOST_DATA_TEST_CASE(deform, loadFixtureJson("geoData/deform/1.json"), points, cams) { auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100)); -- cgit v1.2.3 From 2865ce32bc00e6c05c2686215880085b23aecabf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 2 Apr 2024 20:37:23 +0100 Subject: Tests for triangle helpers --- test/test-geoData.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 2d6b1aa..0a2de8d 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -192,6 +192,23 @@ BOOST_DATA_TEST_CASE(walkTerrainUntil, BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end()); } +BOOST_AUTO_TEST_CASE(triangle_helpers) +{ + constexpr static GeoData::Triangle<3> t {{0, 0, 0}, {5, 0, 0}, {5, 5, 0}}; + + BOOST_CHECK_EQUAL(t.nnormal(), up); + BOOST_CHECK_CLOSE(t.angle(0), quarter_pi, 0.01F); + BOOST_CHECK_CLOSE(t.angleAt({0, 0, 0}), quarter_pi, 0.01F); + BOOST_CHECK_CLOSE(t.angle(1), half_pi, 0.01F); + BOOST_CHECK_CLOSE(t.angleAt({5, 0, 0}), half_pi, 0.01F); + BOOST_CHECK_CLOSE(t.angle(2), quarter_pi, 0.01F); + BOOST_CHECK_CLOSE(t.angleAt({5, 5, 0}), quarter_pi, 0.01F); + + BOOST_CHECK_CLOSE(t.angleAt({0, 1, 0}), 0.F, 0.01F); + + BOOST_CHECK_CLOSE(t.area(), 12.5F, 0.01F); +} + using FindEntiesData = std::tuple; BOOST_DATA_TEST_CASE(findEntries, -- cgit v1.2.3 From 1fd3c4baf8b8acf97e343a0cd01455d23f2e9daf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 4 Apr 2024 20:06:27 +0100 Subject: Remove wireframe mode from test renders --- test/test-geoData.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 0a2de8d..fb9aba0 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -244,9 +244,7 @@ BOOST_DATA_TEST_CASE(deform, loadFixtureJson("geoData/deform/ void content(const SceneShader & shader) const override { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); terrain.render(shader); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } void -- cgit v1.2.3