Added HybridMultiF 3D & 4D

*new constructors for simple noises
*minor bufixes


Former-commit-id: 2f1e9b6b54087e79b3ac52fefc9bbd67fd45c0eb
This commit is contained in:
Remi Beges 2012-11-13 19:27:48 +01:00
parent 8f04f3e6a0
commit a0b7364eed
18 changed files with 249 additions and 10 deletions

View File

@ -0,0 +1,32 @@
// 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 HYBRIDMULTIFRACTAL3D_HPP
#define HYBRIDMULTIFRACTAL3D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/ComplexNoiseBase.hpp>
#include <Nazara/Noise/Abstract3DNoise.hpp>
class NAZARA_API NzHybridMultiFractal3D : public NzAbstract3DNoise, public NzComplexNoiseBase
{
public:
NzHybridMultiFractal3D(nzNoises source, int seed);
float GetValue(float x, float y, float z, float resolution);
~NzHybridMultiFractal3D();
protected:
private:
NzAbstract3DNoise* m_source;
float m_value;
float m_remainder;
float m_offset;
float m_weight;
float m_signal;
nzNoises m_noiseType;
};
#endif // HYBRIDMULTIFRACTAL3D_HPP

View File

@ -0,0 +1,32 @@
// 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 HYBRIDMULTIFRACTAL4D_HPP
#define HYBRIDMULTIFRACTAL4D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/ComplexNoiseBase.hpp>
#include <Nazara/Noise/Abstract4DNoise.hpp>
class NAZARA_API NzHybridMultiFractal4D : public NzAbstract4DNoise, public NzComplexNoiseBase
{
public:
NzHybridMultiFractal4D(nzNoises source, int seed);
float GetValue(float x, float y, float z, float w, float resolution);
~NzHybridMultiFractal4D();
protected:
private:
NzAbstract4DNoise* m_source;
float m_value;
float m_remainder;
float m_offset;
float m_weight;
float m_signal;
nzNoises m_noiseType;
};
#endif // HYBRIDMULTIFRACTAL4D_HPP

View File

@ -22,6 +22,9 @@ class NAZARA_API NzHybridMultiFractal2D : public NzAbstract2DNoise, public NzCom
NzAbstract2DNoise* m_source;
float m_value;
float m_remainder;
float m_offset;
float m_weight;
float m_signal;
nzNoises m_noiseType;
};

View File

@ -16,6 +16,7 @@ class NAZARA_API NzPerlin2D : public NzAbstract2DNoise
{
public:
NzPerlin2D();
NzPerlin2D(int seed);
float GetValue(float x, float y, float resolution);
~NzPerlin2D() = default;
protected:

View File

@ -16,6 +16,7 @@ class NAZARA_API NzPerlin3D : public NzAbstract3DNoise
{
public:
NzPerlin3D();
NzPerlin3D(int seed);
float GetValue(float x, float y, float z, float resolution);
~NzPerlin3D() = default;
protected:

View File

@ -16,6 +16,7 @@ class NAZARA_API NzPerlin4D : public NzAbstract4DNoise
{
public:
NzPerlin4D();
NzPerlin4D(int seed);
float GetValue(float x, float y, float z, float w, float resolution);
~NzPerlin4D() = default;
protected:

View File

@ -16,6 +16,7 @@ class NAZARA_API NzSimplex2D : public NzAbstract2DNoise
{
public:
NzSimplex2D();
NzSimplex2D(int seed);
float GetValue(float x, float y, float resolution);
virtual ~NzSimplex2D() = default;
protected:

View File

@ -16,6 +16,7 @@ class NAZARA_API NzSimplex3D : public NzAbstract3DNoise
{
public:
NzSimplex3D();
NzSimplex3D(int seed);
float GetValue(float x, float y, float z, float resolution);
~NzSimplex3D() = default;
protected:

View File

@ -16,6 +16,7 @@ class NAZARA_API NzSimplex4D : public NzAbstract4DNoise
{
public:
NzSimplex4D();
NzSimplex4D(int seed);
float GetValue(float x, float y, float z, float w, float resolution);
~NzSimplex4D() = default;
protected:

View File

@ -0,0 +1,65 @@
// 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/Core/Error.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/HybridMultiFractal3D.hpp>
#include <Nazara/Noise/Perlin3D.hpp>
#include <Nazara/Noise/Simplex3D.hpp>
#include <Nazara/Noise/Debug.hpp>
NzHybridMultiFractal3D::NzHybridMultiFractal3D(nzNoises source, int seed)
{
switch(source)
{
case PERLIN:
m_source = new NzPerlin3D();
break;
default:
m_source = new NzSimplex3D();
break;
}
m_source->SetNewSeed(seed);
m_source->ShufflePermutationTable();
m_noiseType = source;
}
float NzHybridMultiFractal3D::GetValue(float x, float y, float z, float resolution)
{
this->RecomputeExponentArray();
m_offset = 1.0f;
m_value = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[0];
m_weight = m_value;
m_signal = 0.f;
resolution *= m_lacunarity;
for(int i(1) ; i < m_octaves; ++i)
{
if(m_weight > 1.0)
m_weight = 1.0;
m_signal = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[i];
m_value += m_weight * m_signal;
m_weight *= m_signal;
resolution *= m_lacunarity;
}
m_remainder = m_octaves - static_cast<int>(m_octaves);
if(remainder != 0)
m_value += m_remainder * m_source->GetValue(x,y,z,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
return m_value/this->m_sum - m_offset;
}
NzHybridMultiFractal3D::~NzHybridMultiFractal3D()
{
delete m_source;
}

View File

@ -0,0 +1,65 @@
// 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/Core/Error.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/HybridMultiFractal4D.hpp>
#include <Nazara/Noise/Perlin4D.hpp>
#include <Nazara/Noise/Simplex4D.hpp>
#include <Nazara/Noise/Debug.hpp>
NzHybridMultiFractal4D::NzHybridMultiFractal4D(nzNoises source, int seed)
{
switch(source)
{
case PERLIN:
m_source = new NzPerlin4D();
break;
default:
m_source = new NzSimplex4D();
break;
}
m_source->SetNewSeed(seed);
m_source->ShufflePermutationTable();
m_noiseType = source;
}
float NzHybridMultiFractal4D::GetValue(float x, float y, float z, float w, float resolution)
{
this->RecomputeExponentArray();
m_offset = 1.0f;
m_value = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[0];
m_weight = m_value;
m_signal = 0.f;
resolution *= m_lacunarity;
for(int i(1) ; i < m_octaves; ++i)
{
if(m_weight > 1.0)
m_weight = 1.0;
m_signal = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[i];
m_value += m_weight * m_signal;
m_weight *= m_signal;
resolution *= m_lacunarity;
}
m_remainder = m_octaves - static_cast<int>(m_octaves);
if(remainder != 0)
m_value += m_remainder * m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
return m_value/this->m_sum - m_offset;
}
NzHybridMultiFractal4D::~NzHybridMultiFractal4D()
{
delete m_source;
}

View File

@ -30,23 +30,23 @@ float NzHybridMultiFractal2D::GetValue(float x, float y, float resolution)
{
this->RecomputeExponentArray();
float offset = 1.0f;
m_offset = 1.0f;
m_value = (m_source->GetValue(x,y,resolution) + offset) * m_exponent_array[0];
float weight = m_value;
float signal;
m_value = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[0];
m_weight = m_value;
m_signal = 0.f;
resolution *= m_lacunarity;
for(int i(1) ; i < m_octaves; ++i)
{
if(weight > 1.0)
weight = 1.0;
if(m_weight > 1.0)
m_weight = 1.0;
signal = (m_source->GetValue(x,y,resolution) + offset) * m_exponent_array[i];
m_value += weight * signal;
m_signal = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[i];
m_value += m_weight * m_signal;
weight *= signal;
m_weight *= m_signal;
resolution *= m_lacunarity;
}
@ -56,7 +56,7 @@ float NzHybridMultiFractal2D::GetValue(float x, float y, float resolution)
if(remainder != 0)
m_value += m_remainder * m_source->GetValue(x,y,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
return m_value/this->m_sum;
return m_value/this->m_sum - m_offset;
}
NzHybridMultiFractal2D::~NzHybridMultiFractal2D()

View File

@ -17,6 +17,12 @@ NzPerlin2D::NzPerlin2D()
gradient2[i][j] = grad2Temp[i][j];
}
NzPerlin2D::NzPerlin2D(int seed) : NzPerlin2D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzPerlin2D::GetValue(float x, float y, float resolution)
{
x *= resolution;

View File

@ -21,6 +21,12 @@ NzPerlin3D::NzPerlin3D()
gradient3[i][j] = grad3Temp[i][j];
}
NzPerlin3D::NzPerlin3D(int seed) : NzPerlin3D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzPerlin3D::GetValue(float x, float y, float z, float resolution)
{
x /= resolution;

View File

@ -26,6 +26,12 @@ NzPerlin4D::NzPerlin4D()
gradient4[i][j] = grad4Temp[i][j];
}
NzPerlin4D::NzPerlin4D(int seed) : NzPerlin4D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzPerlin4D::GetValue(float x, float y, float z, float w, float resolution)
{
x *= resolution;

View File

@ -20,6 +20,12 @@ NzSimplex2D::NzSimplex2D()
UnskewCoeff2D = (3.0-sqrt(3.0))/6.;
}
NzSimplex2D::NzSimplex2D(int seed) : NzSimplex2D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzSimplex2D::GetValue(float x, float y, float resolution)
{
x *= resolution;

View File

@ -21,6 +21,12 @@ NzSimplex3D::NzSimplex3D()
gradient3[i][j] = grad3Temp[i][j];
}
NzSimplex3D::NzSimplex3D(int seed) : NzSimplex3D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzSimplex3D::GetValue(float x, float y, float z, float resolution)
{
x *= resolution;

View File

@ -45,6 +45,12 @@ NzSimplex4D::NzSimplex4D()
gradient4[i][j] = grad4Temp[i][j];
}
NzSimplex4D::NzSimplex4D(int seed) : NzSimplex4D()
{
this->SetNewSeed(seed);
this->ShufflePermutationTable();
}
float NzSimplex4D::GetValue(float x, float y, float z, float w, float resolution)
{
x *= resolution;