2012-01-22 18:39:42 +00:00
|
|
|
#include "formterrain.h"
|
|
|
|
|
|
|
|
#include "tools.h"
|
|
|
|
#include <QColor>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "../lib_paysages/terrain.h"
|
|
|
|
#include "../lib_paysages/shared/functions.h"
|
|
|
|
#include "../lib_paysages/shared/constants.h"
|
|
|
|
|
|
|
|
static TerrainDefinition _definition;
|
|
|
|
|
|
|
|
/**************** Previews ****************/
|
|
|
|
class PreviewTerrainHeight:public Preview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTerrainHeight(QWidget* parent):
|
|
|
|
Preview(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
double height;
|
|
|
|
|
2012-01-23 23:45:33 +00:00
|
|
|
height = terrainGetHeightNormalizedCustom(x, y, &_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PreviewTerrainColor:public Preview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTerrainColor(QWidget* parent):
|
|
|
|
Preview(parent)
|
|
|
|
{
|
2012-01-23 23:45:33 +00:00
|
|
|
_lighting_environment.filter = NULL;
|
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
_environment.toggle_fog = 0;
|
2012-01-23 23:45:33 +00:00
|
|
|
_environment.lighting_definition = NULL;
|
|
|
|
_environment.lighting_environment = &_lighting_environment;
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
return colorToQColor(terrainGetColorCustom(x, y, scaling, &_definition, NULL, &_environment));
|
|
|
|
}
|
|
|
|
private:
|
2012-01-23 23:45:33 +00:00
|
|
|
LightingEnvironment _lighting_environment;
|
2012-01-22 18:39:42 +00:00
|
|
|
TerrainEnvironment _environment;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************** Form ****************/
|
|
|
|
FormTerrain::FormTerrain(QWidget *parent):
|
|
|
|
BaseForm(parent)
|
|
|
|
{
|
|
|
|
_definition = terrainCreateDefinition();
|
|
|
|
|
|
|
|
previewHeight = new PreviewTerrainHeight(this);
|
|
|
|
previewColor = new PreviewTerrainColor(this);
|
2012-01-23 23:45:33 +00:00
|
|
|
addPreview(previewHeight, QString("Height preview (normalized)"));
|
|
|
|
addPreview(previewColor, QString("Textured preview (no shadow)"));
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-01-23 23:45:33 +00:00
|
|
|
addInputNoise("Noise", _definition.height_noise);
|
|
|
|
addInputDouble("Height", &_definition.height_factor, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputDouble("Scaling", &_definition.scaling, 1.0, 20.0, 0.1, 1.0);
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::revertConfig()
|
|
|
|
{
|
|
|
|
terrainCopyDefinition(terrainGetDefinition(), &_definition);
|
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::applyConfig()
|
|
|
|
{
|
|
|
|
terrainSetDefinition(_definition);
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
2012-01-23 23:45:33 +00:00
|
|
|
|
|
|
|
void FormTerrain::applyConfigPreview()
|
|
|
|
{
|
|
|
|
terrainValidateDefinition(&_definition);
|
|
|
|
BaseForm::applyConfigPreview();
|
|
|
|
}
|