Tweaks, trying to get it to work
This commit is contained in:
+9
-14
@@ -30,26 +30,21 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
double SimpleRNG::operator()(double x) {
|
double SimpleRNG::operator()(double x) {
|
||||||
x = x * seed * 345589144.0 + 1123581321.0;
|
return (x + seed) * 345589144.0 + 1123581321.0;
|
||||||
return fmod(x, 21795.0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector2 PerlinNoise::Gradient(Vector2 pos) {
|
Vector2 PerlinNoise::Gradient(Vector2 pos) {
|
||||||
//could cache this result
|
//could cache this result
|
||||||
double j = rng(pos.y*pos.y + pos.x * 144);
|
double angle = rng(pos.x * pos.y + pos.y);
|
||||||
double i = rng(pos.x*pos.x + pos.y * 144);
|
Vector2 v(cos(angle), sin(angle));
|
||||||
Vector2 v(i, j);
|
|
||||||
v.Normalize();
|
v.Normalize();
|
||||||
return v;
|
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) {
|
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);
|
x = Snap(x, width);
|
||||||
y = Snap(y, height);
|
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};
|
Vector2 br = {x + width, y + height};
|
||||||
|
|
||||||
//influence equasion
|
//influence equasion
|
||||||
double s = Influcence(tl, point);
|
double s = ScalarProduct(Gradient(tl), queryPoint - tl);
|
||||||
double t = Influcence(tr, point);
|
double t = ScalarProduct(Gradient(tr), queryPoint - tr);
|
||||||
double u = Influcence(bl, point);
|
double u = ScalarProduct(Gradient(bl), queryPoint - bl);
|
||||||
double v = Influcence(br, point);
|
double v = ScalarProduct(Gradient(br), queryPoint - br);
|
||||||
|
|
||||||
//get the noise
|
//get the noise
|
||||||
double a = s + Curve((t - s) / width);
|
double a = s + Curve((t - s) / width);
|
||||||
|
|||||||
+12
-8
@@ -21,6 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "shell_scene.hpp"
|
#include "shell_scene.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -31,19 +33,21 @@ void setPixel(SDL_Surface* const dest, int x, int y, int colour) {
|
|||||||
|
|
||||||
ShellScene::ShellScene() {
|
ShellScene::ShellScene() {
|
||||||
//test the generator
|
//test the generator
|
||||||
int width = 800;
|
int width = 80;
|
||||||
int height = 600;
|
int height = 80;
|
||||||
image.CreateSurface(width, height);
|
image.CreateSurface(GetScreen()->w, GetScreen()->h);
|
||||||
|
|
||||||
int white = SDL_MapRGB(image.GetSurface()->format, 255, 255, 255);
|
|
||||||
|
|
||||||
double mod;
|
double mod;
|
||||||
for (int i = 0; i < width; i++) {
|
int colour;
|
||||||
for (int j = 0; j < height; j++) {
|
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);
|
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() {
|
ShellScene::~ShellScene() {
|
||||||
|
|||||||
Reference in New Issue
Block a user