diff --git a/src/interface/desktop/formrender.cpp b/src/interface/desktop/formrender.cpp index 49d92b4..05020ab 100644 --- a/src/interface/desktop/formrender.cpp +++ b/src/interface/desktop/formrender.cpp @@ -16,92 +16,7 @@ #include "BasePreview.h" #include "CloudsDefinition.h" #include "CameraDefinition.h" - -/**************** Previews ****************/ -class PreviewRenderLandscape : public BasePreview -{ -public: - PreviewRenderLandscape(QWidget* parent) : BasePreview(parent) - { - _renderer = new SoftwareRenderer(); - _renderer->getCameraLocation = _getCameraLocation; - lightingManagerDisableSpecularity(_renderer->lighting); - - _no_clouds = new CloudsDefinition(NULL); - _clouds_enabled = true; - - addOsd(QString("geolocation")); - addToggle("clouds", tr("Clouds"), false); - - configHdrToneMapping(true); - configScaling(0.5, 200.0, 3.0, 50.0); - configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); - } - ~PreviewRenderLandscape() - { - delete _renderer; - delete _no_clouds; - } - -protected: - Color getColor(double x, double y) - { - Vector3 location; - double height = _renderer->terrain->getHeight(_renderer, x, y, 1); - - if (height < _renderer->water->getHeightInfo(_renderer).max_height) - { - return _renderer->water->getResult(_renderer, x, y).final; - } - else - { - location.x = x; - location.y = height; - location.z = y; - return _renderer->terrain->getFinalColor(_renderer, location, scaling); - } - } - - void updateData() - { - RenderingScenery::getCurrent()->bindToRenderer(_renderer); - if (!_clouds_enabled) - { - CloudsRendererClass.bind(_renderer, _no_clouds); - } - - _renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective; - } - - void toggleChangeEvent(QString key, bool value) - { - if (key == "clouds") - { - _clouds_enabled = value; - redraw(); - } - } - -private: - SoftwareRenderer* _renderer; - bool _clouds_enabled; - CloudsDefinition* _no_clouds; - - static Vector3 _getCameraLocation(Renderer*, Vector3 location) - { - return v3Add(location, v3Scale(VECTOR_UP, 50.0)); - } - - static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base) - { - AtmosphereResult result; - atmosphereInitResult(&result); - result.base = base; - result.final = base; - atmosphereUpdateResult(&result); - return result; - } -}; +#include "SceneryTopDownPreviewRenderer.h" /**************** Form ****************/ FormRender::FormRender(QWidget *parent) : @@ -119,8 +34,10 @@ BaseForm(parent, true) disablePreviewsUpdate(); - _preview_landscape = new PreviewRenderLandscape(this); + _preview_landscape = new BasePreview(this); + _preview_landscape_renderer = new SceneryTopDownPreviewRenderer(RenderingScenery::getCurrent()); addPreview(_preview_landscape, QString(tr("Top-down preview"))); + _preview_landscape->setRenderer(_preview_landscape_renderer); addInput(new InputCamera(this, tr("Camera"), _camera)); addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1); diff --git a/src/interface/desktop/formrender.h b/src/interface/desktop/formrender.h index dffdd05..a8021f3 100644 --- a/src/interface/desktop/formrender.h +++ b/src/interface/desktop/formrender.h @@ -32,6 +32,7 @@ private: Renderer* _renderer; bool _renderer_inited; BasePreview* _preview_landscape; + Base2dPreviewRenderer* _preview_landscape_renderer; }; #endif diff --git a/src/render/preview/Base2dPreviewRenderer.cpp b/src/render/preview/Base2dPreviewRenderer.cpp index f1189f5..579b11a 100644 --- a/src/render/preview/Base2dPreviewRenderer.cpp +++ b/src/render/preview/Base2dPreviewRenderer.cpp @@ -16,6 +16,14 @@ void Base2dPreviewRenderer::bindEvent(BasePreview*) { } +void Base2dPreviewRenderer::toggleChangeEvent(const std::string &, bool) +{ +} + +void Base2dPreviewRenderer::choiceChangeEvent(const std::string &, int) +{ +} + void Base2dPreviewRenderer::updateEvent() { } diff --git a/src/render/preview/Base2dPreviewRenderer.h b/src/render/preview/Base2dPreviewRenderer.h index 0a2c784..6058af9 100644 --- a/src/render/preview/Base2dPreviewRenderer.h +++ b/src/render/preview/Base2dPreviewRenderer.h @@ -19,6 +19,9 @@ public: virtual void bindEvent(BasePreview* preview); + virtual void toggleChangeEvent(const std::string &key, bool value); + virtual void choiceChangeEvent(const std::string &key, int position); + virtual void updateEvent(); virtual void cameraEvent(double x, double y, double scaling); virtual Color getColor2D(double x, double y, double scaling); diff --git a/src/render/preview/BasePreview.cpp b/src/render/preview/BasePreview.cpp index c7b9c6b..04d66d3 100644 --- a/src/render/preview/BasePreview.cpp +++ b/src/render/preview/BasePreview.cpp @@ -551,7 +551,7 @@ void BasePreview::configScrolling(double xmin, double xmax, double xinit, double redraw(); } -void BasePreview::addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value) +void BasePreview::addChoice(const QString &key, const QString &title, const QStringList &choices, int init_value) { _ContextChoice choice; choice.title = title; @@ -563,11 +563,16 @@ void BasePreview::addChoice(const QString& key, const QString& title, const QStr choiceChangeEvent(key, init_value); } -void BasePreview::choiceChangeEvent(const QString&, int) +void BasePreview::choiceChangeEvent(const QString &key, int position) { + if (_renderer) + { + _renderer->choiceChangeEvent(key.toStdString(), position); + } + redraw(); } -void BasePreview::addToggle(const QString& key, const QString& text, bool init_value) +void BasePreview::addToggle(const QString &key, const QString &text, bool init_value) { _ContextToggle toggle; toggle.title = text; @@ -578,8 +583,12 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v toggleChangeEvent(key, init_value); } -void BasePreview::toggleChangeEvent(QString, bool) +void BasePreview::toggleChangeEvent(const QString &key, bool value) { + if (_renderer) + { + _renderer->toggleChangeEvent(key.toStdString(), value); + } redraw(); } diff --git a/src/render/preview/BasePreview.h b/src/render/preview/BasePreview.h index 82d0cf9..54ace9d 100644 --- a/src/render/preview/BasePreview.h +++ b/src/render/preview/BasePreview.h @@ -59,11 +59,11 @@ public: void configScaling(double min, double max, double step, double init, bool logarithmic = true); void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit); - void addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value); - virtual void choiceChangeEvent(const QString& key, int position); + void addChoice(const QString &key, const QString &title, const QStringList &choices, int init_value); + virtual void choiceChangeEvent(const QString &key, int position); - void addToggle(const QString& key, const QString& text, bool init_value); - virtual void toggleChangeEvent(QString key, bool value); + void addToggle(const QString &key, const QString &text, bool init_value); + virtual void toggleChangeEvent(const QString &key, bool value); protected: virtual void updateData(); diff --git a/src/render/preview/CloudsCoveragePreviewRenderer.cpp b/src/render/preview/CloudsCoveragePreviewRenderer.cpp index b827e88..cac8d5f 100644 --- a/src/render/preview/CloudsCoveragePreviewRenderer.cpp +++ b/src/render/preview/CloudsCoveragePreviewRenderer.cpp @@ -63,3 +63,11 @@ Color CloudsCoveragePreviewRenderer::getColor2D(double x, double y, double scali return clouds->getColor(this, COLOR_BLUE, start, end); } } + +void CloudsCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value) +{ + if (key == "3d") + { + perspective = value; + } +} diff --git a/src/render/preview/CloudsCoveragePreviewRenderer.h b/src/render/preview/CloudsCoveragePreviewRenderer.h index c4cb18c..fc1c558 100644 --- a/src/render/preview/CloudsCoveragePreviewRenderer.h +++ b/src/render/preview/CloudsCoveragePreviewRenderer.h @@ -17,6 +17,8 @@ public: virtual void updateEvent() override; virtual Color getColor2D(double x, double y, double scaling) override; + virtual void toggleChangeEvent(const std::string &key, bool value) override; + private: bool perspective; CloudLayerDefinition* layer; diff --git a/src/render/preview/SceneryTopDownPreviewRenderer.cpp b/src/render/preview/SceneryTopDownPreviewRenderer.cpp new file mode 100644 index 0000000..8cae985 --- /dev/null +++ b/src/render/preview/SceneryTopDownPreviewRenderer.cpp @@ -0,0 +1,90 @@ +#include "SceneryTopDownPreviewRenderer.h" + +#include "CloudsDefinition.h" +#include "BasePreview.h" +#include "Scenery.h" + +// TEMP +#include "atmosphere/public.h" +#include "tools/lighting.h" +#include "terrain/public.h" +#include "water/public.h" + +static Vector3 _getCameraLocation(Renderer*, Vector3 location) +{ + return v3Add(location, v3Scale(VECTOR_UP, 50.0)); +} + +static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base) +{ + AtmosphereResult result; + atmosphereInitResult(&result); + result.base = base; + result.final = base; + atmosphereUpdateResult(&result); + return result; +} + +SceneryTopDownPreviewRenderer::SceneryTopDownPreviewRenderer(Scenery* scenery): + scenery(scenery) +{ + clouds_enabled = true; +} + +void SceneryTopDownPreviewRenderer::bindEvent(BasePreview* preview) +{ + no_clouds = new CloudsDefinition(NULL); + clouds_enabled = true; + + // TODO Translation + preview->addOsd("geolocation"); + preview->addToggle("clouds", "Clouds", false); + + preview->configHdrToneMapping(true); + preview->configScaling(0.5, 200.0, 3.0, 50.0); + preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); + +} + +void SceneryTopDownPreviewRenderer::updateEvent() +{ + setScenery(scenery); + + if (not clouds_enabled) + { + getScenery()->getClouds()->clear(); + } + + prepare(); + + getCameraLocation = _getCameraLocation; + lightingManagerDisableSpecularity(lighting); + atmosphere->applyAerialPerspective = _applyAerialPerspective; +} + +Color SceneryTopDownPreviewRenderer::getColor2D(double x, double y, double scaling) +{ + Vector3 location; + double height = terrain->getHeight(this, x, y, 1); + + if (height < water->getHeightInfo(this).max_height) + { + return water->getResult(this, x, y).final; + } + else + { + location.x = x; + location.y = height; + location.z = y; + return terrain->getFinalColor(this, location, scaling); + } +} + +void SceneryTopDownPreviewRenderer::toggleChangeEvent(const std::string &key, bool value) +{ + if (key == "clouds") + { + clouds_enabled = value; + } +} + diff --git a/src/render/preview/SceneryTopDownPreviewRenderer.h b/src/render/preview/SceneryTopDownPreviewRenderer.h new file mode 100644 index 0000000..c725469 --- /dev/null +++ b/src/render/preview/SceneryTopDownPreviewRenderer.h @@ -0,0 +1,31 @@ +#ifndef SCENERYTOPDOWNPREVIEWRENDERER_H +#define SCENERYTOPDOWNPREVIEWRENDERER_H + +#include "preview_global.h" + +#include "Base2dPreviewRenderer.h" + +namespace paysages { +namespace preview { + +class PREVIEWSHARED_EXPORT SceneryTopDownPreviewRenderer : public Base2dPreviewRenderer +{ +public: + SceneryTopDownPreviewRenderer(Scenery* scenery); + +protected: + virtual void bindEvent(BasePreview* preview) override; + virtual void updateEvent() override; + virtual Color getColor2D(double x, double y, double scaling) override; + virtual void toggleChangeEvent(const std::string &key, bool value) override; + +private: + Scenery* scenery; + bool clouds_enabled; + CloudsDefinition* no_clouds; +}; + +} +} + +#endif // SCENERYTOPDOWNPREVIEWRENDERER_H diff --git a/src/render/preview/TerrainShapePreviewRenderer.cpp b/src/render/preview/TerrainShapePreviewRenderer.cpp index 1808345..3304a7f 100644 --- a/src/render/preview/TerrainShapePreviewRenderer.cpp +++ b/src/render/preview/TerrainShapePreviewRenderer.cpp @@ -70,7 +70,6 @@ static void _alterPreviewRenderer(Renderer* renderer) TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terrain) { _terrain = terrain; - _highlight_enabled = true; _alterPreviewRenderer(this); } @@ -78,7 +77,6 @@ TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terr void TerrainShapePreviewRenderer::bindEvent(BasePreview* preview) { preview->addOsd(QString("geolocation")); - //preview->addToggle("highlight", tr("Coverage highlight"), true); preview->configScaling(20.0, 1000.0, 20.0, 200.0); preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); @@ -89,7 +87,7 @@ void TerrainShapePreviewRenderer::updateEvent() TerrainRendererClass.bind(this, _terrain); } -Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double) +Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double scaling) { double height; @@ -100,24 +98,11 @@ Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double) } else { - Color base; - - base = water->getResult(this, x, y).final; - - if (_highlight_enabled) - { - Color mask = {0.5, 0.5, 1.0, 0.5}; - colorMask(&base, &mask); - } - - return base; + return getWaterColor(x, y, scaling); } } -void TerrainShapePreviewRenderer::toggleChangeEvent(QString key, bool value) +Color TerrainShapePreviewRenderer::getWaterColor(double, double, double) { - if (key == "highlight") - { - _highlight_enabled = value; - } + return COLOR_BLUE; } diff --git a/src/render/preview/TerrainShapePreviewRenderer.h b/src/render/preview/TerrainShapePreviewRenderer.h index d807ebc..37f5b48 100644 --- a/src/render/preview/TerrainShapePreviewRenderer.h +++ b/src/render/preview/TerrainShapePreviewRenderer.h @@ -14,15 +14,15 @@ public: explicit TerrainShapePreviewRenderer(TerrainDefinition* terrain); protected: - virtual void bindEvent(BasePreview* preview); - virtual void updateEvent(); + virtual void bindEvent(BasePreview* preview) override; + virtual void updateEvent() override; virtual Color getColor2D(double x, double y, double scaling) override; - virtual void toggleChangeEvent(QString key, bool value); + + virtual Color getWaterColor(double x, double y, double scaling); TerrainDefinition* _terrain; private: - bool _highlight_enabled; double _water_height; }; diff --git a/src/render/preview/WaterAspectPreviewRenderer.cpp b/src/render/preview/WaterAspectPreviewRenderer.cpp index 0cc7ee8..8b9094c 100644 --- a/src/render/preview/WaterAspectPreviewRenderer.cpp +++ b/src/render/preview/WaterAspectPreviewRenderer.cpp @@ -155,3 +155,19 @@ Color WaterAspectPreviewRenderer::getColor2D(double x, double y, double scaling) return water->getResult(this, target_x, target_z).final; } + +void WaterAspectPreviewRenderer::toggleChangeEvent(const std::string &key, bool value) +{ + if (key == "light") + { + lighting = value; + } +} + +void WaterAspectPreviewRenderer::choiceChangeEvent(const std::string &key, int position) +{ + if (key == "bg") + { + background = position; + } +} diff --git a/src/render/preview/WaterAspectPreviewRenderer.h b/src/render/preview/WaterAspectPreviewRenderer.h index 3305cf7..7c3db44 100644 --- a/src/render/preview/WaterAspectPreviewRenderer.h +++ b/src/render/preview/WaterAspectPreviewRenderer.h @@ -18,6 +18,9 @@ public: virtual void cameraEvent(double x, double y, double scaling) override; virtual Color getColor2D(double x, double y, double scaling) override; + virtual void toggleChangeEvent(const std::string &key, bool value) override; + virtual void choiceChangeEvent(const std::string &key, int position) override; + private: WaterDefinition* definition; bool lighting; diff --git a/src/render/preview/WaterCoveragePreviewRenderer.cpp b/src/render/preview/WaterCoveragePreviewRenderer.cpp index 3aba928..04af2bb 100644 --- a/src/render/preview/WaterCoveragePreviewRenderer.cpp +++ b/src/render/preview/WaterCoveragePreviewRenderer.cpp @@ -22,44 +22,42 @@ WaterCoveragePreviewRenderer::~WaterCoveragePreviewRenderer() void WaterCoveragePreviewRenderer::bindEvent(BasePreview* preview) { - preview->addOsd("geolocation"); + TerrainShapePreviewRenderer::bindEvent(preview); + // TODO Translation preview->addToggle("highlight", "Coverage highlight", true); - preview->configScaling(20.0, 1000.0, 20.0, 200.0); - preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); // TODO Keep camera above center (for reflections) } +void WaterCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value) +{ + if (key == "highlight") + { + highlight = value; + } +} + void WaterCoveragePreviewRenderer::updateEvent() { - getScenery()->setWater(definition); - RenderingScenery::getCurrent()->getTerrain(_terrain); TerrainShapePreviewRenderer::updateEvent(); + + getScenery()->setWater(definition); + WaterRendererClass.bind(this, definition); } -Color WaterCoveragePreviewRenderer::getColor2D(double x, double y, double scaling) +Color WaterCoveragePreviewRenderer::getWaterColor(double x, double y, double) { - double height; + Color base; - height = terrain->getHeight(this, x, y, 1); - if (height > terrain->getWaterHeight(this)) + base = water->getResult(this, x, y).final; + + if (highlight) { - return TerrainShapePreviewRenderer::getColor2D(x, y, scaling); + Color mask = {0.5, 0.5, 1.0, 0.5}; + colorMask(&base, &mask); } - else - { - Color base; - base = water->getResult(this, x, y).final; - - if (highlight) - { - Color mask = {0.5, 0.5, 1.0, 0.5}; - colorMask(&base, &mask); - } - - return base; - } + return base; } diff --git a/src/render/preview/WaterCoveragePreviewRenderer.h b/src/render/preview/WaterCoveragePreviewRenderer.h index c1ea993..1ce8725 100644 --- a/src/render/preview/WaterCoveragePreviewRenderer.h +++ b/src/render/preview/WaterCoveragePreviewRenderer.h @@ -16,7 +16,10 @@ public: virtual void bindEvent(BasePreview* preview) override; virtual void updateEvent() override; - virtual Color getColor2D(double x, double y, double scaling) override; + + virtual Color getWaterColor(double x, double y, double scaling) override; + + virtual void toggleChangeEvent(const std::string &key, bool value) override; private: WaterDefinition* definition; diff --git a/src/render/preview/preview.pro b/src/render/preview/preview.pro index f2fc861..6da7978 100644 --- a/src/render/preview/preview.pro +++ b/src/render/preview/preview.pro @@ -22,7 +22,8 @@ SOURCES += Base2dPreviewRenderer.cpp \ CloudsAspectPreviewRenderer.cpp \ WaterCoveragePreviewRenderer.cpp \ WaterAspectPreviewRenderer.cpp \ - TerrainShapePreviewRenderer.cpp + TerrainShapePreviewRenderer.cpp \ + SceneryTopDownPreviewRenderer.cpp HEADERS += Base2dPreviewRenderer.h\ preview_global.h \ @@ -35,7 +36,8 @@ HEADERS += Base2dPreviewRenderer.h\ CloudsAspectPreviewRenderer.h \ WaterCoveragePreviewRenderer.h \ WaterAspectPreviewRenderer.h \ - TerrainShapePreviewRenderer.h + TerrainShapePreviewRenderer.h \ + SceneryTopDownPreviewRenderer.h unix:!symbian { maemo5 {