2012-01-29 17:39:56 +00:00
|
|
|
#include "noise.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tools.h"
|
2012-08-26 20:02:10 +00:00
|
|
|
#include "simplexnoise.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
|
2012-02-27 15:42:23 +00:00
|
|
|
#define MAX_LEVEL_COUNT 30
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
struct NoiseLevel;
|
|
|
|
|
|
|
|
struct NoiseGenerator
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double height_offset;
|
2011-12-10 13:25:22 +00:00
|
|
|
int level_count;
|
2012-02-27 15:42:23 +00:00
|
|
|
struct NoiseLevel levels[MAX_LEVEL_COUNT];
|
2012-06-17 16:46:30 +00:00
|
|
|
|
|
|
|
double _max_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
};
|
|
|
|
|
2012-02-27 15:25:12 +00:00
|
|
|
void noiseInit()
|
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
simplexNoiseInit();
|
2012-02-27 15:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void noiseQuit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void noiseSave(PackStream* stream)
|
2012-02-27 15:25:12 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
UNUSED(stream);
|
2012-02-27 15:25:12 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void noiseLoad(PackStream* stream)
|
2012-02-27 15:25:12 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
UNUSED(stream);
|
2012-02-27 15:25:12 +00:00
|
|
|
}
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
NoiseGenerator* noiseCreateGenerator()
|
|
|
|
{
|
|
|
|
NoiseGenerator* result;
|
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
result = malloc(sizeof(NoiseGenerator));
|
|
|
|
result->level_count = 0;
|
|
|
|
result->height_offset = 0.0;
|
2012-06-17 16:46:30 +00:00
|
|
|
|
|
|
|
noiseValidate(result);
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void noiseDeleteGenerator(NoiseGenerator* generator)
|
|
|
|
{
|
|
|
|
free(generator);
|
|
|
|
}
|
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
void noiseSaveGenerator(PackStream* stream, NoiseGenerator* generator)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
packWriteDouble(stream, &generator->height_offset);
|
|
|
|
packWriteInt(stream, &generator->level_count);
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
for (x = 0; x < generator->level_count; x++)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
NoiseLevel* level = generator->levels + x;
|
2012-01-29 17:39:56 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
packWriteDouble(stream, &level->scaling);
|
|
|
|
packWriteDouble(stream, &level->height);
|
|
|
|
packWriteDouble(stream, &level->xoffset);
|
|
|
|
packWriteDouble(stream, &level->yoffset);
|
|
|
|
packWriteDouble(stream, &level->zoffset);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
void noiseLoadGenerator(PackStream* stream, NoiseGenerator* generator)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
packReadDouble(stream, &generator->height_offset);
|
|
|
|
packReadInt(stream, &generator->level_count);
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
for (x = 0; x < generator->level_count; x++)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
NoiseLevel* level = generator->levels + x;
|
2012-01-29 17:39:56 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
packReadDouble(stream, &level->scaling);
|
|
|
|
packReadDouble(stream, &level->height);
|
|
|
|
packReadDouble(stream, &level->xoffset);
|
|
|
|
packReadDouble(stream, &level->yoffset);
|
|
|
|
packReadDouble(stream, &level->zoffset);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
2012-06-17 16:46:30 +00:00
|
|
|
|
2012-08-26 20:02:10 +00:00
|
|
|
noiseValidate(generator);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination)
|
|
|
|
{
|
|
|
|
destination->height_offset = source->height_offset;
|
|
|
|
destination->level_count = source->level_count;
|
|
|
|
|
|
|
|
memcpy(destination->levels, source->levels, sizeof(NoiseLevel) * destination->level_count);
|
2012-06-17 16:46:30 +00:00
|
|
|
|
|
|
|
noiseValidate(destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
void noiseValidate(NoiseGenerator* generator)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
double max_height = generator->height_offset;
|
|
|
|
|
|
|
|
for (x = 0; x < generator->level_count; x++)
|
|
|
|
{
|
|
|
|
max_height += generator->levels[x].height / 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
generator->_max_height = max_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 13:27:57 +00:00
|
|
|
void noiseForceValue(NoiseGenerator* generator, double value)
|
|
|
|
{
|
|
|
|
noiseClearLevels(generator);
|
|
|
|
generator->height_offset = value;
|
|
|
|
noiseAddLevelSimple(generator, 1.0, 0.0); /* FIXME Should not be needed */
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGetMaxValue(NoiseGenerator* generator)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-06-17 16:46:30 +00:00
|
|
|
return generator->_max_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int noiseGetLevelCount(NoiseGenerator* generator)
|
|
|
|
{
|
|
|
|
return generator->level_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void noiseClearLevels(NoiseGenerator* generator)
|
|
|
|
{
|
|
|
|
generator->level_count = 0;
|
2012-06-17 16:46:30 +00:00
|
|
|
noiseValidate(generator);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level)
|
|
|
|
{
|
2012-02-27 15:42:23 +00:00
|
|
|
if (generator->level_count < MAX_LEVEL_COUNT)
|
|
|
|
{
|
|
|
|
generator->levels[generator->level_count] = level;
|
|
|
|
generator->level_count++;
|
2012-06-17 16:46:30 +00:00
|
|
|
noiseValidate(generator);
|
2012-02-27 15:42:23 +00:00
|
|
|
}
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
NoiseLevel level;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
level.scaling = scaling;
|
|
|
|
level.height = height;
|
|
|
|
level.xoffset = toolsRandom();
|
|
|
|
level.yoffset = toolsRandom();
|
|
|
|
level.zoffset = toolsRandom();
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
noiseAddLevel(generator, level);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < level_count; i++)
|
|
|
|
{
|
|
|
|
if (randomize_offset)
|
|
|
|
{
|
|
|
|
start_level.xoffset = toolsRandom();
|
|
|
|
start_level.yoffset = toolsRandom();
|
|
|
|
start_level.zoffset = toolsRandom();
|
|
|
|
}
|
|
|
|
noiseAddLevel(generator, start_level);
|
|
|
|
start_level.scaling *= scaling_factor;
|
|
|
|
start_level.height *= height_factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
NoiseLevel level;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
level.scaling = scaling;
|
|
|
|
level.height = height;
|
|
|
|
noiseAddLevels(generator, level_count, level, 0.5, 0.5, 1);
|
|
|
|
}
|
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
void noiseRemoveLevel(NoiseGenerator* generator, int level)
|
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
if (generator->level_count > 1 && level < generator->level_count - 1)
|
|
|
|
{
|
|
|
|
memmove(generator->levels + level, generator->levels + level + 1, sizeof(NoiseLevel) * (generator->level_count - level - 1));
|
|
|
|
}
|
|
|
|
generator->level_count--;
|
2012-06-17 16:46:30 +00:00
|
|
|
noiseValidate(generator);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
int noiseGetLevel(NoiseGenerator* generator, int level, NoiseLevel* params)
|
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
*params = generator->levels[level];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params)
|
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
generator->levels[level] = params;
|
2012-06-17 16:46:30 +00:00
|
|
|
noiseValidate(generator);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
NoiseLevel params;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
params.scaling = scaling;
|
|
|
|
params.height = height;
|
|
|
|
params.xoffset = toolsRandom();
|
|
|
|
params.yoffset = toolsRandom();
|
|
|
|
params.zoffset = toolsRandom();
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
noiseSetLevel(generator, level, params);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double height = 0.0;
|
|
|
|
double target_height = max_height - min_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
if (generator->level_count == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
height += generator->levels[level].height;
|
|
|
|
}
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
generator->levels[level].height *= target_height / height;
|
|
|
|
if (adjust_scaling)
|
|
|
|
{
|
|
|
|
generator->levels[level].scaling *= target_height / height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
generator->height_offset = min_height + target_height / 2.0;
|
2012-06-17 16:46:30 +00:00
|
|
|
noiseValidate(generator);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return simplexNoiseGet2DValue(x, 0.0) * 0.5;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return _get1DRawNoiseValue(generator, x / level->scaling + level->xoffset) * level->height;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet1DLevel(NoiseGenerator* generator, int level, double x)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
return _get1DLevelValue(generator, generator->levels + level, x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet1DTotal(NoiseGenerator* generator, double x)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
result += _get1DLevelValue(generator, generator->levels + level, x);
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result, height, factor;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
height = generator->levels[level].height;
|
|
|
|
factor = 1.0;
|
|
|
|
if (height < detail * 0.25)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (height < detail * 0.5)
|
|
|
|
{
|
|
|
|
factor = (detail * 0.5 - height) / 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += _get1DLevelValue(generator, generator->levels + level, x) * factor;
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, double y)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return simplexNoiseGet2DValue(x, y) * 0.5;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return _get2DRawNoiseValue(generator, x / level->scaling + level->xoffset, y / level->scaling + level->yoffset) * level->height;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
return _get2DLevelValue(generator, generator->levels + level, x, y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet2DTotal(NoiseGenerator* generator, double x, double y)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
result += _get2DLevelValue(generator, generator->levels + level, x, y);
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result, height, factor;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
height = generator->levels[level].height;
|
|
|
|
factor = 1.0;
|
|
|
|
if (height < detail * 0.25)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (height < detail * 0.5)
|
|
|
|
{
|
|
|
|
factor = (detail * 0.5 - height) / 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += _get2DLevelValue(generator, generator->levels + level, x, y) * factor;
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, double y, double z)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return simplexNoiseGet3DValue(x, y, z) * 0.5;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline double _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y, double z)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-08-26 20:02:10 +00:00
|
|
|
return _get3DRawNoiseValue(generator, x / level->scaling + level->xoffset, y / level->scaling + level->yoffset, z / level->scaling + level->zoffset) * level->height;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
if (level >= 0 && level < generator->level_count)
|
|
|
|
{
|
|
|
|
return _get3DLevelValue(generator, generator->levels + level, x, y, z);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
result += _get3DLevelValue(generator, generator->levels + level, x, y, z);
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
|
|
|
int level;
|
2012-06-17 09:40:40 +00:00
|
|
|
double result, height, factor;
|
2011-12-10 13:25:22 +00:00
|
|
|
|
|
|
|
result = 0.0;
|
|
|
|
for (level = 0; level < generator->level_count; level++)
|
|
|
|
{
|
|
|
|
height = generator->levels[level].height;
|
|
|
|
factor = 1.0;
|
|
|
|
if (height < detail * 0.25)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (height < detail * 0.5)
|
|
|
|
{
|
|
|
|
factor = (detail * 0.5 - height) / 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += _get3DLevelValue(generator, generator->levels + level, x, y, z) * factor;
|
|
|
|
}
|
|
|
|
return result + generator->height_offset;
|
|
|
|
}
|