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 "../lib_paysages/shared/constants.h"
|
|
|
|
|
|
|
|
#include "tools.h"
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
static CloudsDefinition _definition;
|
2012-02-05 11:31:16 +00:00
|
|
|
static CloudsLayerDefinition _layer;
|
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-02-21 13:41:02 +00:00
|
|
|
PreviewCloudsCoverage(QWidget* parent):BasePreview(parent)
|
2012-02-05 11:31:16 +00:00
|
|
|
{
|
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
|
|
|
|
|
|
|
_preview_layer = cloudsLayerCreateDefinition();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
Vector3 eye, look;
|
|
|
|
Color color_layer, result;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
result = COLOR_BLUE;
|
|
|
|
color_layer = cloudsGetLayerColor(&_preview_layer, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0)));
|
|
|
|
colorMask(&result, &color_layer);
|
|
|
|
return colorToQColor(result);
|
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
cloudsLayerCopyDefinition(&_layer, &_preview_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Renderer _renderer;
|
|
|
|
CloudsLayerDefinition _preview_layer;
|
|
|
|
};
|
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-02-21 13:41:02 +00:00
|
|
|
PreviewCloudsColor(QWidget* parent):BasePreview(parent)
|
2012-02-08 14:24:53 +00:00
|
|
|
{
|
|
|
|
LightDefinition light;
|
|
|
|
|
|
|
|
_preview_layer = cloudsLayerCreateDefinition();
|
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
|
|
|
light.color = COLOR_WHITE;
|
|
|
|
light.amplitude = 0.0;
|
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);
|
|
|
|
|
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
|
|
|
_renderer.applyLightingToSurface = _applyLightingToSurface;
|
|
|
|
_renderer.maskLight = _maskLight;
|
|
|
|
_renderer.customData[0] = &_preview_layer;
|
|
|
|
_renderer.customData[1] = &_lighting;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
Vector3 start, end;
|
|
|
|
Color color_layer, result;
|
|
|
|
|
|
|
|
start.x = x;
|
2012-02-08 21:20:28 +00:00
|
|
|
start.y = -y;
|
|
|
|
start.z = 100.0;
|
2012-02-08 14:24:53 +00:00
|
|
|
|
|
|
|
end.x = x;
|
2012-02-08 21:20:28 +00:00
|
|
|
end.y = -y;
|
|
|
|
end.z = -100.0;
|
2012-02-08 14:24:53 +00:00
|
|
|
|
|
|
|
result = COLOR_BLUE;
|
|
|
|
color_layer = cloudsGetLayerColor(&_preview_layer, &_renderer, start, end);
|
|
|
|
colorMask(&result, &color_layer);
|
|
|
|
return colorToQColor(result);
|
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
cloudsLayerCopyDefinition(&_layer, &_preview_layer);
|
|
|
|
_preview_layer.ymin = -100.0;
|
|
|
|
_preview_layer.ycenter = 0.0;
|
|
|
|
_preview_layer.ymax = 100.0;
|
|
|
|
_preview_layer.customcoverage = _coverageFunc;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Renderer _renderer;
|
|
|
|
CloudsLayerDefinition _preview_layer;
|
|
|
|
LightingDefinition _lighting;
|
|
|
|
|
|
|
|
static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
|
|
|
|
{
|
|
|
|
double dist = v3Norm(position);
|
|
|
|
|
|
|
|
if (dist >= 100.0)
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1.0 - dist / 100.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
|
|
|
|
{
|
|
|
|
return lightingApplyToSurface((LightingDefinition*)renderer->customData[1], renderer, location, normal, material);
|
|
|
|
}
|
|
|
|
static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light)
|
|
|
|
{
|
|
|
|
return cloudsLayerFilterLight((CloudsLayerDefinition*)renderer->customData[0], renderer, light_color, at_location, light_location, direction_to_light);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-26 23:08:09 +00:00
|
|
|
/**************** Form ****************/
|
|
|
|
FormClouds::FormClouds(QWidget *parent):
|
2012-02-05 11:31:16 +00:00
|
|
|
BaseForm(parent, false, true)
|
2012-01-26 23:08:09 +00:00
|
|
|
{
|
|
|
|
_definition = cloudsCreateDefinition();
|
2012-02-05 11:31:16 +00:00
|
|
|
_layer = cloudsLayerCreateDefinition();
|
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
addPreview(new PreviewCloudsCoverage(parent), tr("Layer coverage (no lighting)"));
|
|
|
|
addPreview(new PreviewCloudsColor(parent), tr("Color and lighting"));
|
|
|
|
|
|
|
|
addInputDouble(tr("Start altitude"), &_layer.ymin, -10.0, 250.0, 0.5, 5.0);
|
|
|
|
addInputDouble(tr("Max density altitude"), &_layer.ycenter, -10.0, 250.0, 0.5, 5.0);
|
|
|
|
addInputDouble(tr("End altitude"), &_layer.ymax, -10.0, 250.0, 0.5, 5.0);
|
|
|
|
addInputNoise(tr("Noise"), _layer.noise);
|
|
|
|
addInputDouble(tr("Coverage"), &_layer.coverage, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
addInputDouble(tr("Scaling"), &_layer.scaling, 1.0, 100.0, 0.5, 5.0);
|
|
|
|
addInputColor(tr("Base color"), &_layer.material.base);
|
|
|
|
addInputDouble(tr("Light reflection"), &_layer.material.reflection, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
addInputDouble(tr("Light reflection shininess"), &_layer.material.shininess, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputDouble(tr("Transparency depth"), &_layer.transparencydepth, 0.0, 100.0, 0.5, 5.0);
|
|
|
|
addInputDouble(tr("Light traversal depth"), &_layer.lighttraversal, 0.0, 100.0, 0.5, 5.0);
|
|
|
|
addInputDouble(tr("Minimum lighting"), &_layer.minimumlight, 0.0, 1.0, 0.01, 0.1);
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetClouds(&_definition);
|
2012-02-05 11:31:16 +00:00
|
|
|
setLayerCount(cloudsGetLayerCount(&_definition));
|
2012-01-26 23:08:09 +00:00
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::applyConfig()
|
|
|
|
{
|
|
|
|
scenerySetClouds(&_definition);
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::configChangeEvent()
|
|
|
|
{
|
2012-02-05 11:31:16 +00:00
|
|
|
cloudsLayerCopyDefinition(&_layer, cloudsGetLayer(&_definition, currentLayer()));
|
2012-01-26 23:08:09 +00:00
|
|
|
cloudsValidateDefinition(&_definition);
|
|
|
|
BaseForm::configChangeEvent();
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
void FormClouds::layerAddedEvent()
|
|
|
|
{
|
2012-02-08 21:20:28 +00:00
|
|
|
if (cloudsAddLayer(&_definition) >= 0)
|
2012-02-05 11:31:16 +00:00
|
|
|
{
|
|
|
|
BaseForm::layerAddedEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::layerDeletedEvent(int layer)
|
|
|
|
{
|
|
|
|
cloudsDeleteLayer(&_definition, layer);
|
|
|
|
|
|
|
|
BaseForm::layerDeletedEvent(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormClouds::layerSelectedEvent(int layer)
|
|
|
|
{
|
|
|
|
cloudsLayerCopyDefinition(cloudsGetLayer(&_definition, layer), &_layer);
|
|
|
|
|
|
|
|
BaseForm::layerSelectedEvent(layer);
|
|
|
|
}
|