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/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
|
|
|
{
|
2012-01-25 22:32:06 +00:00
|
|
|
_preview_definition = terrainCreateDefinition();
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
double height;
|
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
height = terrainGetHeightNormalized(&_preview_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));
|
|
|
|
}
|
2012-01-25 22:32:06 +00:00
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
terrainCopyDefinition(&_definition, &_preview_definition);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
TerrainDefinition _preview_definition;
|
2012-01-22 18:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-26 18:20:19 +00:00
|
|
|
_renderer = rendererGetFake();
|
2012-01-26 22:30:20 +00:00
|
|
|
_renderer.applyTextures = _applyTextures;
|
|
|
|
_renderer.getTerrainHeight = _getTerrainHeight;
|
|
|
|
/*_renderer.applyLightingToSurface = _applyLightingToSurface;*/
|
|
|
|
|
|
|
|
_terrain = terrainCreateDefinition();
|
|
|
|
_textures = texturesCreateDefinition();
|
|
|
|
|
|
|
|
_renderer.customData[0] = &_terrain;
|
|
|
|
_renderer.customData[1] = &_textures;
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
2012-01-26 22:30:20 +00:00
|
|
|
return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling));
|
2012-01-25 22:32:06 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-01-26 22:30:20 +00:00
|
|
|
terrainCopyDefinition(&_definition, &_terrain);
|
|
|
|
sceneryGetTextures(&_textures);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
private:
|
2012-01-24 13:16:20 +00:00
|
|
|
Renderer _renderer;
|
2012-01-26 22:30:20 +00:00
|
|
|
TerrainDefinition _terrain;
|
|
|
|
TexturesDefinition _textures;
|
|
|
|
|
|
|
|
static double _getTerrainHeight(Renderer* renderer, double x, double z)
|
|
|
|
{
|
|
|
|
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
|
|
|
{
|
|
|
|
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location, precision);
|
|
|
|
}
|
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
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
void FormTerrain::configChangeEvent()
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
|
|
|
terrainValidateDefinition(&_definition);
|
2012-01-25 22:32:06 +00:00
|
|
|
BaseForm::configChangeEvent();
|
2012-01-23 23:45:33 +00:00
|
|
|
}
|