Im using the Noise++ Library to generate noise in my program, well at least thats the aim. I have it setup like one of the tests in order to test it out, however no matter what parameters I give it I only get 0 back
If anyone has any experience with Noise++ it would be really helpful if you could check over and see if im doing anything wrong.
//
// Defaults are
// Frequency = 1
// Octaves = 6
// Seed = 0
// Quality = 1
// Lacunarity = 2
// Persistence = 0.5
// Scale = 2.12
//
NoiseppNoise::NoiseppNoise( ) : mPipeline2d( 2 )
{
mThreadCount = noisepp::utils::System::getNumberOfCPUs ();
mPerlin.setSeed(4321);
if ( mThreadCount > 2 ) {
mPipeline2d = noisepp::ThreadedPipeline2D( mThreadCount );
}
mNoiseID2D = mPerlin.addToPipe ( mPipeline2d );
mCache2d = mPipeline2d.createCache();
}
double NoiseppNoise::Generate( double x, double y )
{
return mPipeline2d.getElement( mNoiseID2D )->getValue ( x, y, mCache2d );
}
I have added the following lines to your code to compile (basically no changes except for cleaning the cache):
struct NoiseppNoise
{
NoiseppNoise();
double Generate( double x, double y );
noisepp::ThreadedPipeline2D mPipeline2d;
noisepp::ElementID mThreadCount;
noisepp::PerlinModule mPerlin;
noisepp::ElementID mNoiseID2D;
noisepp::Cache* mCache2d;
};
/* constructor as in the question */
double NoiseppNoise::Generate( double x, double y )
{
mPipeline2d.cleanCache (mCache2d); // clean the cache before calculating value
return mPipeline2d.getElement( mNoiseID2D )->getValue ( x, y, mCache2d );
}
Calling it with
NoiseppNoise np;
std::cout<<np.Generate(1.5,1)<<std::endl;
actually outputs a good value, 0.0909 for me.
However if you call it with two "integers" (e.g. 3.0 and 5.0) the output will be 0 because at some point something similar to the following statement is executed:
const Real xs = Math::CubicCurve3 (x - Real(x0));
If the parameters are integers then x
and Real(x0)
are always the same because Real(x0)
is basically the integer part of x
and so xs
will be set to 0. After this there are more calculations to get the actual value but it becomes deterministically 0.