From 2001e534d4b5fa18faa29adeccbad6abb26923e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 12 Feb 2012 17:26:17 +0000 Subject: [PATCH] paysages: Atmosphere form. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@266 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 1 + gui_qt/baseform.cpp | 6 ++++ gui_qt/baseform.h | 1 + gui_qt/formatmosphere.cpp | 59 ++++++++++++++++++++++++++++++++++----- gui_qt/formsky.cpp | 12 ++++---- gui_qt/inputboolean.cpp | 58 ++++++++++++++++++++++++++++++++++++++ gui_qt/inputboolean.h | 25 +++++++++++++++++ lib_paysages/color.h | 1 + 8 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 gui_qt/inputboolean.cpp create mode 100644 gui_qt/inputboolean.h diff --git a/TODO b/TODO index 56fe165..2a23082 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ +- ColorGradation dialog. - All noises should use the same entropy pool (saved separately), and avoid reallocs. - Implement light multi-sampling (mainly for skydome). - Implement scaling and scrolling on previews. diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index bfb3b20..ca13a69 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -2,6 +2,7 @@ #include "inputdouble.h" #include "inputint.h" +#include "inputboolean.h" #include "inputcolor.h" #include "inputcolorgradation.h" #include "inputnoise.h" @@ -192,6 +193,11 @@ void BaseForm::addInputDouble(QString label, double* value, double min, double m addInput(new InputDouble(form, label, value, min, max, small_step, large_step)); } +void BaseForm::addInputBoolean(QString label, int* value) +{ + addInput(new InputBoolean(form, label, value)); +} + void BaseForm::addInputColor(QString label, Color* value) { addInput(new InputColor(form, label, value)); diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 5f75b87..ce9cfd8 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -37,6 +37,7 @@ protected: void addInput(BaseInput* input); void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step); void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step); + void addInputBoolean(QString label, int* value); void addInputColor(QString label, Color* value); void addInputColorGradation(QString label, ColorGradation* value); void addInputNoise(QString label, NoiseGenerator* value); diff --git a/gui_qt/formatmosphere.cpp b/gui_qt/formatmosphere.cpp index 734f48e..7e46732 100644 --- a/gui_qt/formatmosphere.cpp +++ b/gui_qt/formatmosphere.cpp @@ -1,11 +1,56 @@ #include "formatmosphere.h" +#include "tools.h" #include "../lib_paysages/atmosphere.h" #include "../lib_paysages/scenery.h" +#include "../lib_paysages/euclid.h" +#include "../lib_paysages/color.h" static AtmosphereDefinition _definition; /**************** Previews ****************/ +class PreviewAtmosphereColor:public Preview +{ +public: + PreviewAtmosphereColor(QWidget* parent): + Preview(parent) + { + _renderer = rendererCreate(); + _preview_definition = atmosphereCreateDefinition(); + } +protected: + QColor getColor(double x, double y) + { + Vector3 eye, look, location; + + eye.x = 0.0; + eye.y = scaling * 5.0; + eye.z = -10.0 * scaling; + _renderer.camera_location = eye; + look.x = x * 0.01 / scaling; + look.y = -y * 0.01 / scaling - 0.3; + look.z = 1.0; + look = v3Normalize(look); + + if (look.y > -0.0001) + { + return colorToQColor(COLOR_BLUE); + } + + location.x = eye.x - look.x * eye.y / look.y; + location.y = 0.0; + location.z = eye.z - look.z * eye.y / look.y; + + return colorToQColor(atmosphereApply(&_preview_definition, &_renderer, location, COLOR_BLACK)); + } + void updateData() + { + atmosphereCopyDefinition(&_definition, &_preview_definition); + } +private: + Renderer _renderer; + AtmosphereDefinition _preview_definition; +}; /**************** Form ****************/ FormAtmosphere::FormAtmosphere(QWidget *parent): @@ -13,14 +58,14 @@ FormAtmosphere::FormAtmosphere(QWidget *parent): { _definition = atmosphereCreateDefinition(); - /*previewHeight = new PreviewTerrainHeight(this); - previewColor = new PreviewTerrainColor(this); - addPreview(previewHeight, QString("Height preview (normalized)")); - addPreview(previewColor, QString("Textured preview (no shadow)"));*/ + previewColor = new PreviewAtmosphereColor(this); + addPreview(previewColor, QString("Color preview")); - /*addInputNoise("Noise", _definition.height_noise); - addInputDouble("Height", &_definition.height_factor, 0.0, 20.0, 0.1, 1.0); - addInputDouble("Scaling", &_definition.scaling, 1.0, 20.0, 0.1, 1.0);*/ + addInputDouble("Start distance", &_definition.distance_near, -500.0, 500.0, 5.0, 50.0); + addInputDouble("End distance", &_definition.distance_far, -500.0, 500.0, 5.0, 50.0); + addInputDouble("Masking power", &_definition.full_mask, 0.0, 1.0, 0.01, 0.1); + addInputBoolean("Lock color on haze", &_definition.auto_lock_on_haze); + addInputColor("Color", &_definition.color); revertConfig(); } diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index e481bfa..37104ce 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -14,10 +14,10 @@ static SkyDefinition _definition; /**************** Previews ****************/ -class PreviewEast:public Preview +class PreviewSkyEast:public Preview { public: - PreviewEast(QWidget* parent): + PreviewSkyEast(QWidget* parent): Preview(parent) { _renderer = rendererCreate(); @@ -44,10 +44,10 @@ private: SkyDefinition _preview_definition; }; -class PreviewWest:public Preview +class PreviewSkyWest:public Preview { public: - PreviewWest(QWidget* parent): + PreviewSkyWest(QWidget* parent): Preview(parent) { _renderer = rendererCreate(); @@ -80,9 +80,9 @@ FormSky::FormSky(QWidget *parent): { _definition = skyCreateDefinition(); - previewWest = new PreviewWest(this); + previewWest = new PreviewSkyWest(this); addPreview(previewWest, QString("West preview")); - previewEast = new PreviewEast(this); + previewEast = new PreviewSkyEast(this); addPreview(previewEast, QString("East preview")); addInputDouble("Day time", &_definition.daytime, 0.0, 1.0, 0.01, 0.1); diff --git a/gui_qt/inputboolean.cpp b/gui_qt/inputboolean.cpp new file mode 100644 index 0000000..36fffcb --- /dev/null +++ b/gui_qt/inputboolean.cpp @@ -0,0 +1,58 @@ +#include "inputboolean.h" + +#include +#include "math.h" + +InputBoolean::InputBoolean(QWidget* form, QString label, int* value) : BaseInput(form, label) +{ + this->value = value; + + checkbox = new QCheckBox(form); + + connect(checkbox, SIGNAL(stateChanged(int)), this, SLOT(applyValue())); + + _preview = new QLabel(form); + _control = checkbox; +} + +void InputBoolean::updatePreview() +{ + if (checkbox->checkState() == Qt::Checked) + { + ((QLabel*)_preview)->setText("Yes"); + } + else + { + ((QLabel*)_preview)->setText("No"); + } + + BaseInput::updatePreview(); +} + +void InputBoolean::applyValue() +{ + if (checkbox->checkState() == Qt::Checked) + { + *value = 1; + } + else + { + *value = 0; + } + + BaseInput::applyValue(); +} + +void InputBoolean::revert() +{ + if (*value) + { + checkbox->setCheckState(Qt::Checked); + } + else + { + checkbox->setCheckState(Qt::Unchecked); + } + + BaseInput::revert(); +} diff --git a/gui_qt/inputboolean.h b/gui_qt/inputboolean.h new file mode 100644 index 0000000..fad8910 --- /dev/null +++ b/gui_qt/inputboolean.h @@ -0,0 +1,25 @@ +#ifndef _PAYSAGES_QT_INPUTBOOLEAN_H_ +#define _PAYSAGES_QT_INPUTBOOLEAN_H_ + +#include +#include +#include "baseinput.h" + +class InputBoolean:public BaseInput +{ + Q_OBJECT + +public: + InputBoolean(QWidget* form, QString label, int* value); + +public slots: + virtual void updatePreview(); + virtual void applyValue(); + virtual void revert(); + +private: + QCheckBox* checkbox; + int* value; +}; + +#endif diff --git a/lib_paysages/color.h b/lib_paysages/color.h index 3e17ade..ff7727d 100644 --- a/lib_paysages/color.h +++ b/lib_paysages/color.h @@ -2,6 +2,7 @@ #define _PAYSAGES_COLOR_H_ #include "shared/types.h" +#include "shared/constants.h" #ifdef __cplusplus extern "C" {