From d9ad396d121cc88c1be8ad90a2ee6d37507ef9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 17 Jan 2012 20:54:14 +0000 Subject: [PATCH] paysages: Small changes. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@224 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_gtk/tab_water.c | 4 ++-- gui_qt/formwater.cpp | 14 ++++++++------ gui_qt/tools.h | 2 ++ lib_paysages/auto.c | 13 +++++++------ lib_paysages/water.c | 25 ++++++++++++++----------- lib_paysages/water.h | 5 +++-- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/gui_gtk/tab_water.c b/gui_gtk/tab_water.c index d57c5a6..b0c8cdc 100644 --- a/gui_gtk/tab_water.c +++ b/gui_gtk/tab_water.c @@ -101,13 +101,13 @@ static Color _cbPreviewRender(SmallPreview* preview, double x, double y, double static void _cbEditNoiseDone(NoiseGenerator* generator) { - noiseCopy(generator, _definition.height_noise); + noiseCopy(generator, _definition.waves_noise); guiPreviewRedraw(_preview_render); } static void _cbEditNoise(GtkWidget* widget, gpointer data) { - guiNoiseEdit(_definition.height_noise, _cbEditNoiseDone); + guiNoiseEdit(_definition.waves_noise, _cbEditNoiseDone); } static void _cbHeightChanged(GtkRange* range, gpointer data) diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 896a7ab..8de4169 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -1,5 +1,6 @@ #include "preview.h" #include "formwater.h" +#include "tools.h" #include #include #include @@ -32,7 +33,7 @@ protected: } else { - return QColor(_definition.main_color.r * 255.0, _definition.main_color.g * 255.0, _definition.main_color.b * 255.0); + return colorToQColor(_definition.main_color); } } }; @@ -64,7 +65,7 @@ protected: if (look.y > -0.0001) { result = this->rayCastFromWater(eye, look).hit_color; - return QColor(result.r * 255.0, result.g * 255.0, result.b * 255.0); + return colorToQColor(result); } location.x = eye.x - look.x * eye.y / look.y; @@ -74,7 +75,7 @@ protected: if (location.z > 0.0) { result = this->rayCastFromWater(eye, look).hit_color; - return QColor(result.r * 255.0, result.g * 255.0, result.b * 255.0); + return colorToQColor(result); } definition = _definition; @@ -86,7 +87,7 @@ protected: quality.force_detail = 0.0001; result = waterGetColorCustom(location, look, &definition, &quality, &environment).final; - return QColor(result.r * 255.0, result.g * 255.0, result.b * 255.0); + return colorToQColor(result); } private: @@ -137,8 +138,9 @@ FormWater::FormWater(QWidget *parent): addInputDouble("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1); addInputColor("Depth color", &_definition.depth_color); addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0); - addInputNoise("Wave noise", _definition.height_noise); - addInputDouble("Wave factor", &_definition.height_noise_factor, 0.0, 2.0, 0.01, 0.2); + addInputNoise("Waves noise", _definition.waves_noise); + addInputDouble("Waves height", &_definition.waves_noise_height, 0.0, 0.1, 0.001, 0.01); + addInputDouble("Waves scaling", &_definition.waves_noise_scale, 0.01, 1.0, 0.01, 0.1); revertConfig(); } diff --git a/gui_qt/tools.h b/gui_qt/tools.h index 471f514..a8c55a4 100644 --- a/gui_qt/tools.h +++ b/gui_qt/tools.h @@ -4,9 +4,11 @@ #include #include "../lib_paysages/shared/types.h" +#include "../lib_paysages/shared/functions.h" static inline QColor colorToQColor(Color color) { + colorNormalize(&color); return QColor(color.r * 255.0, color.g * 255.0, color.b * 255.0, color.a * 255.0); } diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 546cb6f..4745c29 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -213,13 +213,14 @@ void autoGenRealisticLandscape(int seed) water.depth_color.g = 0.2; water.depth_color.b = 0.3; water.depth_color.a = 1.0; - water.height_noise = noiseCreateGenerator(); - water.height_noise_factor = 1.0; - noiseGenerateBaseNoise(water.height_noise, 262144); - noiseAddLevelsSimple(water.height_noise, 2, 0.2, 0.015); - noiseAddLevelsSimple(water.height_noise, 3, 0.03, 0.003); + water.waves_noise = noiseCreateGenerator(); + water.waves_noise_height = 0.015; + water.waves_noise_scale = 0.2; + noiseGenerateBaseNoise(water.waves_noise, 262144); + noiseAddLevelsSimple(water.waves_noise, 2, 1.0, 1.0); + noiseAddLevelsSimple(water.waves_noise, 3, 0.15, 0.1); waterSetDefinition(water); - noiseDeleteGenerator(water.height_noise); + noiseDeleteGenerator(water.waves_noise); /* Sky */ sky.sun_color = colorGradationCreate(); diff --git a/lib_paysages/water.c b/lib_paysages/water.c index f89e059..ced1df8 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -55,8 +55,9 @@ void waterSave(FILE* f) toolsSaveDouble(f, _definition.transparency_depth); toolsSaveDouble(f, _definition.transparency); toolsSaveDouble(f, _definition.reflection); - noiseSave(_definition.height_noise, f); - toolsSaveDouble(f, _definition.height_noise_factor); + noiseSave(_definition.waves_noise, f); + toolsSaveDouble(f, _definition.waves_noise_height); + toolsSaveDouble(f, _definition.waves_noise_scale); } void waterLoad(FILE* f) @@ -67,8 +68,9 @@ void waterLoad(FILE* f) _definition.transparency_depth = toolsLoadDouble(f); _definition.transparency = toolsLoadDouble(f); _definition.reflection = toolsLoadDouble(f); - noiseLoad(_definition.height_noise, f); - _definition.height_noise_factor = toolsLoadDouble(f); + noiseLoad(_definition.waves_noise, f); + _definition.waves_noise_height = toolsLoadDouble(f); + _definition.waves_noise_scale = toolsLoadDouble(f); } WaterDefinition waterCreateDefinition() @@ -78,25 +80,26 @@ WaterDefinition waterCreateDefinition() result.main_color = COLOR_BLACK; result.depth_color = COLOR_BLACK; result.height = -1000.0; - result.height_noise = noiseCreateGenerator(); - result.height_noise_factor = 1.0; + result.waves_noise = noiseCreateGenerator(); + result.waves_noise_height = 0.02; + result.waves_noise_scale = 0.2; return result; } void waterDeleteDefinition(WaterDefinition definition) { - noiseDeleteGenerator(definition.height_noise); + noiseDeleteGenerator(definition.waves_noise); } void waterCopyDefinition(WaterDefinition source, WaterDefinition* destination) { NoiseGenerator* noise; - noise = destination->height_noise; + noise = destination->waves_noise; *destination = source; - destination->height_noise = noise; - noiseCopy(source.height_noise, destination->height_noise); + destination->waves_noise = noise; + noiseCopy(source.waves_noise, destination->waves_noise); } void waterSetDefinition(WaterDefinition config) @@ -123,7 +126,7 @@ WaterQuality waterGetQuality() static inline double _getHeight(WaterDefinition* definition, double x, double z, double detail) { - return definition->height + noiseGet2DDetail(definition->height_noise, x, z, detail) * definition->height_noise_factor; + return definition->height + noiseGet2DDetail(definition->waves_noise, x / definition->waves_noise_scale, z / definition->waves_noise_scale, detail) * definition->waves_noise_height; } static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail) diff --git a/lib_paysages/water.h b/lib_paysages/water.h index 7497ae4..bd8cd41 100644 --- a/lib_paysages/water.h +++ b/lib_paysages/water.h @@ -16,8 +16,9 @@ typedef struct Color main_color; Color depth_color; double transparency_depth; - NoiseGenerator* height_noise; - double height_noise_factor; + NoiseGenerator* waves_noise; + double waves_noise_height; + double waves_noise_scale; } WaterDefinition; typedef struct