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-12-09 17:49:28 +00:00
|
|
|
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
_renderer = rendererCreate();
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->render_quality = 3;
|
2012-12-06 14:04:04 +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-12-06 14:04:04 +00:00
|
|
|
|
2012-06-26 19:36:50 +00:00
|
|
|
addOsd(QString("geolocation"));
|
2012-12-06 14:04:04 +00:00
|
|
|
|
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:
|
2013-01-16 14:26:46 +00:00
|
|
|
Color getColor(double x, double y)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-04-05 17:47:43 +00:00
|
|
|
Vector3 location;
|
2013-01-16 14:26:46 +00:00
|
|
|
Color result;
|
2012-04-05 17:47:43 +00:00
|
|
|
location.x = x;
|
2013-01-20 15:07:45 +00:00
|
|
|
location.y = _renderer->terrain->getHeight(_renderer, x, y, 1);
|
2012-04-05 17:47:43 +00:00
|
|
|
location.z = y;
|
2013-01-20 15:07:45 +00:00
|
|
|
result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, _renderer, location, this->scaling);
|
2013-01-16 14:26:46 +00:00
|
|
|
return result;
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
sceneryGetTerrain(_terrain);
|
2013-01-20 15:07:45 +00:00
|
|
|
TerrainRendererClass.bind(_renderer, _terrain);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-08-26 13:06:42 +00:00
|
|
|
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* _renderer;
|
2012-08-26 13:06:42 +00:00
|
|
|
TextureLayerDefinition* _original_layer;
|
|
|
|
TextureLayerDefinition* _preview_layer;
|
2012-12-09 17:49:28 +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();
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2013-01-19 22:42:50 +00:00
|
|
|
/*_lighting = lightingCreateDefinition();
|
2012-04-05 16:16:32 +00:00
|
|
|
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);
|
2013-01-19 22:42:50 +00:00
|
|
|
lightingValidateDefinition(&_lighting);*/
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
_renderer = rendererCreate();
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->render_quality = 3;
|
|
|
|
/*_renderer->getLightStatus = _getLightStatus;
|
|
|
|
_renderer->customData[0] = &_lighting;*/
|
|
|
|
_renderer->camera_location.x = 0.0;
|
|
|
|
_renderer->camera_location.y = 20.0;
|
|
|
|
_renderer->camera_location.z = 0.0;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-04-27 20:05:33 +00:00
|
|
|
_zone = zoneCreate();
|
2012-12-06 14:04:04 +00:00
|
|
|
|
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:
|
2013-01-16 14:26:46 +00:00
|
|
|
Color 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;
|
2013-01-20 15:07:45 +00:00
|
|
|
return 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;
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* _renderer;
|
2012-08-26 13:06:42 +00:00
|
|
|
TextureLayerDefinition* _original_layer;
|
|
|
|
TextureLayerDefinition* _preview_layer;
|
2013-01-19 22:42:50 +00:00
|
|
|
//LightingDefinition _lighting;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2013-01-19 22:42:50 +00:00
|
|
|
/*static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
2012-06-05 20:22:12 +00:00
|
|
|
{
|
|
|
|
lightingGetStatus((LightingDefinition*)renderer->customData[0], renderer, location, status);
|
2013-01-19 22:42:50 +00:00
|
|
|
}*/
|
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:36:46 +00:00
|
|
|
_previewCoverage = new PreviewTexturesCoverage(this, _layer);
|
|
|
|
_previewColor = new PreviewTexturesColor(this, _layer);
|
|
|
|
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);
|
2012-08-26 20:02:10 +00:00
|
|
|
addInputDouble(tr("Surface noise scaling"), &_layer->bump_scaling, 0.003, 0.3, 0.003, 0.03);
|
2012-08-26 13:06:42 +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-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-12-06 14:04:04 +00:00
|
|
|
void FormTextures::layerReadCurrentFrom(void* layer_definition)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
TextureLayerDefinition* source = (TextureLayerDefinition*)layer_definition;
|
|
|
|
texturesLayerCopyDefinition(source, _layer);
|
|
|
|
|
|
|
|
zoneGetHeightCurve(source->zone, _supp.height_curve);
|
|
|
|
zoneGetSlopeCurve(source->zone, _supp.slope_curve);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:04:04 +00:00
|
|
|
void FormTextures::layerWriteCurrentTo(void* layer_definition)
|
2012-04-03 19:33:40 +00:00
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
TextureLayerDefinition* destination = (TextureLayerDefinition*)layer_definition;
|
|
|
|
texturesLayerCopyDefinition(_layer, destination);
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
zoneSetHeightCurve(destination->zone, _supp.height_curve);
|
|
|
|
zoneSetSlopeCurve(destination->zone, _supp.slope_curve);
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|