diff --git a/TODO b/TODO index 5497c48..a7fe1b8 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ Technology Preview 2 : - Fully move layer management from BaseForm to BaseFormLayer. - Replace math.h methods by optimized ones (fastfloor, fastsin...). -- Reimplement perlin noise and custom noise. - Replace terrain canvas editor by full sculpting editor. => Add a generation dialog, with fixed resolution. => Store local terrain modifications in fully dynamic canvas. diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index ccef198..6b47782 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -9,6 +9,7 @@ #include #include #include +#include /**************** Previews ****************/ class PreviewLevel:public BasePreview @@ -124,13 +125,14 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value): function->layout()->addWidget(new QLabel(tr("Noise function"))); function_algo = new QComboBox(function); - function_algo->addItems(QStringList(tr("Simplex")) << tr("Perlin") << tr("Naive")); + function_algo->addItems(QStringList(tr("Simplex (best)")) << tr("Perlin (fast)") << tr("Naive (slow)")); function->layout()->addWidget(function_algo); function->layout()->addWidget(new QLabel(tr("Ridge factor"))); function_ridge = new QSlider(Qt::Horizontal, function); function_ridge->setRange(-10, 10); function_ridge->setTickInterval(10); function_ridge->setTickPosition(QSlider::TicksBelow); + function_ridge->setMinimumWidth(150); function->layout()->addWidget(function_ridge); QObject::connect(function_algo, SIGNAL(currentIndexChanged(int)), this, SLOT(functionChanged())); QObject::connect(function_ridge, SIGNAL(valueChanged(int)), this, SLOT(functionChanged())); diff --git a/lib_paysages/noise.c b/lib_paysages/noise.c index ad9cc87..9ab950a 100644 --- a/lib_paysages/noise.c +++ b/lib_paysages/noise.c @@ -361,6 +361,18 @@ void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double m static inline double _applyRidge(double value, double ridge) { if (ridge > 0.0) + { + return fabs(value + 0.5 - ridge) / (1.0 - ridge) - 0.5; + } + else if (ridge < 0.0) + { + return -fabs(value - 0.5 - ridge) / (1.0 + ridge) + 0.5; + } + else + { + return value; + } + /*if (ridge > 0.0) { return fabs(value + 0.5 - ridge) - 0.5 + ridge; } @@ -371,7 +383,7 @@ static inline double _applyRidge(double value, double ridge) else { return value; - } + }*/ } @@ -379,7 +391,7 @@ static inline double _applyRidge(double value, double ridge) static inline double _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x) { - return _applyRidge(generator->_func_noise_1d(x / level->scaling + level->xoffset) * level->height, generator->function.ridge_factor); + return _applyRidge(generator->_func_noise_1d(x / level->scaling + level->xoffset), generator->function.ridge_factor) * level->height; } double noiseGet1DLevel(NoiseGenerator* generator, int level, double x) @@ -436,7 +448,7 @@ double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail) static inline double _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y) { - return _applyRidge(generator->_func_noise_2d(x / level->scaling + level->xoffset, y / level->scaling + level->yoffset) * level->height, generator->function.ridge_factor); + return _applyRidge(generator->_func_noise_2d(x / level->scaling + level->xoffset, y / level->scaling + level->yoffset), generator->function.ridge_factor) * level->height; } double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y) @@ -493,7 +505,7 @@ double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double de static inline double _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y, double z) { - return _applyRidge(generator->_func_noise_3d(x / level->scaling + level->xoffset, y / level->scaling + level->yoffset, z / level->scaling + level->zoffset) * level->height, generator->function.ridge_factor); + return _applyRidge(generator->_func_noise_3d(x / level->scaling + level->xoffset, y / level->scaling + level->yoffset, z / level->scaling + level->zoffset), generator->function.ridge_factor) * level->height; } double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z)