2012-01-22 18:39:42 +00:00
|
|
|
#include "formterrain.h"
|
|
|
|
|
2012-06-25 20:11:15 +00:00
|
|
|
#include <math.h>
|
2012-01-22 18:39:42 +00:00
|
|
|
#include <QColor>
|
|
|
|
#include <QSlider>
|
2012-06-25 20:11:15 +00:00
|
|
|
#include "tools.h"
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
#include "../lib_paysages/terrain.h"
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-05-11 13:34:45 +00:00
|
|
|
#include "../lib_paysages/euclid.h"
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
static TerrainDefinition _definition;
|
|
|
|
|
|
|
|
/**************** Previews ****************/
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewTerrainHeight:public BasePreview
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-21 13:41:02 +00:00
|
|
|
PreviewTerrainHeight(QWidget* parent):BasePreview(parent)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
2012-01-25 22:32:06 +00:00
|
|
|
_preview_definition = terrainCreateDefinition();
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2012-06-25 20:11:15 +00:00
|
|
|
addOsd(QString("geolocation"));
|
|
|
|
|
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);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
2012-06-17 09:40:40 +00:00
|
|
|
QColor getColor(double x, double y)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double height;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
height = terrainGetHeightNormalized(&_preview_definition, x, y);
|
2012-01-22 18:39:42 +00:00
|
|
|
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
|
|
|
}
|
2012-01-25 22:32:06 +00:00
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
terrainCopyDefinition(&_definition, &_preview_definition);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
TerrainDefinition _preview_definition;
|
2012-01-22 18:39:42 +00:00
|
|
|
};
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
class PreviewTerrainColor:public BasePreview
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-21 13:41:02 +00:00
|
|
|
PreviewTerrainColor(QWidget* parent):BasePreview(parent)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
2012-04-12 20:02:31 +00:00
|
|
|
LightDefinition light;
|
|
|
|
TextureLayerDefinition* texture;
|
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
_renderer = rendererCreate();
|
2012-06-02 10:03:48 +00:00
|
|
|
_renderer.render_quality = 3;
|
2012-01-26 22:30:20 +00:00
|
|
|
_renderer.applyTextures = _applyTextures;
|
|
|
|
_renderer.getTerrainHeight = _getTerrainHeight;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.alterLight = _alterLight;
|
|
|
|
_renderer.getLightStatus = _getLightStatus;
|
2012-04-12 20:20:57 +00:00
|
|
|
_renderer.camera_location.x = 0.0;
|
|
|
|
_renderer.camera_location.y = 50.0;
|
|
|
|
_renderer.camera_location.z = 0.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
2012-04-12 20:20:57 +00:00
|
|
|
light.color.r = 0.6;
|
|
|
|
light.color.g = 0.6;
|
|
|
|
light.color.b = 0.6;
|
2012-05-11 13:34:45 +00:00
|
|
|
light.direction.x = -1.0;
|
|
|
|
light.direction.y = -0.5;
|
|
|
|
light.direction.z = 1.0;
|
|
|
|
light.direction = v3Normalize(light.direction);
|
2012-04-12 20:02:31 +00:00
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 1;
|
2012-04-12 20:20:57 +00:00
|
|
|
light.reflection = 1.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
light.color.r = 0.3;
|
|
|
|
light.color.g = 0.3;
|
|
|
|
light.color.b = 0.3;
|
|
|
|
light.direction.x = 0.5;
|
2012-04-12 20:20:57 +00:00
|
|
|
light.direction.y = 0.7071;
|
2012-04-12 20:02:31 +00:00
|
|
|
light.direction.z = -0.5;
|
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 0;
|
|
|
|
light.reflection = 0.0;
|
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
lightingValidateDefinition(&_lighting);
|
2012-01-26 22:30:20 +00:00
|
|
|
|
|
|
|
_terrain = terrainCreateDefinition();
|
|
|
|
_textures = texturesCreateDefinition();
|
2012-04-12 20:02:31 +00:00
|
|
|
texturesAddLayer(&_textures);
|
|
|
|
texture = texturesGetLayer(&_textures, 0);
|
|
|
|
texture->material.base = COLOR_WHITE;
|
2012-04-12 20:20:57 +00:00
|
|
|
texture->material.reflection = 0.3;
|
|
|
|
texture->material.shininess = 2.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
texture->bump_height = 0.0;
|
|
|
|
texturesLayerValidateDefinition(texture);
|
2012-01-26 22:30:20 +00:00
|
|
|
|
|
|
|
_renderer.customData[0] = &_terrain;
|
|
|
|
_renderer.customData[1] = &_textures;
|
2012-04-12 20:02:31 +00:00
|
|
|
_renderer.customData[2] = &_lighting;
|
2012-06-25 20:11:15 +00:00
|
|
|
|
|
|
|
addOsd(QString("geolocation"));
|
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);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
2012-06-17 09:40:40 +00:00
|
|
|
QColor getColor(double x, double y)
|
2012-01-22 18:39:42 +00:00
|
|
|
{
|
2012-01-26 22:30:20 +00:00
|
|
|
return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling));
|
2012-01-25 22:32:06 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-01-26 22:30:20 +00:00
|
|
|
terrainCopyDefinition(&_definition, &_terrain);
|
2012-04-12 20:02:31 +00:00
|
|
|
//sceneryGetTextures(&_textures);
|
2012-01-22 18:39:42 +00:00
|
|
|
}
|
|
|
|
private:
|
2012-01-24 13:16:20 +00:00
|
|
|
Renderer _renderer;
|
2012-01-26 22:30:20 +00:00
|
|
|
TerrainDefinition _terrain;
|
|
|
|
TexturesDefinition _textures;
|
2012-04-12 20:02:31 +00:00
|
|
|
LightingDefinition _lighting;
|
2012-01-26 22:30:20 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static double _getTerrainHeight(Renderer* renderer, double x, double z)
|
2012-01-26 22:30:20 +00:00
|
|
|
{
|
|
|
|
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
2012-01-26 22:30:20 +00:00
|
|
|
{
|
2012-05-05 22:07:02 +00:00
|
|
|
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
|
2012-01-26 22:30:20 +00:00
|
|
|
}
|
2012-06-05 20:22:12 +00:00
|
|
|
|
|
|
|
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
light->color = terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0));
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status);
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
2012-06-05 20:22:12 +00:00
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************** Form ****************/
|
|
|
|
FormTerrain::FormTerrain(QWidget *parent):
|
|
|
|
BaseForm(parent)
|
|
|
|
{
|
|
|
|
_definition = terrainCreateDefinition();
|
|
|
|
|
|
|
|
previewHeight = new PreviewTerrainHeight(this);
|
|
|
|
previewColor = new PreviewTerrainColor(this);
|
2012-02-28 13:45:11 +00:00
|
|
|
addPreview(previewHeight, QString(tr("Height preview (normalized)")));
|
2012-04-12 20:02:31 +00:00
|
|
|
addPreview(previewColor, QString(tr("Lighted preview (no texture)")));
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
addInputNoise(tr("Noise"), _definition.height_noise);
|
|
|
|
addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0);
|
2012-06-24 12:33:59 +00:00
|
|
|
addInputDouble(tr("Scaling"), &_definition.scaling, 1.0, 50.0, 0.1, 5.0);
|
2012-06-17 15:59:20 +00:00
|
|
|
addInputDouble(tr("Shadow smoothing"), &_definition.shadow_smoothing, 0.0, 0.3, 0.003, 0.03);
|
2012-07-10 15:38:12 +00:00
|
|
|
addInputLayers(tr("Canvases"), _definition.canvases);
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::revertConfig()
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
sceneryGetTerrain(&_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::applyConfig()
|
|
|
|
{
|
2012-01-24 13:16:20 +00:00
|
|
|
scenerySetTerrain(&_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
void FormTerrain::configChangeEvent()
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
|
|
|
terrainValidateDefinition(&_definition);
|
2012-01-25 22:32:06 +00:00
|
|
|
BaseForm::configChangeEvent();
|
2012-01-23 23:45:33 +00:00
|
|
|
}
|