NzNoise new architecture + Perlin 1D algorithm modified
This commit is contained in:
30
include/Nazara/Noise/NoiseBase.hpp
Normal file
30
include/Nazara/Noise/NoiseBase.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NOISEBASE_H
|
||||
#define NOISEBASE_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
class NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzNoiseBase(int seed = 0);
|
||||
virtual ~NzNoiseBase();
|
||||
|
||||
void SetNewSeed(int seed);
|
||||
int GetUniformRandomValue();
|
||||
void ShufflePermutationTable();
|
||||
protected:
|
||||
int perm[512];
|
||||
private:
|
||||
int Ua, Uc, Um;
|
||||
int UcurrentSeed;
|
||||
int Uprevious, Ulast;
|
||||
|
||||
};
|
||||
|
||||
#endif // NOISEBASE_H
|
||||
@@ -8,22 +8,22 @@
|
||||
#define NOISEMACHINE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
//#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include "NoiseBase.hpp"
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
//TODO : tableau de gradients en float au lieu de int ? Ou alors condition ternaires ?
|
||||
//TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ?
|
||||
// utiliser fastfloor partout
|
||||
// vérifier bon fonctionnement perlin1d
|
||||
|
||||
class NzNoiseMachine
|
||||
class NzNoiseMachine : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzNoiseMachine(int seed = 0);
|
||||
~NzNoiseMachine();
|
||||
|
||||
void SetNewSeed(int seed);
|
||||
int GetUniformRandomValue();
|
||||
void ShufflePermutationTable();
|
||||
|
||||
float Get1DPerlinNoiseValue (float x, float res);
|
||||
float Get2DPerlinNoiseValue (float x, float y, float res);
|
||||
float Get3DPerlinNoiseValue (float x, float y, float z, float res);
|
||||
@@ -55,20 +55,12 @@ class NzNoiseMachine
|
||||
//Pour tronquer les nombres
|
||||
int fastfloor(float n);
|
||||
|
||||
float pi;
|
||||
int perm[512];
|
||||
int PermutationTemp[256];
|
||||
int gradient1[2];
|
||||
float gradient2[8][2];
|
||||
int gradient3[16][3];
|
||||
int gradient4[32][4];
|
||||
int lookupTable4D[64][4];
|
||||
|
||||
//multiplicative congruential generator
|
||||
int UcurrentSeed;
|
||||
int Ua,Uc,Um;
|
||||
int Uprevious;
|
||||
int Ulast;
|
||||
|
||||
//----------------------- Simplex variables --------------------------------------
|
||||
|
||||
float n1, n2, n3, n4, n5;
|
||||
|
||||
38
include/Nazara/Noise/Perlin1D.hpp
Normal file
38
include/Nazara/Noise/Perlin1D.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN1D_H
|
||||
#define PERLIN1D_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
//#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include "NoiseBase.hpp"
|
||||
|
||||
template <typename T> class NzPerlin1D : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzPerlin1D();
|
||||
T GetValue(T x, T res);
|
||||
~NzPerlin1D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0;
|
||||
int gi0,gi1;
|
||||
int ii;
|
||||
int gradient1[16];
|
||||
T s,t;
|
||||
T Cx;
|
||||
T nx;
|
||||
T tmp;
|
||||
};
|
||||
|
||||
typedef NzPerlin1D<float> NzPerlin1Df;
|
||||
typedef NzPerlin1D<double> NzPerlin1Dd;
|
||||
|
||||
//#include <Nazara/Noise/Perlin1D.inl>
|
||||
#include "Perlin1D.inl"
|
||||
|
||||
#endif // PERLIN1D_H
|
||||
37
include/Nazara/Noise/Perlin1D.inl
Normal file
37
include/Nazara/Noise/Perlin1D.inl
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
//#include <Nazara/Noise/Error.hpp>
|
||||
//#include <Nazara/Noise/Config.hpp>
|
||||
//#include <Nazara/Noise/Debug.hpp>
|
||||
#include <iostream>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin1D<T>::NzPerlin1D()
|
||||
{
|
||||
gradient1[0] = 1;
|
||||
gradient1[1] = -1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin1D<T>::GetValue(T x, T res)
|
||||
{
|
||||
nx = x/res;
|
||||
x0 = static_cast<int>(nx);
|
||||
ii = x0 & 255;
|
||||
|
||||
gi0 = perm[ii] % 2;
|
||||
gi1 = perm[ii + 1] % 2;
|
||||
|
||||
tmp = nx-x0;
|
||||
s = gradient1[gi0]*tmp;
|
||||
|
||||
tmp = nx-(x0+1);
|
||||
t = gradient1[gi1]*tmp;
|
||||
|
||||
tmp = nx-x0;
|
||||
Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
return s + Cx*(t-s);
|
||||
}
|
||||
Reference in New Issue
Block a user