2012-01-06 16:09:03 +00:00
|
|
|
#include "formrender.h"
|
|
|
|
|
2012-01-18 16:20:14 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2012-01-06 16:09:03 +00:00
|
|
|
#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;
|
|
|
|
_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
|
|
|
|
|
|
|
_textures = texturesCreateDefinition();
|
|
|
|
_water = waterCreateDefinition();
|
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();
|
2012-04-12 20:02:31 +00:00
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->customData[0] = &_terrain;
|
|
|
|
_renderer->customData[1] = &_textures;
|
|
|
|
_renderer->customData[3] = &_water;
|
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 down = {0.0, -1.0, 0.0};
|
|
|
|
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
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
if (height < _water.height)
|
|
|
|
{
|
|
|
|
location.x = x;
|
|
|
|
location.y = _water.height;
|
|
|
|
location.z = y;
|
2013-01-20 15:07:45 +00:00
|
|
|
return waterGetColor(&_water, _renderer, location, down);
|
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);
|
|
|
|
sceneryGetWater(&_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;
|
2012-04-12 20:02:31 +00:00
|
|
|
WaterDefinition _water;
|
|
|
|
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
|
|
|
{
|
2012-05-05 22:07:02 +00:00
|
|
|
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
2012-06-24 16:04:01 +00:00
|
|
|
|
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()));
|
2012-02-28 13:45:11 +00:00
|
|
|
button = addButton(tr("Save last render"));
|
2012-01-06 16:09:03 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(saveRender()));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void FormRender::saveRender()
|
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
if (_renderer_inited)
|
2012-01-18 16:20:14 +00:00
|
|
|
{
|
2012-04-02 19:38:59 +00:00
|
|
|
QString filepath;
|
|
|
|
|
2012-04-16 19:24:46 +00:00
|
|
|
filepath = QFileDialog::getSaveFileName(this, tr("Paysages 3D - Choose a filename to save the last render"), QString(), tr("Images (*.png *.jpg)"));
|
2012-04-02 19:38:59 +00:00
|
|
|
if (!filepath.isNull())
|
|
|
|
{
|
2012-04-16 19:24:46 +00:00
|
|
|
if (!filepath.toLower().endsWith(".jpg") && !filepath.toLower().endsWith(".jpeg") && !filepath.toLower().endsWith(".png"))
|
|
|
|
{
|
|
|
|
filepath = filepath.append(".png");
|
|
|
|
}
|
2013-01-20 15:07:45 +00:00
|
|
|
if (renderSaveToFile(_renderer->render_area, (char*)filepath.toStdString().c_str()))
|
2012-05-06 10:13:34 +00:00
|
|
|
{
|
|
|
|
QMessageBox::information(this, "Message", QString(tr("The picture %1 has been saved.")).arg(filepath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, "Message", QString(tr("Can't write to file : %1")).arg(filepath));
|
|
|
|
}
|
2012-04-02 19:38:59 +00:00
|
|
|
}
|
2012-01-18 16:20:14 +00:00
|
|
|
}
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|