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
|
|
|
|
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-12-10 22:05:53 +00:00
|
|
|
#include "dialogheightmap.h"
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-12-09 17:49:28 +00:00
|
|
|
static TerrainDefinition* _definition;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
/**************** 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-12-09 17:49:28 +00:00
|
|
|
_renderer = rendererCreate();
|
|
|
|
|
2012-06-25 20:11:15 +00:00
|
|
|
addOsd(QString("geolocation"));
|
2012-12-09 17:49:28 +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-12-09 17:49:28 +00:00
|
|
|
double height = 0.0;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-12-09 17:49:28 +00:00
|
|
|
// TODO
|
|
|
|
//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()
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
2012-01-25 22:32:06 +00:00
|
|
|
}
|
|
|
|
private:
|
2012-12-09 17:49:28 +00:00
|
|
|
Renderer _renderer;
|
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;
|
2012-06-05 20:22:12 +00:00
|
|
|
_renderer.getLightStatus = _getLightStatus;
|
2012-12-10 22:05:53 +00:00
|
|
|
_renderer.alterLight = _alterLight;
|
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
|
|
|
|
|
|
|
_textures = texturesCreateDefinition();
|
2012-08-26 13:06:42 +00:00
|
|
|
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));
|
2012-04-12 20:02:31 +00:00
|
|
|
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[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-12-09 17:49:28 +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-12-09 17:49:28 +00:00
|
|
|
Vector3 point;
|
|
|
|
|
|
|
|
point.x = x;
|
|
|
|
point.y = _renderer.terrain->getHeight(&_renderer, x, y);
|
|
|
|
point.z = y;
|
|
|
|
|
|
|
|
return colorToQColor(_renderer.terrain->getFinalColor(&_renderer, point, scaling));
|
2012-01-25 22:32:06 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
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
|
|
|
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 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 _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-12-09 17:49:28 +00:00
|
|
|
|
2012-12-10 22:05:53 +00:00
|
|
|
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
|
|
|
{
|
|
|
|
*light = renderer->terrain->alterLight(renderer, light, location);
|
|
|
|
}
|
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************** Form ****************/
|
|
|
|
FormTerrain::FormTerrain(QWidget *parent):
|
|
|
|
BaseForm(parent)
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
_definition = (TerrainDefinition*)TerrainDefinitionClass.create();
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-12-10 22:05:53 +00:00
|
|
|
QPushButton* button = addButton(tr("Paint"));
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(startPainting()));
|
|
|
|
|
2012-01-22 18:39:42 +00:00
|
|
|
previewHeight = new PreviewTerrainHeight(this);
|
|
|
|
previewColor = new PreviewTerrainColor(this);
|
2012-08-02 19:26:22 +00:00
|
|
|
addPreview(previewHeight, tr("Height preview (normalized)"));
|
|
|
|
addPreview(previewColor, tr("Lighted preview (no texture)"));
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-12-09 17:49:28 +00:00
|
|
|
//addInputNoise(tr("Noise"), _definition.height_noise);
|
|
|
|
addInputDouble(tr("Height"), &_definition->height, 0.0, 20.0, 0.1, 1.0);
|
|
|
|
addInputDouble(tr("Scaling"), &_definition->scaling, 20.0, 200.0, 1.0, 10.0);
|
|
|
|
addInputDouble(tr("Shadow smoothing"), &_definition->shadow_smoothing, 0.0, 0.3, 0.003, 0.03);
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::revertConfig()
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
sceneryGetTerrain(_definition);
|
2012-01-22 18:39:42 +00:00
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTerrain::applyConfig()
|
|
|
|
{
|
2012-12-09 17:49:28 +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
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
TerrainDefinitionClass.validate(_definition);
|
2012-01-25 22:32:06 +00:00
|
|
|
BaseForm::configChangeEvent();
|
2012-01-23 23:45:33 +00:00
|
|
|
}
|
2012-12-10 22:05:53 +00:00
|
|
|
|
|
|
|
void FormTerrain::startPainting()
|
|
|
|
{
|
|
|
|
DialogHeightMap::editHeightMap(this, _definition);
|
|
|
|
}
|