Tweaks, trying to get it to work

This commit is contained in:
Kayne Ruse
2014-06-17 06:48:01 +10:00
parent 2b46608d68
commit 1cd198ad66
2 changed files with 21 additions and 22 deletions
+9 -14
View File
@@ -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);
+12 -8
View File
@@ -21,6 +21,8 @@
*/
#include "shell_scene.hpp"
#include <iostream>
//-------------------------
//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() {