2013-11-03 14:46:39 +00:00
|
|
|
#ifndef NOISEGENERATOR_H
|
|
|
|
#define NOISEGENERATOR_H
|
|
|
|
|
|
|
|
#include "basics_global.h"
|
|
|
|
|
|
|
|
#define MAX_LEVEL_COUNT 30
|
2013-12-31 14:50:28 +00:00
|
|
|
#include "NoiseState.h"
|
2013-11-03 14:46:39 +00:00
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace basics {
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
class BASICSSHARED_EXPORT NoiseGenerator {
|
|
|
|
public:
|
|
|
|
typedef enum { NOISE_FUNCTION_PERLIN, NOISE_FUNCTION_SIMPLEX, NOISE_FUNCTION_CUSTOM } NoiseFunctionAlgorithm;
|
2013-12-31 14:50:28 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
typedef struct {
|
2013-12-31 14:50:28 +00:00
|
|
|
NoiseFunctionAlgorithm algorithm;
|
|
|
|
double ridge_factor; /* -0.5;0.5 */
|
|
|
|
double curve_factor; /* -1.0;1.0 */
|
|
|
|
} NoiseFunction;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
typedef struct {
|
2014-08-20 14:45:45 +00:00
|
|
|
double frequency;
|
2013-12-31 14:50:28 +00:00
|
|
|
double amplitude;
|
|
|
|
double minvalue;
|
|
|
|
} NoiseLevel;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
public:
|
2013-11-03 14:46:39 +00:00
|
|
|
NoiseGenerator();
|
|
|
|
virtual ~NoiseGenerator();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
virtual void save(PackStream *stream) const;
|
|
|
|
virtual void load(PackStream *stream);
|
|
|
|
virtual void copy(NoiseGenerator *destination) const;
|
2013-11-03 14:46:39 +00:00
|
|
|
virtual void validate();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline const NoiseState &getState() const {
|
|
|
|
return state;
|
|
|
|
}
|
2013-12-31 14:50:28 +00:00
|
|
|
void setState(const NoiseState &state);
|
|
|
|
|
2013-11-03 14:46:39 +00:00
|
|
|
void randomizeOffsets();
|
|
|
|
NoiseFunction getFunction();
|
2015-11-09 21:30:46 +00:00
|
|
|
void setCustomFunction(double (*func1d)(double x), double (*func2d)(double x, double y),
|
|
|
|
double (*func3d)(double x, double y, double z));
|
|
|
|
void setFunction(NoiseFunction *function);
|
2013-11-03 14:46:39 +00:00
|
|
|
void setFunctionParams(NoiseFunctionAlgorithm algorithm, double ridge_factor, double curve_factor);
|
|
|
|
void forceValue(double value);
|
2015-11-09 21:30:46 +00:00
|
|
|
void getRange(double *minvalue, double *maxvalue) const;
|
2015-10-18 22:26:25 +00:00
|
|
|
int getLevelCount() const;
|
2013-11-03 14:46:39 +00:00
|
|
|
void clearLevels();
|
2013-12-31 14:50:28 +00:00
|
|
|
void addLevel(NoiseLevel level);
|
2013-11-03 14:46:39 +00:00
|
|
|
void addLevelSimple(double scaling, double minvalue, double maxvalue);
|
2015-11-09 21:30:46 +00:00
|
|
|
void addLevels(int level_count, NoiseLevel start_level, double scaling_factor, double amplitude_factor,
|
|
|
|
double center_factor);
|
2013-11-03 14:46:39 +00:00
|
|
|
void addLevelsSimple(int level_count, double scaling, double minvalue, double maxvalue, double center_factor);
|
|
|
|
void removeLevel(int level);
|
2015-11-09 21:30:46 +00:00
|
|
|
int getLevel(int level, NoiseLevel *params) const;
|
2013-12-31 14:50:28 +00:00
|
|
|
void setLevel(int index, NoiseLevel level);
|
2013-11-03 14:46:39 +00:00
|
|
|
void setLevelSimple(int index, double scaling, double minvalue, double maxvalue);
|
|
|
|
void normalizeAmplitude(double minvalue, double maxvalue, int adjust_scaling);
|
2015-10-18 22:26:25 +00:00
|
|
|
double get1DLevel(int level, double x) const;
|
|
|
|
double get1DTotal(double x) const;
|
|
|
|
double get1DDetail(double x, double detail) const;
|
|
|
|
double get2DLevel(int level, double x, double y) const;
|
|
|
|
double get2DTotal(double x, double y) const;
|
|
|
|
double get2DDetail(double x, double y, double detail) const;
|
|
|
|
double get3DLevel(int level, double x, double y, double z) const;
|
|
|
|
double get3DTotal(double x, double y, double z) const;
|
|
|
|
double get3DDetail(double x, double y, double z, double detail) const;
|
2013-11-03 14:46:39 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
|
|
|
double _get1DLevelValue(const NoiseLevel *level, const NoiseState::NoiseOffset &offset, double x) const;
|
|
|
|
double _get2DLevelValue(const NoiseLevel *level, const NoiseState::NoiseOffset &offset, double x, double y) const;
|
|
|
|
double _get3DLevelValue(const NoiseLevel *level, const NoiseState::NoiseOffset &offset, double x, double y,
|
|
|
|
double z) const;
|
2013-11-03 14:46:39 +00:00
|
|
|
|
|
|
|
NoiseFunction function;
|
|
|
|
double height_offset;
|
|
|
|
int level_count;
|
|
|
|
NoiseLevel levels[MAX_LEVEL_COUNT];
|
|
|
|
|
2013-12-31 14:50:28 +00:00
|
|
|
NoiseState state;
|
|
|
|
|
2013-11-03 14:46:39 +00:00
|
|
|
double _min_value;
|
|
|
|
double _max_value;
|
|
|
|
double (*_func_noise_1d)(double x);
|
|
|
|
double (*_func_noise_2d)(double x, double y);
|
|
|
|
double (*_func_noise_3d)(double x, double y, double z);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOISEGENERATOR_H
|