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
|
|
|
|
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:
|
2012-08-26 13:06:42 +00:00
|
|
|
PreviewTexturesCoverage(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
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
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
_original_layer = layer;
|
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
|
|
|
}
|
2012-08-26 13:06:42 +00:00
|
|
|
~PreviewTexturesCoverage()
|
|
|
|
{
|
|
|
|
texturesLayerDeleteDefinition(_preview_layer);
|
|
|
|
}
|
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;
|
2012-08-26 13:06:42 +00:00
|
|
|
coverage = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling);
|
2012-04-05 17:47:43 +00:00
|
|
|
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-08-26 13:06:42 +00:00
|
|
|
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-08-26 13:06:42 +00:00
|
|
|
TextureLayerDefinition* _original_layer;
|
|
|
|
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:
|
2012-08-26 13:06:42 +00:00
|
|
|
PreviewTexturesColor(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-04-05 16:16:32 +00:00
|
|
|
LightDefinition light;
|
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
_original_layer = layer;
|
2012-04-05 16:16:32 +00:00
|
|
|
_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
|
|
|
}
|
2012-08-26 13:06:42 +00:00
|
|
|
~PreviewTexturesColor()
|
|
|
|
{
|
|
|
|
texturesLayerDeleteDefinition(_preview_layer);
|
|
|
|
}
|
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;
|
2012-08-26 13:06:42 +00:00
|
|
|
return colorToQColor(texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling));
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
|
|
|
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;
|
2012-08-26 13:06:42 +00:00
|
|
|
TextureLayerDefinition* _original_layer;
|
|
|
|
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-08-26 13:06:42 +00:00
|
|
|
BaseFormLayer(parent)
|
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-08-26 13:06:42 +00:00
|
|
|
previewCoverage = new PreviewTexturesCoverage(this, _layer);
|
|
|
|
previewColor = new PreviewTexturesColor(this, _layer);
|
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-08-26 13:06:42 +00:00
|
|
|
addInputNoise(tr("Surface noise"), _layer->bump_noise);
|
|
|
|
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);
|
|
|
|
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-08-26 13:06:42 +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-08-26 13:06:42 +00:00
|
|
|
setLayers(_definition.layers);
|
2012-01-26 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 15:35:10 +00:00
|
|
|
FormTextures::~FormTextures()
|
|
|
|
{
|
|
|
|
texturesDeleteDefinition(&_definition);
|
2012-08-26 13:06:42 +00:00
|
|
|
texturesLayerDeleteDefinition(_layer);
|
2012-07-02 15:35:10 +00:00
|
|
|
curveDelete(_supp.height_curve);
|
|
|
|
curveDelete(_supp.slope_curve);
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
void FormTextures::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetTextures(&_definition);
|
2012-08-26 13:06:42 +00:00
|
|
|
BaseFormLayer::revertConfig();
|
2012-01-26 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::applyConfig()
|
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
BaseFormLayer::applyConfig();
|
2012-01-26 23:08:09 +00:00
|
|
|
scenerySetTextures(&_definition);
|
2012-07-05 17:05:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
void FormTextures::layerGetCopy(void* layer_definition)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
texturesLayerCopyDefinition((TextureLayerDefinition*)layer_definition, _layer);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
void FormTextures::layerApply(void* layer_definition)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-08-26 13:06:42 +00:00
|
|
|
texturesLayerCopyDefinition(_layer, (TextureLayerDefinition*)layer_definition);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|