diff --git a/libs/pcg/include/psemek/pcg/perlin.hpp b/libs/pcg/include/psemek/pcg/perlin.hpp index 083ae4d0..c38f7b76 100644 --- a/libs/pcg/include/psemek/pcg/perlin.hpp +++ b/libs/pcg/include/psemek/pcg/perlin.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace psemek::pcg { @@ -10,6 +11,7 @@ namespace psemek::pcg { perlin() = default; perlin(gfx::basic_pixmap> grad_map); + perlin(gfx::basic_pixmap> const & grad_map, seamless_tag); perlin(perlin &&) = default; perlin & operator = (perlin &&) = default; diff --git a/libs/pcg/include/psemek/pcg/seamless.hpp b/libs/pcg/include/psemek/pcg/seamless.hpp new file mode 100644 index 00000000..bf44a5de --- /dev/null +++ b/libs/pcg/include/psemek/pcg/seamless.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace psemek::pcg +{ + + struct seamless_tag{}; + + constexpr seamless_tag seamless; + +} diff --git a/libs/pcg/source/perlin.cpp b/libs/pcg/source/perlin.cpp index 9d3c87be..4ebcd909 100644 --- a/libs/pcg/source/perlin.cpp +++ b/libs/pcg/source/perlin.cpp @@ -11,6 +11,22 @@ namespace psemek::pcg : grad_map_(std::move(grad_map)) {} + perlin::perlin(gfx::basic_pixmap> const & grad_map, seamless_tag) + { + auto const w = grad_map.width(); + auto const h = grad_map.height(); + + grad_map_.resize({w + 1, h + 1}); + + for (std::size_t j = 0; j <= h; ++j) + { + for (std::size_t i = 0; i <= w; ++i) + { + grad_map_(i, j) = grad_map(i % w, j % h); + } + } + } + static float step(float x0, float x1, float t) { return x0 * (1.f - t) + x1 * t;