2012-01-06 16:09:03 +00:00
|
|
|
#include "formrender.h"
|
|
|
|
|
|
|
|
#include "dialogrender.h"
|
2012-01-27 23:01:21 +00:00
|
|
|
#include "inputcamera.h"
|
2012-04-12 20:02:31 +00:00
|
|
|
#include "tools.h"
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/render.h"
|
2012-01-27 23:01:21 +00:00
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-01-06 16:09:03 +00:00
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
/**************** Previews ****************/
|
|
|
|
class PreviewRenderLandscape:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewRenderLandscape(QWidget* parent):BasePreview(parent)
|
|
|
|
{
|
|
|
|
_renderer = rendererCreate();
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->applyTextures = _applyTextures;
|
2013-01-31 15:10:11 +00:00
|
|
|
_renderer->getCameraLocation = _getCameraLocation;
|
2013-03-07 14:07:12 +00:00
|
|
|
lightingManagerDisableSpecularity(_renderer->lighting);
|
2012-04-12 20:02:31 +00:00
|
|
|
|
|
|
|
_textures = texturesCreateDefinition();
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-11-25 21:53:01 +00:00
|
|
|
_atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
|
2012-12-09 17:49:28 +00:00
|
|
|
_terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
2013-02-28 15:34:47 +00:00
|
|
|
_water = (WaterDefinition*)WaterDefinitionClass.create();
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2013-02-28 15:34:47 +00:00
|
|
|
_renderer->customData[0] = &_textures;
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-06-26 19:36:50 +00:00
|
|
|
addOsd(QString("geolocation"));
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
configHdrToneMapping(true);
|
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-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
protected:
|
2013-01-16 14:26:46 +00:00
|
|
|
Color getColor(double x, double y)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
|
|
|
Vector3 location;
|
2013-01-20 15:07:45 +00:00
|
|
|
double height = _renderer->terrain->getHeight(_renderer, x, y, 1);
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2013-02-28 15:34:47 +00:00
|
|
|
if (height < _water->height)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2013-02-28 15:34:47 +00:00
|
|
|
return _renderer->water->getResult(_renderer, x, y).final;
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
location.x = x;
|
|
|
|
location.y = height;
|
|
|
|
location.z = y;
|
2013-01-20 15:07:45 +00:00
|
|
|
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
sceneryGetTextures(&_textures);
|
2013-02-28 15:34:47 +00:00
|
|
|
|
|
|
|
sceneryGetWater(_water);
|
|
|
|
WaterRendererClass.bind(_renderer, _water);
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-11-25 21:53:01 +00:00
|
|
|
sceneryGetAtmosphere(_atmosphere);
|
2013-01-20 15:07:45 +00:00
|
|
|
AtmosphereRendererClass.bind(_renderer, _atmosphere);
|
|
|
|
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
|
|
|
sceneryGetTerrain(_terrain);
|
2013-01-20 15:07:45 +00:00
|
|
|
TerrainRendererClass.bind(_renderer, _terrain);
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
private:
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* _renderer;
|
2012-12-09 17:49:28 +00:00
|
|
|
TerrainDefinition* _terrain;
|
2013-02-28 15:34:47 +00:00
|
|
|
WaterDefinition *_water;
|
2012-04-12 20:02:31 +00:00
|
|
|
TexturesDefinition _textures;
|
2012-11-25 21:53:01 +00:00
|
|
|
AtmosphereDefinition* _atmosphere;
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2013-02-28 15:34:47 +00:00
|
|
|
return texturesGetColor((TexturesDefinition*)(renderer->customData[0]), renderer, location.x, location.z, precision);
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
2012-06-24 16:04:01 +00:00
|
|
|
|
2013-02-03 21:18:32 +00:00
|
|
|
static Vector3 _getCameraLocation(Renderer*, Vector3 location)
|
2013-01-31 15:10:11 +00:00
|
|
|
{
|
|
|
|
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
|
|
|
|
}
|
|
|
|
|
2012-12-24 14:13:19 +00:00
|
|
|
static Color _applyAerialPerspective(Renderer*, Vector3, Color base)
|
2012-12-02 11:08:56 +00:00
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
2012-04-12 20:02:31 +00:00
|
|
|
};
|
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
/**************** Form ****************/
|
|
|
|
FormRender::FormRender(QWidget *parent) :
|
2012-01-27 23:01:21 +00:00
|
|
|
BaseForm(parent, true)
|
2012-01-06 16:09:03 +00:00
|
|
|
{
|
|
|
|
QPushButton* button;
|
|
|
|
|
2012-06-13 15:38:11 +00:00
|
|
|
_params.quality = 5;
|
|
|
|
_params.width = 800;
|
|
|
|
_params.height = 600;
|
|
|
|
_params.antialias = 1;
|
2012-01-27 23:01:21 +00:00
|
|
|
_camera = cameraCreateDefinition();
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-04-02 19:38:59 +00:00
|
|
|
_renderer_inited = false;
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-06-27 13:28:12 +00:00
|
|
|
disablePreviewsUpdate();
|
2012-01-27 23:01:21 +00:00
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
_preview_landscape = new PreviewRenderLandscape(this);
|
|
|
|
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
addInput(new InputCamera(this, tr("Camera"), &_camera));
|
2012-06-13 15:38:11 +00:00
|
|
|
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);
|
|
|
|
addInputInt(tr("Image width"), &_params.width, 100, 2000, 10, 100);
|
2012-06-15 19:45:41 +00:00
|
|
|
addInputInt(tr("Image height"), &_params.height, 100, 1200, 10, 100);
|
2012-06-13 15:38:11 +00:00
|
|
|
addInputInt(tr("Anti aliasing"), &_params.antialias, 1, 4, 1, 1);
|
2012-01-06 16:09:03 +00:00
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
button = addButton(tr("Start new render"));
|
2012-01-06 16:09:03 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(startRender()));
|
2012-02-28 13:45:11 +00:00
|
|
|
button = addButton(tr("Show last render"));
|
2012-01-06 16:09:03 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(showRender()));
|
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
2012-04-02 19:38:59 +00:00
|
|
|
FormRender::~FormRender()
|
|
|
|
{
|
|
|
|
if (_renderer_inited)
|
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
rendererDelete(_renderer);
|
2012-04-02 19:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
void FormRender::savePack(PackStream* stream)
|
|
|
|
{
|
|
|
|
BaseForm::savePack(stream);
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
packWriteInt(stream, &_params.width);
|
|
|
|
packWriteInt(stream, &_params.height);
|
|
|
|
packWriteInt(stream, &_params.antialias);
|
|
|
|
packWriteInt(stream, &_params.quality);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormRender::loadPack(PackStream* stream)
|
|
|
|
{
|
|
|
|
BaseForm::loadPack(stream);
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
packReadInt(stream, &_params.width);
|
|
|
|
packReadInt(stream, &_params.height);
|
|
|
|
packReadInt(stream, &_params.antialias);
|
|
|
|
packReadInt(stream, &_params.quality);
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
2012-01-27 23:01:21 +00:00
|
|
|
void FormRender::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetCamera(&_camera);
|
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormRender::applyConfig()
|
|
|
|
{
|
|
|
|
scenerySetCamera(&_camera);
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormRender::configChangeEvent()
|
|
|
|
{
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(&_camera, 1);
|
2012-01-27 23:01:21 +00:00
|
|
|
BaseForm::configChangeEvent();
|
|
|
|
}
|
|
|
|
|
2012-04-02 19:38:59 +00:00
|
|
|
void FormRender::startQuickRender()
|
|
|
|
{
|
|
|
|
if (_renderer_inited)
|
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
rendererDelete(_renderer);
|
2012-04-02 19:38:59 +00:00
|
|
|
}
|
|
|
|
_renderer = sceneryCreateStandardRenderer();
|
|
|
|
_renderer_inited = true;
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
DialogRender* dialog = new DialogRender(this, _renderer);
|
2012-06-13 15:38:11 +00:00
|
|
|
RenderParams params = {400, 300, 1, 3};
|
|
|
|
dialog->startRender(params);
|
2012-04-02 19:38:59 +00:00
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
void FormRender::startRender()
|
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
if (_renderer_inited)
|
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
rendererDelete(_renderer);
|
2012-04-02 19:38:59 +00:00
|
|
|
}
|
|
|
|
_renderer = sceneryCreateStandardRenderer();
|
|
|
|
_renderer_inited = true;
|
2012-12-02 11:08:56 +00:00
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
DialogRender* dialog = new DialogRender(this, _renderer);
|
2012-06-13 15:38:11 +00:00
|
|
|
dialog->startRender(_params);
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormRender::showRender()
|
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
if (_renderer_inited)
|
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
DialogRender* dialog = new DialogRender(this, _renderer);
|
2012-04-02 19:38:59 +00:00
|
|
|
dialog->loadLastRender();
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-04-02 19:38:59 +00:00
|
|
|
delete dialog;
|
|
|
|
}
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|