2012-01-26 23:08:09 +00:00
|
|
|
#include "formclouds.h"
|
|
|
|
|
|
|
|
#include "../lib_paysages/clouds.h"
|
2012-02-05 11:31:16 +00:00
|
|
|
#include "../lib_paysages/color.h"
|
|
|
|
#include "../lib_paysages/euclid.h"
|
2012-01-26 23:08:09 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
#include "tools.h"
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
/**************** Previews ****************/
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewCloudsCoverage:public BasePreview
|
2012-02-05 11:31:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-26 13:36:46 +00:00
|
|
|
PreviewCloudsCoverage(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent)
|
2012-02-05 11:31:16 +00:00
|
|
|
{
|
|
|
|
_renderer = rendererCreate();
|
2012-08-27 20:40:35 +00:00
|
|
|
_renderer.render_quality = 5;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.applyLightStatus = _applyLightStatus;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-08-26 13:36:46 +00:00
|
|
|
_original_layer = layer;
|
2012-02-05 11:31:16 +00:00
|
|
|
_preview_layer = cloudsLayerCreateDefinition();
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
configScaling(100.0, 1000.0, 20.0, 200.0);
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
2012-08-26 13:36:46 +00:00
|
|
|
~PreviewCloudsCoverage()
|
|
|
|
{
|
|
|
|
cloudsLayerDeleteDefinition(_preview_layer);
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
protected:
|
2013-01-16 14:26:46 +00:00
|
|
|
Color getColor(double x, double y)
|
2012-02-05 11:31:16 +00:00
|
|
|
{
|
|
|
|
Vector3 eye, look;
|
|
|
|
|
|
|
|
eye.x = 0.0;
|
|
|
|
eye.y = scaling;
|
|
|
|
eye.z = -10.0 * scaling;
|
|
|
|
look.x = x * 0.01 / scaling;
|
|
|
|
look.y = -y * 0.01 / scaling - 0.3;
|
|
|
|
look.z = 1.0;
|
|
|
|
look = v3Normalize(look);
|
|
|
|
|
2013-01-16 14:26:46 +00:00
|
|
|
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0)));
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-08-26 13:36:46 +00:00
|
|
|
cloudsLayerCopyDefinition(_original_layer, _preview_layer);
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
2012-12-24 15:15:40 +00:00
|
|
|
static Color _applyLightStatus(Renderer*, LightStatus*, Vector3, Vector3, SurfaceMaterial)
|
2012-06-05 20:22:12 +00:00
|
|
|
{
|
|
|
|
return COLOR_WHITE;
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Renderer _renderer;
|
2012-08-26 13:36:46 +00:00
|
|
|
CloudsLayerDefinition* _original_layer;
|
|
|
|
CloudsLayerDefinition* _preview_layer;
|
2012-02-05 11:31:16 +00:00
|
|
|
};
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewCloudsColor:public BasePreview
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-26 13:36:46 +00:00
|
|
|
PreviewCloudsColor(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
|
|
|
LightDefinition light;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-08-26 13:36:46 +00:00
|
|
|
_original_layer = layer;
|
2012-02-08 14:24:53 +00:00
|
|
|
_preview_layer = cloudsLayerCreateDefinition();
|
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
|
|
|
light.color = COLOR_WHITE;
|
2012-02-08 21:20:28 +00:00
|
|
|
light.direction.x = -1.0;
|
|
|
|
light.direction.y = -1.0;
|
|
|
|
light.direction.z = 1.0;
|
|
|
|
light.direction = v3Normalize(light.direction);
|
2012-02-08 14:24:53 +00:00
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 1;
|
|
|
|
light.reflection = 1.0;
|
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
lightingValidateDefinition(&_lighting);
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-02-08 14:24:53 +00:00
|
|
|
_renderer = rendererCreate();
|
2012-08-27 20:40:35 +00:00
|
|
|
_renderer.render_quality = 8;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.alterLight = _alterLight;
|
|
|
|
_renderer.getLightStatus = _getLightStatus;
|
2012-08-26 13:36:46 +00:00
|
|
|
_renderer.customData[0] = _preview_layer;
|
2012-02-08 14:24:53 +00:00
|
|
|
_renderer.customData[1] = &_lighting;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-07-01 13:27:57 +00:00
|
|
|
configScaling(0.5, 2.0, 0.1, 2.0);
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
|
|
|
protected:
|
2013-01-16 14:26:46 +00:00
|
|
|
Color getColor(double x, double y)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
|
|
|
Vector3 start, end;
|
|
|
|
|
2012-08-26 13:36:46 +00:00
|
|
|
start.x = x * _preview_layer->thickness * 0.5;
|
|
|
|
start.y = -y * _preview_layer->thickness * 0.5;
|
|
|
|
start.z = _preview_layer->thickness * 0.5;
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-08-26 13:36:46 +00:00
|
|
|
end.x = x * _preview_layer->thickness * 0.5;
|
|
|
|
end.y = -y * _preview_layer->thickness * 0.5;
|
|
|
|
end.z = -_preview_layer->thickness * 0.5;
|
2012-02-08 14:24:53 +00:00
|
|
|
|
2013-01-16 14:26:46 +00:00
|
|
|
return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end);
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-08-26 13:36:46 +00:00
|
|
|
cloudsLayerCopyDefinition(_original_layer, _preview_layer);
|
2012-08-27 20:40:35 +00:00
|
|
|
//noiseForceValue(_preview_layer->shape_noise, 1.0);
|
2012-08-26 13:36:46 +00:00
|
|
|
_preview_layer->lower_altitude = -_preview_layer->thickness * 0.5;
|
2012-08-27 20:40:35 +00:00
|
|
|
//curveClear(_preview_layer->coverage_by_altitude);
|
2012-08-26 13:36:46 +00:00
|
|
|
_preview_layer->base_coverage = 1.0;
|
|
|
|
_preview_layer->_custom_coverage = _coverageFunc;
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
Renderer _renderer;
|
2012-08-26 13:36:46 +00:00
|
|
|
CloudsLayerDefinition* _original_layer;
|
|
|
|
CloudsLayerDefinition* _preview_layer;
|
2012-02-08 14:24:53 +00:00
|
|
|
LightingDefinition _lighting;
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
2012-12-05 15:35:25 +00:00
|
|
|
double coverage = curveGetValue(layer->_coverage_by_altitude, position.y / layer->thickness + 0.5);
|
2012-07-01 13:27:57 +00:00
|
|
|
position.y = 0.0;
|
2012-06-17 09:40:40 +00:00
|
|
|
double dist = v3Norm(position);
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-07-01 13:27:57 +00:00
|
|
|
if (dist >= layer->thickness * 0.5)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
2012-11-24 12:30:51 +00:00
|
|
|
else if (dist < layer->thickness * 0.4)
|
|
|
|
{
|
|
|
|
return coverage;
|
|
|
|
}
|
2012-02-08 14:24:53 +00:00
|
|
|
else
|
|
|
|
{
|
2012-11-24 12:30:51 +00:00
|
|
|
double density = 1.0 - (dist - (layer->thickness * 0.4)) / (layer->thickness * 0.1);
|
2012-07-01 13:27:57 +00:00
|
|
|
return (density < coverage) ? density : coverage;
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
light->color = cloudsLayerFilterLight((CloudsLayerDefinition*)renderer->customData[0], renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0));
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status);
|
2012-02-08 14:24:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
/**************** Form ****************/
|
|
|
|
FormClouds::FormClouds(QWidget *parent):
|
2012-08-26 13:36:46 +00:00
|
|
|
BaseFormLayer(parent)
|
2012-01-26 23:08:09 +00:00
|
|
|
{
|
2012-11-24 12:30:51 +00:00
|
|
|
addAutoPreset(tr("Cirrus"));
|
2012-11-24 16:04:33 +00:00
|
|
|
addAutoPreset(tr("Cumulus"));
|
|
|
|
addAutoPreset(tr("Stratocumulus"));
|
2012-11-24 12:30:51 +00:00
|
|
|
addAutoPreset(tr("Stratus"));
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
_definition = cloudsCreateDefinition();
|
2012-02-05 11:31:16 +00:00
|
|
|
_layer = cloudsLayerCreateDefinition();
|
2012-12-06 14:04:04 +00:00
|
|
|
|
2012-08-26 13:36:46 +00:00
|
|
|
_previewCoverage = new PreviewCloudsCoverage(parent, _layer);
|
|
|
|
_previewColor = new PreviewCloudsColor(parent, _layer);
|
|
|
|
addPreview(_previewCoverage, tr("Layer coverage (no lighting)"));
|
|
|
|
addPreview(_previewColor, tr("Appearance"));
|
|
|
|
|
2012-12-05 15:35:25 +00:00
|
|
|
addInputEnum(tr("Clouds model"), (int*)&_layer->type, QStringList() << tr("Cirrus") << tr("Cumulus") << tr("Stratocumulus") << tr("Stratus"));
|
2012-08-26 13:36:46 +00:00
|
|
|
addInputDouble(tr("Lower altitude"), &_layer->lower_altitude, -10.0, 50.0, 0.5, 5.0);
|
|
|
|
addInputDouble(tr("Layer thickness"), &_layer->thickness, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputDouble(tr("Max coverage"), &_layer->base_coverage, 0.0, 1.0, 0.01, 0.1);
|
2012-12-05 15:35:25 +00:00
|
|
|
// addInputCurve(tr("Coverage by altitude"), _layer->_coverage_by_altitude, 0.0, 1.0, 0.0, 1.0, tr("Altitude in cloud layer"), tr("Coverage value"));
|
|
|
|
// addInputNoise(tr("Shape noise"), _layer->_shape_noise);
|
2012-08-26 20:02:10 +00:00
|
|
|
addInputDouble(tr("Shape scaling"), &_layer->shape_scaling, 3.0, 30.0, 0.3, 3.0);
|
2012-12-05 15:35:25 +00:00
|
|
|
// addInputNoise(tr("Edge noise"), _layer->_edge_noise);
|
2012-11-24 12:30:51 +00:00
|
|
|
addInputDouble(tr("Edge scaling"), &_layer->edge_scaling, 0.5, 5.0, 0.05, 0.5);
|
2012-08-26 13:36:46 +00:00
|
|
|
addInputDouble(tr("Edge length"), &_layer->edge_length, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
addInputMaterial(tr("Material"), &_layer->material);
|
|
|
|
addInputDouble(tr("Hardness to light"), &_layer->hardness, 0.0, 1.0, 0.01, 0.1);
|
2012-08-27 20:40:35 +00:00
|
|
|
addInputDouble(tr("Transparency depth"), &_layer->transparencydepth, 0.0, 10.0, 0.1, 1.0);
|
|
|
|
addInputDouble(tr("Light traversal depth"), &_layer->lighttraversal, 0.0, 10.0, 0.1, 1.0);
|
2012-08-26 13:36:46 +00:00
|
|
|
addInputDouble(tr("Minimum lighting"), &_layer->minimumlight, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
|
|
|
|
setLayers(_definition.layers);
|
2012-01-26 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetClouds(&_definition);
|
2012-08-26 13:36:46 +00:00
|
|
|
BaseFormLayer::revertConfig();
|
2012-01-26 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::applyConfig()
|
|
|
|
{
|
2012-08-26 13:36:46 +00:00
|
|
|
BaseFormLayer::applyConfig();
|
2012-01-26 23:08:09 +00:00
|
|
|
scenerySetClouds(&_definition);
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
|
2012-12-05 15:35:25 +00:00
|
|
|
void FormClouds::configChangeEvent()
|
|
|
|
{
|
|
|
|
cloudsLayerValidateDefinition(_layer);
|
2012-12-06 14:04:04 +00:00
|
|
|
BaseFormLayer::configChangeEvent();
|
2012-12-05 15:35:25 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:04:04 +00:00
|
|
|
void FormClouds::layerReadCurrentFrom(void* layer_definition)
|
2012-07-05 17:05:03 +00:00
|
|
|
{
|
2012-08-26 13:36:46 +00:00
|
|
|
cloudsLayerCopyDefinition((CloudsLayerDefinition*)layer_definition, _layer);
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:04:04 +00:00
|
|
|
void FormClouds::layerWriteCurrentTo(void* layer_definition)
|
2012-07-05 15:01:58 +00:00
|
|
|
{
|
2012-08-26 13:36:46 +00:00
|
|
|
cloudsLayerCopyDefinition(_layer, (CloudsLayerDefinition*)layer_definition);
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
2012-11-24 12:30:51 +00:00
|
|
|
|
|
|
|
void FormClouds::autoPresetSelected(int preset)
|
|
|
|
{
|
|
|
|
cloudsLayerAutoPreset(_layer, (CloudsPreset)preset);
|
|
|
|
BaseForm::autoPresetSelected(preset);
|
|
|
|
}
|
|
|
|
|