Added HybridMultiF 3D & 4D
*new constructors for simple noises *minor bufixes Former-commit-id: 2f1e9b6b54087e79b3ac52fefc9bbd67fd45c0eb
This commit is contained in:
65
src/Nazara/Noise/HybridMultiFractal3D.cpp
Normal file
65
src/Nazara/Noise/HybridMultiFractal3D.cpp
Normal 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;
|
||||
}
|
||||
65
src/Nazara/Noise/HybridMultiFractal4D.cpp
Normal file
65
src/Nazara/Noise/HybridMultiFractal4D.cpp
Normal 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;
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user