【问题标题】:Noise++ Perlin Module returns 0 all the timeNoise++ Perlin 模块一直返回 0
【发布时间】:2013-10-24 23:25:15
【问题描述】:

我正在使用 Noise++ 库在我的程序中生成噪声,至少这就是目标。 我将它设置为像其中一项测试一样进行测试,但是无论我给它什么参数,我只会得到 0 回来

如果有人对 Noise++ 有任何经验,如果你能检查一下我是否做错了什么,那将非常有帮助。

//
// 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 );
}

【问题讨论】:

  • 您确定要等待线程完成吗?
  • 我以为线程都是在内部完成的,即:用户(在这种情况下是我)不必担心线程问题
  • 不使用线程是否有效?

标签: c++ perlin-noise noise-generator


【解决方案1】:

我已在您的代码中添加了以下几行以进行编译(除了清理缓存之外基本上没有任何更改):

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 );
}

调用它
NoiseppNoise np;
std::cout<<np.Generate(1.5,1)<<std::endl;

实际上输出了一个不错的值,对我来说是 0.0909。

但是,如果您使用两个“整数”(例如 3.0 和 5.0)调用它,则输出将为 0,因为在某些时候会执行类似于以下语句的内容:

const Real xs = Math::CubicCurve3 (x - Real(x0));

如果参数是整数,那么xReal(x0) 总是相同的,因为Real(x0) 基本上是x 的整数部分,所以xs 将被设置为0。这之后还有更多的计算得到实际值,但它确定性地变为 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 2013-04-09
    • 2017-12-05
    • 2015-10-21
    • 2012-03-23
    • 2013-01-10
    • 2015-04-06
    相关资源
    最近更新 更多