From 6099241ec9bcf157a0525123c242418c7e78a748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 12 Apr 2012 20:02:31 +0000 Subject: [PATCH] paysages: More UI polishing + top down render preview + configurable preview scaling. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@292 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 2 +- gui_qt/basepreview.cpp | 54 ++++++++--- gui_qt/basepreview.h | 5 +- gui_qt/dialognoise.cpp | 6 +- gui_qt/formatmosphere.cpp | 2 + gui_qt/formclouds.cpp | 4 + gui_qt/formrender.cpp | 85 ++++++++++++++++++ gui_qt/formrender.h | 1 + gui_qt/formsky.cpp | 8 +- gui_qt/formterrain.cpp | 57 +++++++++++- gui_qt/formtextures.cpp | 10 ++- gui_qt/formwater.cpp | 4 + i18n/paysages_fr.ts | 183 ++++++++++++++++++++------------------ 13 files changed, 310 insertions(+), 111 deletions(-) diff --git a/TODO b/TODO index d8b14aa..ef4630d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ - Make colorgradation dialog sizable (and reduce minimum size). - Make all UI more sizable. -- Implement scaling and scrolling on previews. +- Implement scrolling on previews. - Add a material editor dialog. - Replace FILE* by a custom type for Save and Load. - Water and terrain LOD moves with the camera, fix it like in the wanderer. diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index ff1f504..471bfbf 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -44,6 +44,7 @@ BasePreview::BasePreview(QWidget* parent) : this->conf_scroll_ymax = 0.0; this->conf_scale_min = 1.0; this->conf_scale_max = 1.0; + this->conf_scale_init = 1.0; this->conf_scale_step = 0.0; this->scaling = 1.0; this->xoffset = 0.0; @@ -86,6 +87,21 @@ QColor BasePreview::getColor(double x, double y) return QColor(0, 0, 0); } +void BasePreview::configScaling(double min, double max, double step, double init) +{ + double size = (double)width(); + + if (size >= 1.0) + { + conf_scale_min = min / size; + conf_scale_max = max / size; + conf_scale_step = step / size; + conf_scale_init = init / size; + scaling = init / size; + redraw(); + } +} + void BasePreview::start() { this->updater->start(); @@ -121,13 +137,6 @@ void BasePreview::handleRedraw() lock_drawing->unlock(); } -void BasePreview::setScaling(double scaling) -{ - // TODO Follow conf_scale - this->scaling = scaling; - redraw(); -} - void BasePreview::resizeEvent(QResizeEvent* event) { QImage* image; @@ -207,16 +216,39 @@ void BasePreview::renderPixbuf() void BasePreview::wheelEvent(QWheelEvent* event) { + double factor; + + if (event->modifiers() & Qt::ShiftModifier) + { + factor = 5.0; + } + else if (event->modifiers() & Qt::ControlModifier) + { + factor = 0.2; + } + else + { + factor = 1.0; + } + if (event->orientation() == Qt::Vertical) { - if (event->delta() > 0 && scaling > 0.19) + if (event->delta() > 0 && scaling > conf_scale_min) { - scaling -= 0.1; + scaling -= conf_scale_step * factor; + if (scaling < conf_scale_min) + { + scaling = conf_scale_min; + } redraw(); } - else if (event->delta() < 0 && scaling < 10.0) + else if (event->delta() < 0 && scaling < conf_scale_max) { - scaling += 0.1; + scaling += conf_scale_step * factor; + if (scaling > conf_scale_max) + { + scaling = conf_scale_max; + } redraw(); } event->accept(); diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index 67767e5..1b2b75a 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -18,11 +18,11 @@ public: void doRender(); void redraw(); - void setScaling(double scaling); - protected: virtual void updateData(); virtual QColor getColor(double x, double y); + + void configScaling(double min, double max, double step, double init); double xoffset; double yoffset; @@ -56,6 +56,7 @@ private: double conf_scale_min; double conf_scale_max; + double conf_scale_init; double conf_scale_step; signals: diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index 2b64090..74a1156 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -18,6 +18,8 @@ public: _noise_original = noise; _noise_preview = noiseCreateGenerator(); _level = -1; + + configScaling(0.05, 2.0, 0.05, 2.0); } void setLevel(int row) @@ -54,6 +56,8 @@ public: { _noise_original = noise; _noise_preview = noiseCreateGenerator(); + + configScaling(0.05, 2.0, 0.03, 2.0); } protected: void updateData() @@ -97,12 +101,10 @@ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value): previewLevel = new PreviewLevel(previews, _current); previews->layout()->addWidget(new QLabel(tr("Level preview"))); previews->layout()->addWidget(previewLevel); - previewLevel->setScaling(1.0 / 127.0); previewLevel->start(); previewTotal = new PreviewTotal(previews, _current); previews->layout()->addWidget(new QLabel(tr("Total preview"))); previews->layout()->addWidget(previewTotal); - previewTotal->setScaling(1.0 / 127.0); previewTotal->start(); form = new QWidget(this); diff --git a/gui_qt/formatmosphere.cpp b/gui_qt/formatmosphere.cpp index a85486c..8c8942e 100644 --- a/gui_qt/formatmosphere.cpp +++ b/gui_qt/formatmosphere.cpp @@ -17,6 +17,8 @@ public: { _renderer = rendererCreate(); _preview_definition = atmosphereCreateDefinition(); + + configScaling(100.0, 1000.0, 20.0, 200.0); } protected: QColor getColor(double x, double y) diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index af9b487..da69bb4 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -21,6 +21,8 @@ public: _renderer.render_quality = 3; _preview_layer = cloudsLayerCreateDefinition(); + + configScaling(100.0, 1000.0, 20.0, 200.0); } protected: QColor getColor(double x, double y) @@ -79,6 +81,8 @@ public: _renderer.maskLight = _maskLight; _renderer.customData[0] = &_preview_layer; _renderer.customData[1] = &_lighting; + + configScaling(100.0, 400.0, 20.0, 200.0); } protected: QColor getColor(double x, double y) diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 81b1c63..eb745ad 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -4,9 +4,91 @@ #include #include "dialogrender.h" #include "inputcamera.h" +#include "tools.h" #include "../lib_paysages/render.h" #include "../lib_paysages/scenery.h" +/**************** Previews ****************/ +class PreviewRenderLandscape:public BasePreview +{ +public: + PreviewRenderLandscape(QWidget* parent):BasePreview(parent) + { + _renderer = rendererCreate(); + _renderer.applyTextures = _applyTextures; + _renderer.getTerrainHeight = _getTerrainHeight; + _renderer.applyLightingToSurface = _applyLightingToSurface; + _renderer.maskLight = _maskLight; + _renderer.camera_location.x = 0.0; + _renderer.camera_location.y = 50.0; + _renderer.camera_location.z = 0.0; + + _terrain = terrainCreateDefinition(); + _textures = texturesCreateDefinition(); + _lighting = lightingCreateDefinition(); + _water = waterCreateDefinition(); + + _renderer.customData[0] = &_terrain; + _renderer.customData[1] = &_textures; + _renderer.customData[2] = &_lighting; + _renderer.customData[3] = &_water; + + configScaling(0.5, 200.0, 1.0, 50.0); + } +protected: + QColor getColor(double x, double y) + { + Vector3 down = {0.0, -1.0, 0.0}; + Vector3 location; + double height = terrainGetHeight(&_terrain, x, y); + + if (height < _water.height) + { + location.x = x; + location.y = _water.height; + location.z = y; + return colorToQColor(waterGetColor(&_water, &_renderer, location, down)); + } + else + { + return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling)); + } + } + void updateData() + { + sceneryGetTerrain(&_terrain); + sceneryGetLighting(&_lighting); + sceneryGetTextures(&_textures); + sceneryGetWater(&_water); + } +private: + Renderer _renderer; + TerrainDefinition _terrain; + WaterDefinition _water; + TexturesDefinition _textures; + LightingDefinition _lighting; + + static double _getTerrainHeight(Renderer* renderer, double x, double z) + { + return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); + } + + static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) + { + return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location, precision); + } + + static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + { + return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material); + } + + static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) + { + return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light); + } +}; + /**************** Form ****************/ FormRender::FormRender(QWidget *parent) : BaseForm(parent, true) @@ -20,6 +102,9 @@ FormRender::FormRender(QWidget *parent) : _renderer_inited = false; + _preview_landscape = new PreviewRenderLandscape(this); + addPreview(_preview_landscape, QString(tr("Top-down preview"))); + addInput(new InputCamera(this, tr("Camera"), &_camera)); addInputInt(tr("Quality"), &_quality, 1, 10, 1, 1); addInputInt(tr("Image width"), &_width, 100, 2000, 10, 100); diff --git a/gui_qt/formrender.h b/gui_qt/formrender.h index 416bbf3..b801b47 100644 --- a/gui_qt/formrender.h +++ b/gui_qt/formrender.h @@ -33,6 +33,7 @@ private: CameraDefinition _camera; Renderer _renderer; bool _renderer_inited; + BasePreview* _preview_landscape; }; #endif // _PAYSAGES_QT_FORMRENDER_H_ diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index c96facb..8eb51be 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -22,6 +22,8 @@ public: { _renderer = rendererCreate(); _preview_definition = skyCreateDefinition(); + + configScaling(0.5, 5.0, 0.5, 2.5); } protected: QColor getColor(double x, double y) @@ -29,7 +31,7 @@ protected: Vector3 eye = {0.0, 0.0, 0.0}; Vector3 look; - look.x = 100.0; + look.x = 1.0; look.y = -y; look.z = x; @@ -52,6 +54,8 @@ public: { _renderer = rendererCreate(); _preview_definition = skyCreateDefinition(); + + configScaling(0.5, 5.0, 0.5, 2.5); } protected: QColor getColor(double x, double y) @@ -59,7 +63,7 @@ protected: Vector3 eye = {0.0, 0.0, 0.0}; Vector3 look; - look.x = -100.0; + look.x = -1.0; look.y = -y; look.z = -x; diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index c14474f..19d9ff2 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -18,6 +18,8 @@ public: PreviewTerrainHeight(QWidget* parent):BasePreview(parent) { _preview_definition = terrainCreateDefinition(); + + configScaling(0.5, 200.0, 1.0, 50.0); } protected: QColor getColor(double x, double y) @@ -40,16 +42,54 @@ class PreviewTerrainColor:public BasePreview public: PreviewTerrainColor(QWidget* parent):BasePreview(parent) { + LightDefinition light; + TextureLayerDefinition* texture; + _renderer = rendererCreate(); _renderer.applyTextures = _applyTextures; _renderer.getTerrainHeight = _getTerrainHeight; - /*_renderer.applyLightingToSurface = _applyLightingToSurface;*/ + _renderer.applyLightingToSurface = _applyLightingToSurface; + _renderer.maskLight = _maskLight; + + _lighting = lightingCreateDefinition(); + light.color.r = 0.7; + light.color.g = 0.7; + light.color.b = 0.7; + light.amplitude = 0.0; + light.direction.x = -0.5; + light.direction.y = -0.7071; + light.direction.z = 0.5; + light.filtered = 0; + light.masked = 1; + light.reflection = 0.0; + lightingAddLight(&_lighting, light); + light.color.r = 0.3; + light.color.g = 0.3; + light.color.b = 0.3; + light.amplitude = 0.0; + light.direction.x = 0.5; + light.direction.y = -0.7071; + light.direction.z = -0.5; + light.filtered = 0; + light.masked = 0; + light.reflection = 0.0; + lightingAddLight(&_lighting, light); + lightingValidateDefinition(&_lighting); _terrain = terrainCreateDefinition(); _textures = texturesCreateDefinition(); + texturesAddLayer(&_textures); + texture = texturesGetLayer(&_textures, 0); + texture->material.base = COLOR_WHITE; + texture->material.reflection = 0.0; + texture->bump_height = 0.0; + texturesLayerValidateDefinition(texture); _renderer.customData[0] = &_terrain; _renderer.customData[1] = &_textures; + _renderer.customData[2] = &_lighting; + + configScaling(0.5, 200.0, 1.0, 50.0); } protected: QColor getColor(double x, double y) @@ -59,12 +99,13 @@ protected: void updateData() { terrainCopyDefinition(&_definition, &_terrain); - sceneryGetTextures(&_textures); + //sceneryGetTextures(&_textures); } private: Renderer _renderer; TerrainDefinition _terrain; TexturesDefinition _textures; + LightingDefinition _lighting; static double _getTerrainHeight(Renderer* renderer, double x, double z) { @@ -75,6 +116,16 @@ private: { return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location, precision); } + + static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + { + return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material); + } + + static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) + { + return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light); + } }; /**************** Form ****************/ @@ -86,7 +137,7 @@ FormTerrain::FormTerrain(QWidget *parent): previewHeight = new PreviewTerrainHeight(this); previewColor = new PreviewTerrainColor(this); addPreview(previewHeight, QString(tr("Height preview (normalized)"))); - addPreview(previewColor, QString(tr("Textured preview (no shadow)"))); + addPreview(previewColor, QString(tr("Lighted preview (no texture)"))); addInputNoise(tr("Noise"), _definition.height_noise); addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0); diff --git a/gui_qt/formtextures.cpp b/gui_qt/formtextures.cpp index c1f4dde..9fc5f37 100644 --- a/gui_qt/formtextures.cpp +++ b/gui_qt/formtextures.cpp @@ -34,6 +34,8 @@ public: _renderer.customData[0] = &_terrain; _preview_layer = texturesLayerCreateDefinition(); + + configScaling(0.5, 200.0, 1.0, 50.0); } protected: QColor getColor(double x, double y) @@ -91,15 +93,17 @@ public: _renderer.camera_location.x = 0.0; _renderer.camera_location.y = 20.0; _renderer.camera_location.z = 0.0; + + configScaling(0.1, 10.0, 0.1, 1.0); } protected: QColor getColor(double x, double y) { Vector3 location; - location.x = x * 0.01; + location.x = x; location.y = 0.0; - location.z = y * 0.01; - return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling * 0.01)); + location.z = y; + return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling)); } void updateData() { diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 866a9f9..b813e9e 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -24,6 +24,8 @@ public: { _water = waterCreateDefinition(); _terrain = terrainCreateDefinition(); + + configScaling(0.5, 200.0, 1.0, 50.0); } protected: QColor getColor(double x, double y) @@ -77,6 +79,8 @@ public: _renderer.applyLightingToSurface = _applyLightingToSurface; _renderer.customData[0] = &_water; _renderer.customData[1] = &_lighting; + + configScaling(10.0, 1000.0, 10.0, 250.0); } protected: QColor getColor(double x, double y) diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 296ce78..890f527 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -93,62 +93,62 @@ Cliquez avec le bouton droit sur un point pour le supprimer. DialogNoise - + Level preview Aperçu du composant - + Total preview Aperçu du total - + Noise components Composants du bruit - + Add component Ajouter un composant - + Remove component Supprimer un composant - + Component height Hauteur du composant - + Component scaling Echelle du composant - + Validate Valider - + Reset Recommencer - + Cancel Annuler - + Paysages 3D - Noise editor Paysages 3D - Editeur de bruit - + Component %1 Composant %1 @@ -220,32 +220,32 @@ Maintenir Ctrl : Plus rapide FormAtmosphere - + Color preview Aperçu de la couleur - + Start distance Distance de début - + End distance Distance de fin - + Masking power Opacité maximale - + Lock color on haze Verrouiller sur la couleur de la brume - + Color Couleur @@ -253,72 +253,72 @@ Maintenir Ctrl : Plus rapide FormClouds - + Layer coverage (no lighting) Couverture de la couche (sans éclairage) - + Color and lighting Echantillon éclairé - + Start altitude Altitude de début - + Max density altitude Altitude de densité maximale - + End altitude Altitude de fin - + Noise Bruit - + Coverage Couverture - + Scaling Echelle - + Base color Couleur de base - + Light reflection Facteur de réflexion de la lumière - + Light reflection shininess Concentration de la réflexion de lumière - + Transparency depth Distance de transparence - + Light traversal depth Distance de traversée de la lumière - + Minimum lighting Eclairage minimal @@ -353,47 +353,52 @@ Maintenir Ctrl : Plus rapide FormRender - + + Top-down preview + Aperçu plongeant + + + Camera Caméra - + Quality Qualité de rendu - + Image width Largeur de l'image - + Image height Hauteur de l'image - + Start new render Démarrer un rendu - + Show last render Voir le dernier rendu - + Save last render Sauvegarder le dernier rendu - + Choose a filename to save the last render Choisissez un nom de fichier pour le rendu - + The picture %1 has been saved. L'image %1 a été sauvegardée. @@ -401,47 +406,47 @@ Maintenir Ctrl : Plus rapide FormSky - + West preview Aperçu de l'ouest - + East preview Aperçu de l'est - + Day time Heure du jour - + Sun color Couleur du soleil - + Sun radius Diamètre apparent du soleil - + Zenith color Couleur du ciel au zénith - + Haze color Couleur de la brume - + Haze height Hauteur apparente de la brume - + Haze smoothing Facteur de lissage de la brume @@ -449,27 +454,31 @@ Maintenir Ctrl : Plus rapide FormTerrain - + Height preview (normalized) Aperçu de la hauteur (normalisée) - Textured preview (no shadow) - Aperçu du rendu (sans ombres) + Aperçu du rendu (sans ombres) - + + Lighted preview (no texture) + Aperçu éclairé (sans texture) + + + Noise Bruit - + Height Hauteur - + Scaling Echelle @@ -477,7 +486,7 @@ Maintenir Ctrl : Plus rapide FormTextures - + Coverage preview Aperçu de la couverture @@ -486,77 +495,77 @@ Maintenir Ctrl : Plus rapide Rendu en couleur - + Lighted sample Echantillon éclairé - + Surface noise Bruit de surface - + Surface noise height Hauteur du bruit - + Surface noise scaling Echelle du bruit - + Base color Couleur de base - + Light reflection Réflexion de lumière - + Light reflection shininess - Concentration de la réflexion de lumière + Concentration de la lumière réfléchie - + Soft minimal height Altitude minimal (adoucie) - + Hard minimal height Altitude minimale - + Hard maximal height Altitude maximale - + Soft maximal height Altitude maximale (adoucie) - + Soft minimal slope Pente minimale (adoucie) - + Hard minimal slope Pente minimale - + Hard maximal slope Pente maximale - + Soft maximal slope Pente maximale (adoucie) @@ -564,72 +573,72 @@ Maintenir Ctrl : Plus rapide FormWater - + Coverage preview Aperçu de la couverture - + Rendered preview (without/with lighting) Aperçu du rendu (sans/avec éclairage) - + Height Hauteur - + Surface color Couleur de la surface - + Light reflection Réflection de la lumière - + Shininess to light Concentration de la lumière réfléchie - + Transparency Transparence - + Reflection Reflets - + Transparency distance Distance maximale de transparence - + Depth color Couleur en profondeur - + Light-through distance Distance de filtrage de la lumière - + Waves noise Bruit des vagues - + Waves height Hauteur des vagues - + Waves scaling Echelle des vagues