55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
// Copyright (C) 2015 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/FBM4D.hpp>
|
|
#include <Nazara/Noise/Perlin4D.hpp>
|
|
#include <Nazara/Noise/Simplex4D.hpp>
|
|
#include <Nazara/Noise/Debug.hpp>
|
|
|
|
namespace Nz
|
|
{
|
|
FBM4D::FBM4D(NoiseType source, unsigned int seed)
|
|
{
|
|
switch(source)
|
|
{
|
|
case PERLIN:
|
|
m_source = new Perlin4D();
|
|
break;
|
|
|
|
default:
|
|
m_source = new Simplex4D();
|
|
break;
|
|
}
|
|
m_source->SetNewSeed(seed);
|
|
m_source->ShufflePermutationTable();
|
|
m_noiseType = source;
|
|
}
|
|
|
|
float FBM4D::GetValue(float x, float y, float z, float w, float resolution)
|
|
{
|
|
this->RecomputeExponentArray();
|
|
|
|
m_value = 0.0;
|
|
|
|
for (int i(0); i < m_octaves; ++i)
|
|
{
|
|
m_value += m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[i];
|
|
resolution *= m_lacunarity;
|
|
}
|
|
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
|
|
|
if(!NumberEquals(m_remainder, static_cast<float>(0.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;
|
|
}
|
|
|
|
FBM4D::~FBM4D()
|
|
{
|
|
delete m_source;
|
|
}
|
|
}
|