From ca276ca5471a4e7a137f68a81feb150282eae62f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 7 Feb 2024 23:50:50 +0000 Subject: Add stripiter A generic iterator wrapper returning a tuple of 3 references to the original values, as processed in the fashion of an OpenGL triangle strip. --- test/test-lib.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/test-lib.cpp b/test/test-lib.cpp index 58b769a..5f0b5e5 100644 --- a/test/test-lib.cpp +++ b/test/test-lib.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -49,3 +50,22 @@ BOOST_AUTO_TEST_CASE(generate_move_and_delete) } BOOST_CHECK(active.empty()); } + +constexpr std::array TRIANGLE_STRIP_IN {0, 1, 2, 3, 4, 5}; +static_assert(std::distance(strip_begin(TRIANGLE_STRIP_IN), strip_end(TRIANGLE_STRIP_IN)) == 4); + +BOOST_AUTO_TEST_CASE(triangle_strip_iter) +{ + constexpr std::array TRIANGLE_STRIP_EXPECTED {0, 1, 2, 2, 1, 3, 2, 3, 4, 4, 3, 5}; + + std::vector out; + std::for_each(strip_begin(TRIANGLE_STRIP_IN), strip_end(TRIANGLE_STRIP_IN), [&out](const auto & t) { + const auto [a, b, c] = t; + out.push_back(a); + out.push_back(b); + out.push_back(c); + }); + BOOST_REQUIRE_EQUAL(out.size(), (TRIANGLE_STRIP_IN.size() - 2) * 3); + BOOST_CHECK_EQUAL_COLLECTIONS( + out.begin(), out.end(), TRIANGLE_STRIP_EXPECTED.begin(), TRIANGLE_STRIP_EXPECTED.end()); +} -- cgit v1.2.3 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') 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') 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