diff --git a/perlin/perlin_noise.cpp b/perlin/perlin_noise.cpp index 1cc9c6c..c093d6a 100644 --- a/perlin/perlin_noise.cpp +++ b/perlin/perlin_noise.cpp @@ -30,26 +30,21 @@ //------------------------- double SimpleRNG::operator()(double x) { - x = x * seed * 345589144.0 + 1123581321.0; - return fmod(x, 21795.0); + return (x + seed) * 345589144.0 + 1123581321.0; }; Vector2 PerlinNoise::Gradient(Vector2 pos) { //could cache this result - double j = rng(pos.y*pos.y + pos.x * 144); - double i = rng(pos.x*pos.x + pos.y * 144); - Vector2 v(i, j); + double angle = rng(pos.x * pos.y + pos.y); + Vector2 v(cos(angle), sin(angle)); v.Normalize(); return v; } -double PerlinNoise::Influcence(Vector2 gridPoint, Vector2 queryPoint) { - return ScalarProduct(Gradient(gridPoint), queryPoint - gridPoint); -} - double PerlinNoise::Noise(double x, double y, double width, double height) { - Vector2 point = {x, y}; + Vector2 queryPoint = {x, y}; + //calc the region's position x = Snap(x, width); y = Snap(y, height); @@ -60,10 +55,10 @@ double PerlinNoise::Noise(double x, double y, double width, double height) { Vector2 br = {x + width, y + height}; //influence equasion - double s = Influcence(tl, point); - double t = Influcence(tr, point); - double u = Influcence(bl, point); - double v = Influcence(br, point); + double s = ScalarProduct(Gradient(tl), queryPoint - tl); + double t = ScalarProduct(Gradient(tr), queryPoint - tr); + double u = ScalarProduct(Gradient(bl), queryPoint - bl); + double v = ScalarProduct(Gradient(br), queryPoint - br); //get the noise double a = s + Curve((t - s) / width); diff --git a/src/shell_scene.cpp b/src/shell_scene.cpp index fa8ad81..82a92c9 100644 --- a/src/shell_scene.cpp +++ b/src/shell_scene.cpp @@ -21,6 +21,8 @@ */ #include "shell_scene.hpp" +#include + //------------------------- //Public access members //------------------------- @@ -31,19 +33,21 @@ void setPixel(SDL_Surface* const dest, int x, int y, int colour) { ShellScene::ShellScene() { //test the generator - int width = 800; - int height = 600; - image.CreateSurface(width, height); - - int white = SDL_MapRGB(image.GetSurface()->format, 255, 255, 255); + int width = 80; + int height = 80; + image.CreateSurface(GetScreen()->w, GetScreen()->h); double mod; - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { + int colour; + std::cout << "Beggining generation" << std::endl; + for (int i = 0; i < image.GetSurface()->w; i++) { + for (int j = 0; j < image.GetSurface()->h; j++) { mod = generator.Noise(i, j, width, height); - setPixel(image.GetSurface(), i, j, white*mod); + colour = SDL_MapRGB(image.GetSurface()->format, 255*mod, 255*mod, 255*mod); + setPixel(image.GetSurface(), i, j, colour); } } + std::cout << "Finished generation" << std::endl; } ShellScene::~ShellScene() {