Merge branch 'master' into vegetation
This commit is contained in:
commit
0ddec2393d
6 changed files with 131 additions and 36 deletions
|
@ -29,7 +29,7 @@ NoiseGenerator::~NoiseGenerator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseGenerator::save(PackStream* stream)
|
void NoiseGenerator::save(PackStream* stream) const
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ void NoiseGenerator::save(PackStream* stream)
|
||||||
|
|
||||||
for (x = 0; x < level_count; x++)
|
for (x = 0; x < level_count; x++)
|
||||||
{
|
{
|
||||||
NoiseLevel* level = levels + x;
|
const NoiseLevel* level = levels + x;
|
||||||
|
|
||||||
stream->write(&level->frequency);
|
stream->write(&level->frequency);
|
||||||
stream->write(&level->amplitude);
|
stream->write(&level->amplitude);
|
||||||
|
@ -84,7 +84,7 @@ void NoiseGenerator::load(PackStream* stream)
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseGenerator::copy(NoiseGenerator* destination)
|
void NoiseGenerator::copy(NoiseGenerator* destination) const
|
||||||
{
|
{
|
||||||
destination->function = function;
|
destination->function = function;
|
||||||
destination->height_offset = height_offset;
|
destination->height_offset = height_offset;
|
||||||
|
@ -94,7 +94,7 @@ void NoiseGenerator::copy(NoiseGenerator* destination)
|
||||||
|
|
||||||
state.copy(&destination->state);
|
state.copy(&destination->state);
|
||||||
|
|
||||||
validate();
|
destination->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseGenerator::validate()
|
void NoiseGenerator::validate()
|
||||||
|
@ -189,13 +189,13 @@ void NoiseGenerator::forceValue(double value)
|
||||||
addLevelSimple(1.0, 0.0, 0.0); /* FIXME Should not be needed */
|
addLevelSimple(1.0, 0.0, 0.0); /* FIXME Should not be needed */
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseGenerator::getRange(double* minvalue, double* maxvalue)
|
void NoiseGenerator::getRange(double* minvalue, double* maxvalue) const
|
||||||
{
|
{
|
||||||
*minvalue = _min_value;
|
*minvalue = _min_value;
|
||||||
*maxvalue = _max_value;
|
*maxvalue = _max_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NoiseGenerator::getLevelCount()
|
int NoiseGenerator::getLevelCount() const
|
||||||
{
|
{
|
||||||
return level_count;
|
return level_count;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ void NoiseGenerator::removeLevel(int level)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int NoiseGenerator::getLevel(int level, NoiseLevel* params)
|
int NoiseGenerator::getLevel(int level, NoiseLevel* params) const
|
||||||
{
|
{
|
||||||
if (level >= 0 && level < level_count)
|
if (level >= 0 && level < level_count)
|
||||||
{
|
{
|
||||||
|
@ -374,12 +374,12 @@ static inline double _fixValue(double value, double ridge, double curve)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline double NoiseGenerator::_get1DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x)
|
inline double NoiseGenerator::_get1DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x) const
|
||||||
{
|
{
|
||||||
return level->minvalue + _fixValue(_func_noise_1d(x * level->frequency + offset.x), function.ridge_factor, function.curve_factor) * level->amplitude;
|
return level->minvalue + _fixValue(_func_noise_1d(x * level->frequency + offset.x), function.ridge_factor, function.curve_factor) * level->amplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get1DLevel(int level, double x)
|
double NoiseGenerator::get1DLevel(int level, double x) const
|
||||||
{
|
{
|
||||||
if (level >= 0 && level < level_count)
|
if (level >= 0 && level < level_count)
|
||||||
{
|
{
|
||||||
|
@ -391,7 +391,7 @@ double NoiseGenerator::get1DLevel(int level, double x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get1DTotal(double x)
|
double NoiseGenerator::get1DTotal(double x) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result;
|
double result;
|
||||||
|
@ -404,7 +404,7 @@ double NoiseGenerator::get1DTotal(double x)
|
||||||
return result + height_offset;
|
return result + height_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get1DDetail(double x, double detail)
|
double NoiseGenerator::get1DDetail(double x, double detail) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result, height, factor;
|
double result, height, factor;
|
||||||
|
@ -431,12 +431,12 @@ double NoiseGenerator::get1DDetail(double x, double detail)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline double NoiseGenerator::_get2DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y)
|
inline double NoiseGenerator::_get2DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y) const
|
||||||
{
|
{
|
||||||
return level->minvalue + _fixValue(_func_noise_2d(x * level->frequency + offset.x, y * level->frequency + offset.y), function.ridge_factor, function.curve_factor) * level->amplitude;
|
return level->minvalue + _fixValue(_func_noise_2d(x * level->frequency + offset.x, y * level->frequency + offset.y), function.ridge_factor, function.curve_factor) * level->amplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get2DLevel(int level, double x, double y)
|
double NoiseGenerator::get2DLevel(int level, double x, double y) const
|
||||||
{
|
{
|
||||||
if (level >= 0 && level < level_count)
|
if (level >= 0 && level < level_count)
|
||||||
{
|
{
|
||||||
|
@ -448,7 +448,7 @@ double NoiseGenerator::get2DLevel(int level, double x, double y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get2DTotal(double x, double y)
|
double NoiseGenerator::get2DTotal(double x, double y) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result;
|
double result;
|
||||||
|
@ -461,7 +461,7 @@ double NoiseGenerator::get2DTotal(double x, double y)
|
||||||
return result + height_offset;
|
return result + height_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get2DDetail(double x, double y, double detail)
|
double NoiseGenerator::get2DDetail(double x, double y, double detail) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result, height, factor;
|
double result, height, factor;
|
||||||
|
@ -488,12 +488,12 @@ double NoiseGenerator::get2DDetail(double x, double y, double detail)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline double NoiseGenerator::_get3DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y, double z)
|
inline double NoiseGenerator::_get3DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y, double z) const
|
||||||
{
|
{
|
||||||
return level->minvalue + _fixValue(_func_noise_3d(x * level->frequency + offset.x, y * level->frequency + offset.y, z * level->frequency + offset.z), function.ridge_factor, function.curve_factor) * level->amplitude;
|
return level->minvalue + _fixValue(_func_noise_3d(x * level->frequency + offset.x, y * level->frequency + offset.y, z * level->frequency + offset.z), function.ridge_factor, function.curve_factor) * level->amplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get3DLevel(int level, double x, double y, double z)
|
double NoiseGenerator::get3DLevel(int level, double x, double y, double z) const
|
||||||
{
|
{
|
||||||
if (level >= 0 && level < level_count)
|
if (level >= 0 && level < level_count)
|
||||||
{
|
{
|
||||||
|
@ -505,7 +505,7 @@ double NoiseGenerator::get3DLevel(int level, double x, double y, double z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get3DTotal(double x, double y, double z)
|
double NoiseGenerator::get3DTotal(double x, double y, double z) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result;
|
double result;
|
||||||
|
@ -518,7 +518,7 @@ double NoiseGenerator::get3DTotal(double x, double y, double z)
|
||||||
return result + height_offset;
|
return result + height_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
double NoiseGenerator::get3DDetail(double x, double y, double z, double detail)
|
double NoiseGenerator::get3DDetail(double x, double y, double z, double detail) const
|
||||||
{
|
{
|
||||||
int level;
|
int level;
|
||||||
double result, height, factor;
|
double result, height, factor;
|
||||||
|
|
|
@ -37,9 +37,9 @@ public:
|
||||||
NoiseGenerator();
|
NoiseGenerator();
|
||||||
virtual ~NoiseGenerator();
|
virtual ~NoiseGenerator();
|
||||||
|
|
||||||
virtual void save(PackStream* stream);
|
virtual void save(PackStream* stream) const;
|
||||||
virtual void load(PackStream* stream);
|
virtual void load(PackStream* stream);
|
||||||
virtual void copy(NoiseGenerator* destination);
|
virtual void copy(NoiseGenerator* destination) const;
|
||||||
virtual void validate();
|
virtual void validate();
|
||||||
|
|
||||||
inline const NoiseState &getState() const {return state;}
|
inline const NoiseState &getState() const {return state;}
|
||||||
|
@ -51,32 +51,32 @@ public:
|
||||||
void setFunction(NoiseFunction* function);
|
void setFunction(NoiseFunction* function);
|
||||||
void setFunctionParams(NoiseFunctionAlgorithm algorithm, double ridge_factor, double curve_factor);
|
void setFunctionParams(NoiseFunctionAlgorithm algorithm, double ridge_factor, double curve_factor);
|
||||||
void forceValue(double value);
|
void forceValue(double value);
|
||||||
void getRange(double* minvalue, double* maxvalue);
|
void getRange(double* minvalue, double* maxvalue) const;
|
||||||
int getLevelCount();
|
int getLevelCount() const;
|
||||||
void clearLevels();
|
void clearLevels();
|
||||||
void addLevel(NoiseLevel level);
|
void addLevel(NoiseLevel level);
|
||||||
void addLevelSimple(double scaling, double minvalue, double maxvalue);
|
void addLevelSimple(double scaling, double minvalue, double maxvalue);
|
||||||
void addLevels(int level_count, NoiseLevel start_level, double scaling_factor, double amplitude_factor, double center_factor);
|
void addLevels(int level_count, NoiseLevel start_level, double scaling_factor, double amplitude_factor, double center_factor);
|
||||||
void addLevelsSimple(int level_count, double scaling, double minvalue, double maxvalue, double center_factor);
|
void addLevelsSimple(int level_count, double scaling, double minvalue, double maxvalue, double center_factor);
|
||||||
void removeLevel(int level);
|
void removeLevel(int level);
|
||||||
int getLevel(int level, NoiseLevel* params);
|
int getLevel(int level, NoiseLevel* params) const;
|
||||||
void setLevel(int index, NoiseLevel level);
|
void setLevel(int index, NoiseLevel level);
|
||||||
void setLevelSimple(int index, double scaling, double minvalue, double maxvalue);
|
void setLevelSimple(int index, double scaling, double minvalue, double maxvalue);
|
||||||
void normalizeAmplitude(double minvalue, double maxvalue, int adjust_scaling);
|
void normalizeAmplitude(double minvalue, double maxvalue, int adjust_scaling);
|
||||||
double get1DLevel(int level, double x);
|
double get1DLevel(int level, double x) const;
|
||||||
double get1DTotal(double x);
|
double get1DTotal(double x) const;
|
||||||
double get1DDetail(double x, double detail);
|
double get1DDetail(double x, double detail) const;
|
||||||
double get2DLevel(int level, double x, double y);
|
double get2DLevel(int level, double x, double y) const;
|
||||||
double get2DTotal(double x, double y);
|
double get2DTotal(double x, double y) const;
|
||||||
double get2DDetail(double x, double y, double detail);
|
double get2DDetail(double x, double y, double detail) const;
|
||||||
double get3DLevel(int level, double x, double y, double z);
|
double get3DLevel(int level, double x, double y, double z) const;
|
||||||
double get3DTotal(double x, double y, double z);
|
double get3DTotal(double x, double y, double z) const;
|
||||||
double get3DDetail(double x, double y, double z, double detail);
|
double get3DDetail(double x, double y, double z, double detail) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double _get1DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x);
|
double _get1DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x) const;
|
||||||
double _get2DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y);
|
double _get2DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y) const;
|
||||||
double _get3DLevelValue(NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y, double z);
|
double _get3DLevelValue(const NoiseLevel* level, const NoiseState::NoiseOffset &offset, double x, double y, double z) const;
|
||||||
|
|
||||||
NoiseFunction function;
|
NoiseFunction function;
|
||||||
double height_offset;
|
double height_offset;
|
||||||
|
|
51
src/definition/NoiseNode.cpp
Normal file
51
src/definition/NoiseNode.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include "NoiseNode.h"
|
||||||
|
|
||||||
|
#include "NoiseGenerator.h"
|
||||||
|
#include "Logs.h"
|
||||||
|
|
||||||
|
NoiseNode::NoiseNode(DefinitionNode *parent):
|
||||||
|
DefinitionNode(parent, "noise")
|
||||||
|
{
|
||||||
|
noise = new NoiseGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
NoiseNode::~NoiseNode()
|
||||||
|
{
|
||||||
|
delete noise;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseNode::setLevels(int levels, double min_value, double max_value)
|
||||||
|
{
|
||||||
|
noise->clearLevels();
|
||||||
|
noise->addLevelsSimple(levels, 1.0, -1.0, 1.0, 0.5);
|
||||||
|
noise->normalizeAmplitude(min_value, max_value, false);
|
||||||
|
noise->randomizeOffsets();
|
||||||
|
noise->validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseNode::save(PackStream *stream) const
|
||||||
|
{
|
||||||
|
noise->save(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseNode::load(PackStream *stream)
|
||||||
|
{
|
||||||
|
noise->load(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseNode::copy(DefinitionNode *destination) const
|
||||||
|
{
|
||||||
|
if (destination->getTypeName() == getTypeName())
|
||||||
|
{
|
||||||
|
noise->copy(((NoiseNode *)destination)->noise);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseNode::validate()
|
||||||
|
{
|
||||||
|
noise->validate();
|
||||||
|
}
|
41
src/definition/NoiseNode.h
Normal file
41
src/definition/NoiseNode.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef NOISENODE_H
|
||||||
|
#define NOISENODE_H
|
||||||
|
|
||||||
|
#include "definition_global.h"
|
||||||
|
|
||||||
|
#include "DefinitionNode.h"
|
||||||
|
|
||||||
|
namespace paysages {
|
||||||
|
namespace definition {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition node with noise parameters.
|
||||||
|
*/
|
||||||
|
class DEFINITIONSHARED_EXPORT NoiseNode: public DefinitionNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NoiseNode(DefinitionNode *parent);
|
||||||
|
virtual ~NoiseNode();
|
||||||
|
|
||||||
|
inline const NoiseGenerator *getGenerator() {return noise;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the number of levels to use in the noise generator.
|
||||||
|
*/
|
||||||
|
void setLevels(int levels, double min_value=-1.0, double max_value=1.0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void save(PackStream *stream) const override;
|
||||||
|
virtual void load(PackStream *stream) override;
|
||||||
|
virtual void copy(DefinitionNode *destination) const override;
|
||||||
|
virtual void validate() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
NoiseGenerator *noise;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NOISENODE_H
|
|
@ -42,6 +42,7 @@ SOURCES += \
|
||||||
DefinitionWatcher.cpp \
|
DefinitionWatcher.cpp \
|
||||||
IntNode.cpp \
|
IntNode.cpp \
|
||||||
IntDiff.cpp \
|
IntDiff.cpp \
|
||||||
|
NoiseNode.cpp \
|
||||||
GodRaysDefinition.cpp \
|
GodRaysDefinition.cpp \
|
||||||
TimeManager.cpp \
|
TimeManager.cpp \
|
||||||
VegetationPresenceDefinition.cpp
|
VegetationPresenceDefinition.cpp
|
||||||
|
@ -76,6 +77,7 @@ HEADERS +=\
|
||||||
DefinitionWatcher.h \
|
DefinitionWatcher.h \
|
||||||
IntNode.h \
|
IntNode.h \
|
||||||
IntDiff.h \
|
IntDiff.h \
|
||||||
|
NoiseNode.h \
|
||||||
GodRaysDefinition.h \
|
GodRaysDefinition.h \
|
||||||
TimeManager.h \
|
TimeManager.h \
|
||||||
VegetationPresenceDefinition.h
|
VegetationPresenceDefinition.h
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace definition {
|
||||||
class FloatDiff;
|
class FloatDiff;
|
||||||
class IntNode;
|
class IntNode;
|
||||||
class IntDiff;
|
class IntDiff;
|
||||||
|
class NoiseNode;
|
||||||
class DiffManager;
|
class DiffManager;
|
||||||
class DefinitionWatcher;
|
class DefinitionWatcher;
|
||||||
class Scenery;
|
class Scenery;
|
||||||
|
|
Loading…
Reference in a new issue