paysages : Restored terrain and water previews.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@489 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
eaf72f810c
commit
701e8faba2
5 changed files with 148 additions and 120 deletions
|
@ -1,97 +1,20 @@
|
||||||
#include "formterrain.h"
|
#include "formterrain.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
#include "../lib_paysages/scenery.h"
|
|
||||||
#include "../lib_paysages/euclid.h"
|
|
||||||
#include "dialogheightmap.h"
|
#include "dialogheightmap.h"
|
||||||
|
#include "../lib_paysages/scenery.h"
|
||||||
|
|
||||||
static TerrainDefinition* _definition;
|
static TerrainDefinition* _definition;
|
||||||
|
|
||||||
/**************** Previews ****************/
|
/**************** Previews ****************/
|
||||||
class PreviewTerrainHeight:public BasePreview
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PreviewTerrainHeight(QWidget* parent):BasePreview(parent)
|
|
||||||
{
|
|
||||||
_renderer = rendererCreate();
|
|
||||||
|
|
||||||
addOsd(QString("geolocation"));
|
|
||||||
|
|
||||||
configScaling(0.5, 200.0, 3.0, 50.0);
|
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
QColor getColor(double x, double y)
|
|
||||||
{
|
|
||||||
double height = 0.0;
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
//height = terrainGetHeightNormalized(&_preview_definition, x, y);
|
|
||||||
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
|
||||||
}
|
|
||||||
void updateData()
|
|
||||||
{
|
|
||||||
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Renderer _renderer;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PreviewTerrainColor:public BasePreview
|
class PreviewTerrainColor:public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PreviewTerrainColor(QWidget* parent):BasePreview(parent)
|
PreviewTerrainColor(QWidget* parent):BasePreview(parent)
|
||||||
{
|
{
|
||||||
LightDefinition light;
|
_renderer = terrainCreatePreviewRenderer();
|
||||||
TextureLayerDefinition* texture;
|
|
||||||
|
|
||||||
_renderer = rendererCreate();
|
|
||||||
_renderer.render_quality = 3;
|
|
||||||
_renderer.applyTextures = _applyTextures;
|
|
||||||
_renderer.getLightStatus = _getLightStatus;
|
|
||||||
_renderer.alterLight = _alterLight;
|
|
||||||
_renderer.camera_location.x = 0.0;
|
|
||||||
_renderer.camera_location.y = 50.0;
|
|
||||||
_renderer.camera_location.z = 0.0;
|
|
||||||
|
|
||||||
_lighting = lightingCreateDefinition();
|
|
||||||
light.color.r = 0.6;
|
|
||||||
light.color.g = 0.6;
|
|
||||||
light.color.b = 0.6;
|
|
||||||
light.direction.x = -1.0;
|
|
||||||
light.direction.y = -0.5;
|
|
||||||
light.direction.z = 1.0;
|
|
||||||
light.direction = v3Normalize(light.direction);
|
|
||||||
light.filtered = 0;
|
|
||||||
light.masked = 1;
|
|
||||||
light.reflection = 1.0;
|
|
||||||
lightingAddLight(&_lighting, light);
|
|
||||||
light.color.r = 0.3;
|
|
||||||
light.color.g = 0.3;
|
|
||||||
light.color.b = 0.3;
|
|
||||||
light.direction.x = 0.5;
|
|
||||||
light.direction.y = 0.7071;
|
|
||||||
light.direction.z = -0.5;
|
|
||||||
light.filtered = 0;
|
|
||||||
light.masked = 0;
|
|
||||||
light.reflection = 0.0;
|
|
||||||
lightingAddLight(&_lighting, light);
|
|
||||||
lightingValidateDefinition(&_lighting);
|
|
||||||
|
|
||||||
_textures = texturesCreateDefinition();
|
|
||||||
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));
|
|
||||||
texture->material.base = COLOR_WHITE;
|
|
||||||
texture->material.reflection = 0.3;
|
|
||||||
texture->material.shininess = 2.0;
|
|
||||||
texture->bump_height = 0.0;
|
|
||||||
texturesLayerValidateDefinition(texture);
|
|
||||||
|
|
||||||
_renderer.customData[1] = &_textures;
|
|
||||||
_renderer.customData[2] = &_lighting;
|
|
||||||
|
|
||||||
addOsd(QString("geolocation"));
|
addOsd(QString("geolocation"));
|
||||||
|
|
||||||
|
@ -101,39 +24,14 @@ public:
|
||||||
protected:
|
protected:
|
||||||
QColor getColor(double x, double y)
|
QColor getColor(double x, double y)
|
||||||
{
|
{
|
||||||
Vector3 point;
|
return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling));
|
||||||
|
|
||||||
point.x = x;
|
|
||||||
point.y = _renderer.terrain->getHeight(&_renderer, x, y);
|
|
||||||
point.z = y;
|
|
||||||
|
|
||||||
return colorToQColor(_renderer.terrain->getFinalColor(&_renderer, point, scaling));
|
|
||||||
}
|
}
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
TerrainRendererClass.bind(_renderer.terrain, _definition);
|
||||||
//sceneryGetTextures(&_textures);
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Renderer _renderer;
|
Renderer _renderer;
|
||||||
TexturesDefinition _textures;
|
|
||||||
LightingDefinition _lighting;
|
|
||||||
|
|
||||||
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
|
||||||
{
|
|
||||||
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
|
||||||
{
|
|
||||||
lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
|
||||||
{
|
|
||||||
*light = renderer->terrain->alterLight(renderer, light, location);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**************** Form ****************/
|
/**************** Form ****************/
|
||||||
|
@ -145,9 +43,9 @@ FormTerrain::FormTerrain(QWidget *parent):
|
||||||
QPushButton* button = addButton(tr("Paint"));
|
QPushButton* button = addButton(tr("Paint"));
|
||||||
connect(button, SIGNAL(clicked()), this, SLOT(startPainting()));
|
connect(button, SIGNAL(clicked()), this, SLOT(startPainting()));
|
||||||
|
|
||||||
previewHeight = new PreviewTerrainHeight(this);
|
/*previewHeight = new PreviewTerrainHeight(this);*/
|
||||||
previewColor = new PreviewTerrainColor(this);
|
previewColor = new PreviewTerrainColor(this);
|
||||||
addPreview(previewHeight, tr("Height preview (normalized)"));
|
/*addPreview(previewHeight, tr("Height preview (normalized)"));*/
|
||||||
addPreview(previewColor, tr("Lighted preview (no texture)"));
|
addPreview(previewColor, tr("Lighted preview (no texture)"));
|
||||||
|
|
||||||
//addInputNoise(tr("Noise"), _definition.height_noise);
|
//addInputNoise(tr("Noise"), _definition.height_noise);
|
||||||
|
|
|
@ -23,7 +23,7 @@ private slots:
|
||||||
void startPainting();
|
void startPainting();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BasePreview* previewHeight;
|
/*BasePreview* previewHeight;*/
|
||||||
BasePreview* previewColor;
|
BasePreview* previewColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,38 +20,72 @@ class PreviewWaterCoverage:public BasePreview
|
||||||
public:
|
public:
|
||||||
PreviewWaterCoverage(QWidget* parent):BasePreview(parent)
|
PreviewWaterCoverage(QWidget* parent):BasePreview(parent)
|
||||||
{
|
{
|
||||||
/*_water = waterCreateDefinition();
|
_renderer = terrainCreatePreviewRenderer();
|
||||||
_terrain = terrainCreateDefinition();*/
|
_water = waterCreateDefinition();
|
||||||
|
_highlight_enabled = true;
|
||||||
|
|
||||||
addOsd(QString("geolocation"));
|
addOsd(QString("geolocation"));
|
||||||
|
addToggle("highlight", tr("Coverage highlight"), true);
|
||||||
|
|
||||||
configScaling(0.5, 200.0, 3.0, 50.0);
|
configScaling(0.5, 200.0, 3.0, 50.0);
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
/*protected:
|
protected:
|
||||||
QColor getColor(double x, double y)
|
QColor getColor(double x, double y)
|
||||||
{
|
{
|
||||||
double height;
|
double height;
|
||||||
|
|
||||||
height = terrainGetHeight(&_terrain, x, y);
|
height = _renderer.terrain->getHeight(&_renderer, x, -y);
|
||||||
if (height > _definition.height)
|
if (height > _definition.height)
|
||||||
{
|
{
|
||||||
height = terrainGetHeightNormalized(&_terrain, x, y);
|
return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling));
|
||||||
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return colorToQColor(_definition.material.base);
|
Vector3 location, look;
|
||||||
|
Color base;
|
||||||
|
|
||||||
|
location.x = x;
|
||||||
|
location.y = _water.height;
|
||||||
|
location.z = -y;
|
||||||
|
|
||||||
|
look.x = 0.0;
|
||||||
|
look.y = -1.0;
|
||||||
|
look.z = 0.0;
|
||||||
|
|
||||||
|
base = waterGetColor(&_water, &_renderer, location, look);
|
||||||
|
|
||||||
|
if (_highlight_enabled)
|
||||||
|
{
|
||||||
|
Color mask = {0.5, 0.5, 1.0, 0.5};
|
||||||
|
colorMask(&base, &mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorToQColor(base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
waterCopyDefinition(&_definition, &_water);
|
waterCopyDefinition(&_definition, &_water);
|
||||||
sceneryGetTerrain(&_terrain);
|
|
||||||
}*/
|
// TODO Do this only on full refresh
|
||||||
|
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||||
|
sceneryGetTerrain(terrain);
|
||||||
|
TerrainRendererClass.bind(_renderer.terrain, terrain);
|
||||||
|
TerrainDefinitionClass.destroy(terrain);
|
||||||
|
}
|
||||||
|
void toggleChangeEvent(QString key, bool value)
|
||||||
|
{
|
||||||
|
if (key == "highlight")
|
||||||
|
{
|
||||||
|
_highlight_enabled = value;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
|
Renderer _renderer;
|
||||||
WaterDefinition _water;
|
WaterDefinition _water;
|
||||||
TerrainDefinition _terrain;
|
bool _highlight_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PreviewWaterColor:public BasePreview
|
class PreviewWaterColor:public BasePreview
|
||||||
|
|
95
lib_paysages/terrain/preview.c
Normal file
95
lib_paysages/terrain/preview.c
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
#include "public.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "../renderer.h"
|
||||||
|
#include "../lighting.h"
|
||||||
|
#include "../textures.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Terrain previews.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static TexturesDefinition _textures;
|
||||||
|
static LightingDefinition _lighting;
|
||||||
|
static int _inited = 0;
|
||||||
|
|
||||||
|
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
||||||
|
{
|
||||||
|
return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
||||||
|
{
|
||||||
|
lightingGetStatus(&_lighting, renderer, location, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
||||||
|
{
|
||||||
|
*light = renderer->terrain->alterLight(renderer, light, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer terrainCreatePreviewRenderer()
|
||||||
|
{
|
||||||
|
Renderer result = rendererCreate();
|
||||||
|
|
||||||
|
result.render_quality = 3;
|
||||||
|
result.applyTextures = _applyTextures;
|
||||||
|
result.getLightStatus = _getLightStatus;
|
||||||
|
result.alterLight = _alterLight;
|
||||||
|
result.camera_location.x = 0.0;
|
||||||
|
result.camera_location.y = 50.0;
|
||||||
|
result.camera_location.z = 0.0;
|
||||||
|
|
||||||
|
if (!_inited)
|
||||||
|
{
|
||||||
|
LightDefinition light;
|
||||||
|
TextureLayerDefinition* texture;
|
||||||
|
|
||||||
|
_inited = 1;
|
||||||
|
|
||||||
|
_lighting = lightingCreateDefinition();
|
||||||
|
light.color.r = 0.6;
|
||||||
|
light.color.g = 0.6;
|
||||||
|
light.color.b = 0.6;
|
||||||
|
light.direction.x = -1.0;
|
||||||
|
light.direction.y = -0.5;
|
||||||
|
light.direction.z = -1.0;
|
||||||
|
light.direction = v3Normalize(light.direction);
|
||||||
|
light.filtered = 0;
|
||||||
|
light.masked = 1;
|
||||||
|
light.reflection = 1.0;
|
||||||
|
lightingAddLight(&_lighting, light);
|
||||||
|
light.color.r = 0.3;
|
||||||
|
light.color.g = 0.3;
|
||||||
|
light.color.b = 0.3;
|
||||||
|
light.direction.x = 0.5;
|
||||||
|
light.direction.y = 0.7071;
|
||||||
|
light.direction.z = 0.5;
|
||||||
|
light.filtered = 0;
|
||||||
|
light.masked = 0;
|
||||||
|
light.reflection = 0.0;
|
||||||
|
lightingAddLight(&_lighting, light);
|
||||||
|
lightingValidateDefinition(&_lighting);
|
||||||
|
|
||||||
|
_textures = texturesCreateDefinition();
|
||||||
|
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));
|
||||||
|
texture->material.base = COLOR_WHITE;
|
||||||
|
texture->material.reflection = 0.3;
|
||||||
|
texture->material.shininess = 2.0;
|
||||||
|
texture->bump_height = 0.0;
|
||||||
|
texturesLayerValidateDefinition(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color terrainGetPreviewColor(Renderer* renderer, double x, double z, double detail)
|
||||||
|
{
|
||||||
|
Vector3 point;
|
||||||
|
|
||||||
|
point.x = x;
|
||||||
|
point.y = renderer->terrain->getHeight(renderer, x, z);
|
||||||
|
point.z = z;
|
||||||
|
|
||||||
|
return renderer->terrain->getFinalColor(renderer, point, detail);
|
||||||
|
}
|
|
@ -46,8 +46,9 @@ extern StandardRenderer TerrainRendererClass;
|
||||||
|
|
||||||
void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset);
|
void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset);
|
||||||
void terrainRenderSurface(Renderer* renderer);
|
void terrainRenderSurface(Renderer* renderer);
|
||||||
/*Renderer terrainCreatePreviewRenderer();
|
|
||||||
Color terrainGetPreview(Renderer* renderer, double x, double y);*/
|
Renderer terrainCreatePreviewRenderer();
|
||||||
|
Color terrainGetPreviewColor(Renderer* renderer, double x, double z, double detail);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue