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)
|
|
|
|
{
|
2013-03-11 14:15:30 +00:00
|
|
|
_renderer = sceneryCreateStandardRenderer();
|
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
|
|
|
|
2013-03-31 20:27:21 +00:00
|
|
|
_no_clouds = (CloudsDefinition*)CloudsDefinitionClass.create();
|
2013-03-11 14:15:30 +00:00
|
|
|
_clouds_enabled = true;
|
|
|
|
|
2012-06-26 19:36:50 +00:00
|
|
|
addOsd(QString("geolocation"));
|
2013-03-11 14:15:30 +00:00
|
|
|
addToggle("clouds", tr("Clouds"), false);
|
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-03-31 20:27:21 +00:00
|
|
|
if (height < _renderer->water->getHeightInfo(_renderer).max_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()
|
|
|
|
{
|
2013-03-11 14:15:30 +00:00
|
|
|
sceneryBindRenderer(_renderer);
|
2013-01-20 15:07:45 +00:00
|
|
|
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-03-11 14:15:30 +00:00
|
|
|
if (!_clouds_enabled)
|
|
|
|
{
|
2013-03-31 20:27:21 +00:00
|
|
|
CloudsRendererClass.bind(_renderer, _no_clouds);
|
2013-03-11 14:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void toggleChangeEvent(QString key, bool value)
|
|
|
|
{
|
|
|
|
if (key == "clouds")
|
|
|
|
{
|
|
|
|
_clouds_enabled = value;
|
|
|
|
redraw();
|
|
|
|
}
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
|
|
|
private:
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* _renderer;
|
2013-03-11 14:15:30 +00:00
|
|
|
bool _clouds_enabled;
|
2013-03-31 20:27:21 +00:00
|
|
|
CloudsDefinition* _no_clouds;
|
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));
|
|
|
|
}
|
|
|
|
|
2013-03-14 17:29:12 +00:00
|
|
|
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
|
2012-12-02 11:08:56 +00:00
|
|
|
{
|
2013-03-14 17:29:12 +00:00
|
|
|
AtmosphereResult result;
|
2013-04-03 20:37:29 +00:00
|
|
|
atmosphereInitResult(&result);
|
2013-03-14 17:29:12 +00:00
|
|
|
result.base = base;
|
|
|
|
result.final = base;
|
2013-04-03 20:37:29 +00:00
|
|
|
atmosphereUpdateResult(&result);
|
2013-03-14 17:29:12 +00:00
|
|
|
return result;
|
2012-12-02 11:08:56 +00:00
|
|
|
}
|
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
|
|
|
}
|