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"
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-01-22 18:39:42 +00:00
|
|
|
#include "../lib_paysages/shared/functions.h"
|
|
|
|
#include "../lib_paysages/shared/constants.h"
|
|
|
|
|
|
|
|
static TerrainDefinition _definition;
|
|
|
|
|
|
|
|
/**************** Previews ****************/
|
|
|
|
class PreviewTerrainHeight:public Preview
|
|
|
|
{
|
|
|
|
public:
|
2012-01-24 13:16:20 +00:00
|
|
|
PreviewTerrainHeight(QWidget* parent):Preview(parent)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
double height;
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
height = terrainGetHeightNormalized(&_definition, x, y);
|
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:
|
2012-01-24 13:16:20 +00:00
|
|
|
PreviewTerrainColor(QWidget* parent):Preview(parent)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
// TODO Use custom renderer
|
|
|
|
_renderer = sceneryGetStandardRenderer(3);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
return colorToQColor(terrainGetColor(&_definition, &_renderer, x, y, scaling));
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
private:
|
2012-01-24 13:16:20 +00:00
|
|
|
Renderer _renderer;
|
2012-01-22 18:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************** 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()
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
sceneryGetTerrain(&_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::applyConfig()
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
scenerySetTerrain(&_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
2012-01-23 23:45:33 +00:00
|
|
|
|
|
|
|
void FormTerrain::applyConfigPreview()
|
|
|
|
{
|
|
|
|
terrainValidateDefinition(&_definition);
|
|
|
|
BaseForm::applyConfigPreview();
|
|
|
|
}
|