From fad0b9941b9f39ba73b222ddf4b45d2442fa79ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 30 Jan 2013 10:57:41 +0000 Subject: [PATCH] paysages : Added cloud preview from above. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@507 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 2 +- gui_qt/basepreview.cpp | 1 + gui_qt/formclouds.cpp | 13 ++++++++++++- lib_paysages/clouds/preview.c | 34 ++++++++++++++++++++++++---------- lib_paysages/clouds/public.h | 2 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 9ed0a40..764d177 100644 --- a/TODO +++ b/TODO @@ -9,7 +9,7 @@ Technology Preview 2 : => Fix artifacts on aerial perspective => Fix blue appearance at night - Finalize lighting refactoring - => Restore water and cloud filters + => Restore water filtering => Restore cloud lighting => Restore and improve skydome lighting - Apply Preetham's model usage diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index c366e77..67c2763 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -507,6 +507,7 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v void BasePreview::toggleChangeEvent(QString, bool) { + redraw(); } void BasePreview::redraw() diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 650fbfc..558ba35 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -13,10 +13,12 @@ public: PreviewCloudsCoverage(QWidget* parent, CloudsLayerDefinition* layer):BasePreview(parent) { _renderer = cloudsCreatePreviewCoverageRenderer(); + _3d = true; _original_layer = layer; _preview_definition = (CloudsDefinition*)CloudsDefinitionClass.create(); + addToggle("3d", tr("Perspective"), true); configScaling(100.0, 1000.0, 20.0, 200.0); } ~PreviewCloudsCoverage() @@ -27,7 +29,15 @@ public: protected: Color getColor(double x, double y) { - return cloudsGetPreviewCoverage(_renderer, x, y, scaling); + return cloudsGetPreviewCoverage(_renderer, x, y, scaling, _3d); + } + virtual void toggleChangeEvent(QString key, bool value) + { + if (key == "3d") + { + _3d = value; + } + BasePreview::toggleChangeEvent(key, value); } void updateData() { @@ -40,6 +50,7 @@ private: Renderer* _renderer; CloudsLayerDefinition* _original_layer; CloudsDefinition* _preview_definition; + bool _3d; }; class PreviewCloudsColor:public BasePreview diff --git a/lib_paysages/clouds/preview.c b/lib_paysages/clouds/preview.c index 3d45bed..6d5381a 100644 --- a/lib_paysages/clouds/preview.c +++ b/lib_paysages/clouds/preview.c @@ -26,19 +26,33 @@ Renderer* cloudsCreatePreviewCoverageRenderer() return result; } -Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling) +Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective) { - Vector3 eye, look; + if (perspective) + { + 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); + 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); - return renderer->clouds->getColor(renderer, COLOR_BLUE, eye, v3Add(eye, v3Scale(look, 1000.0))); + return renderer->clouds->getColor(renderer, COLOR_BLUE, eye, v3Add(eye, v3Scale(look, 1000.0))); + } + else + { + Vector3 start, end; + + start.x = end.x = x; + start.z = end.z = y; + start.y = 1000.0; + end.y = -1000.0; + + return renderer->clouds->getColor(renderer, COLOR_BLUE, start, end); + } } Renderer* cloudsCreatePreviewColorRenderer() diff --git a/lib_paysages/clouds/public.h b/lib_paysages/clouds/public.h index f3ae288..89660f8 100644 --- a/lib_paysages/clouds/public.h +++ b/lib_paysages/clouds/public.h @@ -82,7 +82,7 @@ LayerType cloudsGetLayerType(); void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset); Renderer* cloudsCreatePreviewCoverageRenderer(); -Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling); +Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective); Renderer* cloudsCreatePreviewColorRenderer(); Color cloudsGetPreviewColor(Renderer* renderer, double x, double y);