paysages: Small changes.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@224 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-17 20:54:14 +00:00 committed by ThunderK
parent 375c4f24b8
commit d9ad396d12
6 changed files with 36 additions and 27 deletions

View file

@ -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)

View file

@ -1,5 +1,6 @@
#include "preview.h"
#include "formwater.h"
#include "tools.h"
#include <QColor>
#include <QSlider>
#include <math.h>
@ -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();
}

View file

@ -4,9 +4,11 @@
#include <QColor>
#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);
}

View file

@ -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();

View file

@ -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)

View file

@ -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