Noise: Refresh module using ZNoise

https://github.com/Overdrivr/ZNoise

Former-commit-id: ea7bbeb58a7147934523e2f600b1bd02f1cae5ed [formerly 581ab53941abbda68e00417592240f52ebd482e6]
Former-commit-id: e948aca78eb101292f0458365cfa39e6564d0462
This commit is contained in:
Jérôme Leclercq
2016-06-18 07:52:33 +02:00
parent a66db53057
commit 33f2241d95
56 changed files with 1408 additions and 2017 deletions

View File

@@ -1,43 +1,37 @@
// Copyright (C) 2015 Rémi Bèges
// Copyright (C) 2016 Rémi Bèges
// This file is part of the "Nazara Engine - Noise module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Noise/NoiseBase.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp>
namespace Nz
{
NoiseBase::NoiseBase(unsigned int seed)
{
Ua = 16807;
Uc = 0;
Um = 2147483647;
UcurrentSeed = 0;
Uprevious = 0;
SetSeed(seed);
m_scale = 0.05f;
SetNewSeed(seed);
for(int i(0) ; i < 512 ; i++)
for(unsigned int i(0) ; i < 512; ++i)
perm[i] = i & 255;
}
void NoiseBase::SetNewSeed(unsigned int seed)
float NoiseBase::GetScale()
{
Uprevious = seed;
UcurrentSeed = seed;
return m_scale;
}
unsigned int NoiseBase::GetUniformRandomValue()
void NoiseBase::SetScale(float scale)
{
Ulast = Ua*Uprevious + Uc%Um;
Uprevious = Ulast;
return Ulast;
m_scale = scale;
}
void NoiseBase::ShufflePermutationTable()
void NoiseBase::SetSeed(unsigned int seed)
{
generator.seed(seed);
}
void NoiseBase::Shuffle()
{
int xchanger;
unsigned int ncase;
@@ -45,35 +39,21 @@ namespace Nz
for(unsigned int i(0) ; i < 256 ; i++)
perm[i] = i;
for(unsigned int j(0) ; j < 20 ; ++j)
for (unsigned int i(0); i < 256 ; ++i)
{
ncase = this->GetUniformRandomValue() & 255;
xchanger = perm[i];
perm[i] = perm[ncase];
perm[ncase] = xchanger;
}
for (unsigned int i(0); i < 256 ; ++i)
{
ncase = generator() & 255;
xchanger = perm[i];
perm[i] = perm[ncase];
perm[ncase] = xchanger;
}
for(unsigned int i(256) ; i < 512; ++i)
perm[i] = perm[i & 255];
}
int NoiseBase::fastfloor(float n)
void NoiseBase::Shuffle(unsigned int amount)
{
return (n >= 0) ? static_cast<int>(n) : static_cast<int>(n-1);
}
int NoiseBase::JenkinsHash(int a, int b, int c)
{
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 13);
b = b-c; b = b - a; b = b^(a << 8);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 13);
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 12);
b = b-c; b = b - a; b = b^(a << 16);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 5);
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 3);
b = b-c; b = b - a; b = b^(a << 10);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 15);
return c;
for(unsigned int j(0) ; j < amount ; ++j)
Shuffle();
}
}