Added FBM 3D & 4D and HybridMultiFractal 2D + cleaned code

this commit will change the scale of values produced by fbm2d. This will
probably not happen again. As a consequence, fbm values will always be
constrained between -1 and 1, but do not perfectly stick to that scale.
There is no easy solution, if the user wants the best dynamic between -1
and 1, he should adjust manually the value by multiplying by a gain slightly superior to 1.


Former-commit-id: ebdba9e9f4bbb972abe355c07ec9f8bce42329b9
This commit is contained in:
Remi Beges
2012-11-09 18:38:50 +01:00
parent 7bd6202389
commit 8f04f3e6a0
10 changed files with 270 additions and 28 deletions

View File

@@ -0,0 +1,51 @@
// 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/FBM3D.hpp>
#include <Nazara/Noise/Perlin3D.hpp>
#include <Nazara/Noise/Simplex3D.hpp>
#include <Nazara/Noise/Debug.hpp>
NzFBM3D::NzFBM3D(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 NzFBM3D::GetValue(float x, float y, float z, float resolution)
{
this->RecomputeExponentArray();
m_value = 0.0;
for (int i(0); i < m_octaves; ++i)
{
m_value += m_source->GetValue(x,y,z,resolution) * m_exponent_array[i];
resolution *= m_lacunarity;
}
m_remainder = m_octaves - static_cast<int>(m_octaves);
if(!NzNumberEquals(m_remainder, static_cast<float>(0.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;
}
NzFBM3D::~NzFBM3D()
{
delete m_source;
}