2012-02-21 13:41:02 +00:00
|
|
|
#include "basepreview.h"
|
2011-12-25 21:19:32 +00:00
|
|
|
#include "formwater.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
#include <QColor>
|
2012-01-05 16:32:41 +00:00
|
|
|
#include <QSlider>
|
2011-12-27 19:03:46 +00:00
|
|
|
#include <math.h>
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-01-29 17:39:56 +00:00
|
|
|
#include "../lib_paysages/euclid.h"
|
2012-01-28 18:32:08 +00:00
|
|
|
#include "../lib_paysages/lighting.h"
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/renderer.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
|
|
|
#include "../lib_paysages/terrain.h"
|
|
|
|
#include "../lib_paysages/water.h"
|
|
|
|
#include "tools.h"
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2011-12-27 19:03:46 +00:00
|
|
|
static WaterDefinition _definition;
|
|
|
|
|
|
|
|
/**************** Previews ****************/
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewWaterCoverage:public BasePreview
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-21 13:41:02 +00:00
|
|
|
PreviewWaterCoverage(QWidget* parent):BasePreview(parent)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-01-26 22:30:20 +00:00
|
|
|
_water = waterCreateDefinition();
|
2012-01-24 13:16:20 +00:00
|
|
|
_terrain = terrainCreateDefinition();
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2012-06-02 14:17:01 +00:00
|
|
|
configScaling(0.5, 200.0, 3.0, 50.0);
|
2012-04-15 20:08:01 +00:00
|
|
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
double height;
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
height = terrainGetHeight(&_terrain, x, y);
|
2011-12-27 19:03:46 +00:00
|
|
|
if (height > _definition.height)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
height = terrainGetHeightNormalized(&_terrain, x, y);
|
2011-12-26 21:53:29 +00:00
|
|
|
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-28 18:32:08 +00:00
|
|
|
return colorToQColor(_definition.material.base);
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-26 22:30:20 +00:00
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
waterCopyDefinition(&_definition, &_water);
|
|
|
|
sceneryGetTerrain(&_terrain);
|
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
private:
|
2012-01-26 22:30:20 +00:00
|
|
|
WaterDefinition _water;
|
2012-01-24 13:16:20 +00:00
|
|
|
TerrainDefinition _terrain;
|
2011-12-27 19:03:46 +00:00
|
|
|
};
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewWaterColor:public BasePreview
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-21 13:41:02 +00:00
|
|
|
PreviewWaterColor(QWidget* parent):BasePreview(parent)
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
2012-01-28 18:32:08 +00:00
|
|
|
LightDefinition light;
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
_water = waterCreateDefinition();
|
2012-01-28 18:32:08 +00:00
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
|
|
|
light.color = COLOR_WHITE;
|
|
|
|
light.amplitude = 0.0;
|
|
|
|
light.direction.x = 0.0;
|
|
|
|
light.direction.y = -0.4794;
|
|
|
|
light.direction.z = 0.8776;
|
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 0;
|
|
|
|
light.reflection = 1.0;
|
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
lightingValidateDefinition(&_lighting);
|
2012-01-26 22:30:20 +00:00
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
_renderer = rendererCreate();
|
2012-01-24 13:16:20 +00:00
|
|
|
_renderer.rayWalking = _rayWalking;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.getLightStatus = _getLightStatus;
|
2012-01-28 18:32:08 +00:00
|
|
|
_renderer.customData[0] = &_water;
|
|
|
|
_renderer.customData[1] = &_lighting;
|
2012-04-12 20:02:31 +00:00
|
|
|
|
|
|
|
configScaling(10.0, 1000.0, 10.0, 250.0);
|
2012-06-02 14:17:01 +00:00
|
|
|
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
Vector3 eye, look, location;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (look.y > -0.0001)
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color);
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
location.x = eye.x - look.x * eye.y / look.y;
|
|
|
|
location.y = 0.0;
|
|
|
|
location.z = eye.z - look.z * eye.y / look.y;
|
|
|
|
|
|
|
|
if (location.z > 0.0)
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color);
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 22:30:20 +00:00
|
|
|
return colorToQColor(waterGetColor(&_water, &_renderer, location, look));
|
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
waterCopyDefinition(&_definition, &_water);
|
2012-01-24 13:16:20 +00:00
|
|
|
_water.height = 0.0;
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-01-24 13:16:20 +00:00
|
|
|
Renderer _renderer;
|
|
|
|
WaterDefinition _water;
|
2012-01-28 18:32:08 +00:00
|
|
|
LightingDefinition _lighting;
|
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
|
|
|
RayCastingResult result;
|
|
|
|
double x, y;
|
|
|
|
|
|
|
|
result.hit = 1;
|
|
|
|
if (direction.z < 0.0001)
|
|
|
|
{
|
|
|
|
result.hit_color = COLOR_WHITE;
|
2012-01-24 13:16:20 +00:00
|
|
|
result.hit_location = location;
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
x = location.x + direction.x * (0.0 - location.z) / direction.z;
|
|
|
|
y = location.y + direction.y * (0.0 - location.z) / direction.z;
|
2011-12-27 19:03:46 +00:00
|
|
|
|
2012-06-02 14:17:01 +00:00
|
|
|
//if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0))
|
2012-06-05 20:22:12 +00:00
|
|
|
if (y * 0.1 > x * 0.03 + sin(x - M_PI_2))
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
|
|
|
result.hit_color = COLOR_WHITE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-02 14:17:01 +00:00
|
|
|
result.hit_color = COLOR_BLACK;
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
2012-01-22 18:39:42 +00:00
|
|
|
result.hit_location.x = x;
|
|
|
|
result.hit_location.y = y;
|
|
|
|
result.hit_location.z = 0.0;
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
2011-12-27 19:03:46 +00:00
|
|
|
|
|
|
|
return result;
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
2012-06-05 20:22:12 +00:00
|
|
|
|
|
|
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
2012-01-28 18:32:08 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status);
|
2012-01-28 18:32:08 +00:00
|
|
|
}
|
2011-12-26 21:53:29 +00:00
|
|
|
};
|
2011-12-25 21:19:32 +00:00
|
|
|
|
2011-12-27 19:03:46 +00:00
|
|
|
/**************** Form ****************/
|
2012-01-06 16:09:03 +00:00
|
|
|
FormWater::FormWater(QWidget *parent):
|
2012-01-05 16:32:41 +00:00
|
|
|
BaseForm(parent)
|
2011-12-25 21:19:32 +00:00
|
|
|
{
|
2011-12-27 19:03:46 +00:00
|
|
|
_definition = waterCreateDefinition();
|
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
previewCoverage = new PreviewWaterCoverage(this);
|
|
|
|
previewColor = new PreviewWaterColor(this);
|
2012-02-28 13:45:11 +00:00
|
|
|
addPreview(previewCoverage, QString(tr("Coverage preview")));
|
2012-06-05 20:22:12 +00:00
|
|
|
addPreview(previewColor, QString(tr("Rendered preview")));
|
2012-02-28 13:45:11 +00:00
|
|
|
|
|
|
|
addInputDouble(tr("Height"), &_definition.height, -10.0, 10.0, 0.1, 1.0);
|
2012-06-02 09:46:24 +00:00
|
|
|
addInputMaterial(tr("Surface material"), &_definition.material);
|
|
|
|
addInputColor(tr("Depth color"), &_definition.depth_color);
|
2012-02-28 13:45:11 +00:00
|
|
|
addInputDouble(tr("Transparency"), &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
|
|
|
|
addInputDouble(tr("Reflection"), &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
|
|
|
|
addInputDouble(tr("Transparency distance"), &_definition.transparency_depth, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputDouble(tr("Light-through distance"), &_definition.lighting_depth, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputNoise(tr("Waves noise"), _definition.waves_noise);
|
|
|
|
addInputDouble(tr("Waves height"), &_definition.waves_noise_height, 0.0, 0.1, 0.001, 0.01);
|
|
|
|
addInputDouble(tr("Waves scaling"), &_definition.waves_noise_scale, 0.01, 1.0, 0.01, 0.1);
|
2011-12-27 19:03:46 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
void FormWater::revertConfig()
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
sceneryGetWater(&_definition);
|
2012-01-05 18:39:17 +00:00
|
|
|
BaseForm::revertConfig();
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
void FormWater::applyConfig()
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
scenerySetWater(&_definition);
|
2012-01-07 16:53:23 +00:00
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|