paysages3d/gui_qt/formsky.cpp

104 lines
2.4 KiB
C++

#include "formsky.h"
#include "tools.h"
#include <QColor>
#include <QSlider>
#include <math.h>
#include "../lib_paysages/sky.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/shared/constants.h"
static SkyDefinition _definition;
/**************** Previews ****************/
class PreviewEast:public Preview
{
public:
PreviewEast(QWidget* parent):
Preview(parent)
{
_renderer = rendererGetFake();
}
protected:
QColor getColor(double x, double y)
{
Vector3 eye = {0.0, 0.0, 0.0};
Vector3 look;
look.x = 100.0;
look.y = -y;
look.z = x;
return colorToQColor(skyGetColor(&_definition, &_renderer, eye, look));
}
private:
Renderer _renderer;
};
class PreviewWest:public Preview
{
public:
PreviewWest(QWidget* parent):
Preview(parent)
{
_renderer = rendererGetFake();
}
protected:
QColor getColor(double x, double y)
{
Vector3 eye = {0.0, 0.0, 0.0};
Vector3 look;
look.x = -100.0;
look.y = -y;
look.z = -x;
return colorToQColor(skyGetColor(&_definition, &_renderer, eye, look));
}
private:
Renderer _renderer;
};
/**************** Form ****************/
FormSky::FormSky(QWidget *parent):
BaseForm(parent)
{
_definition = skyCreateDefinition();
previewWest = new PreviewWest(this);
addPreview(previewWest, QString("West preview"));
previewEast = new PreviewEast(this);
addPreview(previewEast, QString("East preview"));
addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1);
addInputColorGradation("Sun color", &_definition.sun_color);
addInputDouble("Sun radius", &_definition.sun_radius, 0.0, 0.3, 0.01, 0.03);
addInputColorGradation("Zenith color", &_definition.zenith_color);
addInputColorGradation("Haze color", &_definition.haze_color);
addInputDouble("Haze height", &_definition.haze_height, 0.0, 1.0, 0.01, 0.1);
addInputDouble("Haze smoothing", &_definition.haze_smoothing, 0.0, 1.0, 0.01, 0.1);
revertConfig();
}
void FormSky::revertConfig()
{
sceneryGetSky(&_definition);
BaseForm::revertConfig();
}
void FormSky::applyConfig()
{
scenerySetSky(&_definition);
BaseForm::applyConfig();
}
void FormSky::applyConfigPreview()
{
skyValidateDefinition(&_definition);
BaseForm::applyConfigPreview();
}