2012-01-26 23:08:09 +00:00
|
|
|
#include "formtextures.h"
|
|
|
|
|
|
|
|
#include "../lib_paysages/textures.h"
|
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-04-05 16:16:32 +00:00
|
|
|
#include "tools.h"
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
static TexturesDefinition _definition;
|
2012-04-03 19:33:40 +00:00
|
|
|
static TextureLayerDefinition _layer;
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-04-05 20:09:39 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-07-02 15:35:10 +00:00
|
|
|
Curve* height_curve;
|
|
|
|
Curve* slope_curve;
|
2012-04-05 20:09:39 +00:00
|
|
|
} TextureSupp;
|
|
|
|
static TextureSupp _supp;
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
/**************** Previews ****************/
|
2012-04-03 19:33:40 +00:00
|
|
|
class PreviewTexturesCoverage:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTexturesCoverage(QWidget* parent):BasePreview(parent)
|
|
|
|
{
|
2012-04-05 17:47:43 +00:00
|
|
|
_terrain = terrainCreateDefinition();
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
2012-04-05 17:47:43 +00:00
|
|
|
_renderer.getTerrainHeight = _getTerrainHeight;
|
|
|
|
_renderer.customData[0] = &_terrain;
|
2012-04-03 19:33:40 +00:00
|
|
|
|
|
|
|
_preview_layer = texturesLayerCreateDefinition();
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2012-06-26 19:36:50 +00:00
|
|
|
addOsd(QString("geolocation"));
|
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
configScaling(0.5, 200.0, 1.0, 50.0);
|
2012-04-15 20:08:01 +00:00
|
|
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
protected:
|
2012-06-17 09:40:40 +00:00
|
|
|
QColor getColor(double x, double y)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-04-05 17:47:43 +00:00
|
|
|
Vector3 location;
|
2012-06-17 09:40:40 +00:00
|
|
|
double coverage;
|
2012-04-05 17:47:43 +00:00
|
|
|
location.x = x;
|
|
|
|
location.y = terrainGetHeight(&_terrain, x, y);
|
|
|
|
location.z = y;
|
|
|
|
coverage = texturesGetLayerCoverage(&_preview_layer, &_renderer, location, this->scaling);
|
|
|
|
return QColor::fromRgbF(coverage, coverage, coverage, 1.0);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-04-05 17:47:43 +00:00
|
|
|
sceneryGetTerrain(&_terrain);
|
2012-04-03 19:33:40 +00:00
|
|
|
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-06-17 09:40:40 +00:00
|
|
|
static double _getTerrainHeight(Renderer* renderer, double x, double z)
|
2012-04-05 17:47:43 +00:00
|
|
|
{
|
|
|
|
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
|
|
|
|
}
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
Renderer _renderer;
|
|
|
|
TextureLayerDefinition _preview_layer;
|
2012-04-05 17:47:43 +00:00
|
|
|
TerrainDefinition _terrain;
|
2012-04-03 19:33:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PreviewTexturesColor:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTexturesColor(QWidget* parent):BasePreview(parent)
|
|
|
|
{
|
2012-04-05 16:16:32 +00:00
|
|
|
LightDefinition light;
|
|
|
|
|
|
|
|
_preview_layer = texturesLayerCreateDefinition();
|
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
|
|
|
light.color = COLOR_WHITE;
|
|
|
|
light.direction.x = 0.0;
|
|
|
|
light.direction.y = -0.4794;
|
|
|
|
light.direction.z = 0.8776;
|
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 0;
|
|
|
|
light.reflection = 1.0;
|
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
lightingValidateDefinition(&_lighting);
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.getLightStatus = _getLightStatus;
|
2012-04-05 16:16:32 +00:00
|
|
|
_renderer.customData[0] = &_lighting;
|
2012-04-09 08:33:13 +00:00
|
|
|
_renderer.camera_location.x = 0.0;
|
|
|
|
_renderer.camera_location.y = 20.0;
|
|
|
|
_renderer.camera_location.z = 0.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2012-04-27 20:05:33 +00:00
|
|
|
_zone = zoneCreate();
|
|
|
|
|
2012-05-06 10:13:34 +00:00
|
|
|
configScaling(0.01, 1.0, 0.01, 0.1);
|
2012-04-15 20:08:01 +00:00
|
|
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
protected:
|
2012-06-17 09:40:40 +00:00
|
|
|
QColor getColor(double x, double y)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-04-05 16:16:32 +00:00
|
|
|
Vector3 location;
|
2012-04-12 20:02:31 +00:00
|
|
|
location.x = x;
|
2012-04-05 16:16:32 +00:00
|
|
|
location.y = 0.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
location.z = y;
|
|
|
|
return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling));
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
2012-04-27 20:05:33 +00:00
|
|
|
zoneCopy(_zone, _preview_layer.zone);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
private:
|
2012-04-27 20:05:33 +00:00
|
|
|
Zone* _zone;
|
2012-04-03 19:33:40 +00:00
|
|
|
Renderer _renderer;
|
|
|
|
TextureLayerDefinition _preview_layer;
|
2012-04-05 16:16:32 +00:00
|
|
|
LightingDefinition _lighting;
|
2012-06-05 20:22:12 +00:00
|
|
|
|
|
|
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
|
|
|
{
|
|
|
|
lightingGetStatus((LightingDefinition*)renderer->customData[0], renderer, location, status);
|
|
|
|
}
|
2012-04-03 19:33:40 +00:00
|
|
|
};
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
/**************** Form ****************/
|
|
|
|
FormTextures::FormTextures(QWidget *parent):
|
2012-04-03 19:33:40 +00:00
|
|
|
BaseForm(parent, false, true)
|
2012-01-26 23:08:09 +00:00
|
|
|
{
|
|
|
|
_definition = texturesCreateDefinition();
|
2012-04-03 19:33:40 +00:00
|
|
|
_layer = texturesLayerCreateDefinition();
|
2012-07-02 15:35:10 +00:00
|
|
|
_supp.height_curve = curveCreate();
|
|
|
|
_supp.slope_curve = curveCreate();
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
previewCoverage = new PreviewTexturesCoverage(this);
|
|
|
|
previewColor = new PreviewTexturesColor(this);
|
2012-04-05 17:47:43 +00:00
|
|
|
addPreview(previewCoverage, tr("Coverage preview"));
|
|
|
|
addPreview(previewColor, tr("Lighted sample"));
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
addInputNoise(tr("Surface noise"), _layer.bump_noise);
|
2012-07-03 16:26:13 +00:00
|
|
|
addInputDouble(tr("Surface noise height"), &_layer.bump_height, 0.0, 0.1, 0.001, 0.01);
|
|
|
|
addInputDouble(tr("Surface noise scaling"), &_layer.bump_scaling, 0.001, 0.1, 0.001, 0.01);
|
2012-06-02 09:46:24 +00:00
|
|
|
addInputMaterial(tr("Material"), &_layer.material);
|
2012-07-02 15:35:10 +00:00
|
|
|
addInputCurve(tr("Coverage by altitude"), _supp.height_curve, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
|
|
|
|
addInputCurve(tr("Coverage by slope"), _supp.slope_curve, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));
|
2012-07-03 16:26:13 +00:00
|
|
|
addInputDouble(tr("Amplitude for slope coverage"), &_layer.slope_range, 0.001, 0.1, 0.001, 0.01);
|
|
|
|
addInputDouble(tr("Layer thickness"), &_layer.thickness, 0.0, 0.1, 0.001, 0.01);
|
|
|
|
addInputDouble(tr("Transparency thickness"), &_layer.thickness_transparency, 0.0, 0.1, 0.001, 0.01);
|
2012-04-05 20:09:39 +00:00
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
2012-07-02 15:35:10 +00:00
|
|
|
FormTextures::~FormTextures()
|
|
|
|
{
|
|
|
|
texturesDeleteDefinition(&_definition);
|
|
|
|
texturesLayerDeleteDefinition(&_layer);
|
|
|
|
curveDelete(_supp.height_curve);
|
|
|
|
curveDelete(_supp.slope_curve);
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
void FormTextures::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetTextures(&_definition);
|
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::applyConfig()
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
configChangeEvent();
|
2012-01-26 23:08:09 +00:00
|
|
|
scenerySetTextures(&_definition);
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::configChangeEvent()
|
|
|
|
{
|
2012-04-03 19:33:40 +00:00
|
|
|
texturesLayerCopyDefinition(&_layer, texturesGetLayer(&_definition, currentLayer()));
|
2012-04-05 20:09:39 +00:00
|
|
|
|
2012-07-02 15:35:10 +00:00
|
|
|
zoneSetHeightCurve(_layer.zone, _supp.height_curve);
|
|
|
|
zoneSetSlopeCurve(_layer.zone, _supp.slope_curve);
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
texturesValidateDefinition(&_definition);
|
|
|
|
BaseForm::configChangeEvent();
|
|
|
|
}
|
2012-04-03 19:33:40 +00:00
|
|
|
|
2012-07-05 17:05:03 +00:00
|
|
|
QStringList FormTextures::getLayers()
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
TextureLayerDefinition* layer;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
n = texturesGetLayerCount(&_definition);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
layer = texturesGetLayer(&_definition, i);
|
|
|
|
result << QString(layer->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
void FormTextures::layerAddedEvent()
|
|
|
|
{
|
|
|
|
if (texturesAddLayer(&_definition) >= 0)
|
|
|
|
{
|
|
|
|
BaseForm::layerAddedEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::layerDeletedEvent(int layer)
|
|
|
|
{
|
|
|
|
texturesDeleteLayer(&_definition, layer);
|
|
|
|
|
|
|
|
BaseForm::layerDeletedEvent(layer);
|
|
|
|
}
|
|
|
|
|
2012-07-05 15:01:58 +00:00
|
|
|
void FormTextures::layerMovedEvent(int layer, int new_position)
|
|
|
|
{
|
|
|
|
texturesMoveLayer(&_definition, layer, new_position);
|
|
|
|
|
|
|
|
BaseForm::layerMovedEvent(layer, new_position);
|
|
|
|
}
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
void FormTextures::layerSelectedEvent(int layer)
|
|
|
|
{
|
|
|
|
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);
|
|
|
|
|
2012-07-02 15:35:10 +00:00
|
|
|
zoneGetHeightCurve(_layer.zone, _supp.height_curve);
|
|
|
|
zoneGetSlopeCurve(_layer.zone, _supp.slope_curve);
|
2012-04-05 20:09:39 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
BaseForm::layerSelectedEvent(layer);
|
|
|
|
}
|