Restored choice and toggles working on preview renderers

This commit is contained in:
Michaël Lemaire 2013-11-30 18:06:41 +01:00
parent 684a64158c
commit 7fecdba313
17 changed files with 220 additions and 144 deletions

View file

@ -16,92 +16,7 @@
#include "BasePreview.h" #include "BasePreview.h"
#include "CloudsDefinition.h" #include "CloudsDefinition.h"
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include "SceneryTopDownPreviewRenderer.h"
/**************** Previews ****************/
class PreviewRenderLandscape : public BasePreview
{
public:
PreviewRenderLandscape(QWidget* parent) : BasePreview(parent)
{
_renderer = new SoftwareRenderer();
_renderer->getCameraLocation = _getCameraLocation;
lightingManagerDisableSpecularity(_renderer->lighting);
_no_clouds = new CloudsDefinition(NULL);
_clouds_enabled = true;
addOsd(QString("geolocation"));
addToggle("clouds", tr("Clouds"), false);
configHdrToneMapping(true);
configScaling(0.5, 200.0, 3.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewRenderLandscape()
{
delete _renderer;
delete _no_clouds;
}
protected:
Color getColor(double x, double y)
{
Vector3 location;
double height = _renderer->terrain->getHeight(_renderer, x, y, 1);
if (height < _renderer->water->getHeightInfo(_renderer).max_height)
{
return _renderer->water->getResult(_renderer, x, y).final;
}
else
{
location.x = x;
location.y = height;
location.z = y;
return _renderer->terrain->getFinalColor(_renderer, location, scaling);
}
}
void updateData()
{
RenderingScenery::getCurrent()->bindToRenderer(_renderer);
if (!_clouds_enabled)
{
CloudsRendererClass.bind(_renderer, _no_clouds);
}
_renderer->atmosphere->applyAerialPerspective = _applyAerialPerspective;
}
void toggleChangeEvent(QString key, bool value)
{
if (key == "clouds")
{
_clouds_enabled = value;
redraw();
}
}
private:
SoftwareRenderer* _renderer;
bool _clouds_enabled;
CloudsDefinition* _no_clouds;
static Vector3 _getCameraLocation(Renderer*, Vector3 location)
{
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
}
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
{
AtmosphereResult result;
atmosphereInitResult(&result);
result.base = base;
result.final = base;
atmosphereUpdateResult(&result);
return result;
}
};
/**************** Form ****************/ /**************** Form ****************/
FormRender::FormRender(QWidget *parent) : FormRender::FormRender(QWidget *parent) :
@ -119,8 +34,10 @@ BaseForm(parent, true)
disablePreviewsUpdate(); disablePreviewsUpdate();
_preview_landscape = new PreviewRenderLandscape(this); _preview_landscape = new BasePreview(this);
_preview_landscape_renderer = new SceneryTopDownPreviewRenderer(RenderingScenery::getCurrent());
addPreview(_preview_landscape, QString(tr("Top-down preview"))); addPreview(_preview_landscape, QString(tr("Top-down preview")));
_preview_landscape->setRenderer(_preview_landscape_renderer);
addInput(new InputCamera(this, tr("Camera"), _camera)); addInput(new InputCamera(this, tr("Camera"), _camera));
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1); addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);

View file

@ -32,6 +32,7 @@ private:
Renderer* _renderer; Renderer* _renderer;
bool _renderer_inited; bool _renderer_inited;
BasePreview* _preview_landscape; BasePreview* _preview_landscape;
Base2dPreviewRenderer* _preview_landscape_renderer;
}; };
#endif #endif

View file

@ -16,6 +16,14 @@ void Base2dPreviewRenderer::bindEvent(BasePreview*)
{ {
} }
void Base2dPreviewRenderer::toggleChangeEvent(const std::string &, bool)
{
}
void Base2dPreviewRenderer::choiceChangeEvent(const std::string &, int)
{
}
void Base2dPreviewRenderer::updateEvent() void Base2dPreviewRenderer::updateEvent()
{ {
} }

View file

@ -19,6 +19,9 @@ public:
virtual void bindEvent(BasePreview* preview); virtual void bindEvent(BasePreview* preview);
virtual void toggleChangeEvent(const std::string &key, bool value);
virtual void choiceChangeEvent(const std::string &key, int position);
virtual void updateEvent(); virtual void updateEvent();
virtual void cameraEvent(double x, double y, double scaling); virtual void cameraEvent(double x, double y, double scaling);
virtual Color getColor2D(double x, double y, double scaling); virtual Color getColor2D(double x, double y, double scaling);

View file

@ -563,8 +563,13 @@ void BasePreview::addChoice(const QString& key, const QString& title, const QStr
choiceChangeEvent(key, init_value); choiceChangeEvent(key, init_value);
} }
void BasePreview::choiceChangeEvent(const QString&, int) void BasePreview::choiceChangeEvent(const QString &key, int position)
{ {
if (_renderer)
{
_renderer->choiceChangeEvent(key.toStdString(), position);
}
redraw();
} }
void BasePreview::addToggle(const QString &key, const QString &text, bool init_value) void BasePreview::addToggle(const QString &key, const QString &text, bool init_value)
@ -578,8 +583,12 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v
toggleChangeEvent(key, init_value); toggleChangeEvent(key, init_value);
} }
void BasePreview::toggleChangeEvent(QString, bool) void BasePreview::toggleChangeEvent(const QString &key, bool value)
{ {
if (_renderer)
{
_renderer->toggleChangeEvent(key.toStdString(), value);
}
redraw(); redraw();
} }

View file

@ -63,7 +63,7 @@ public:
virtual void choiceChangeEvent(const QString &key, int position); virtual void choiceChangeEvent(const QString &key, int position);
void addToggle(const QString &key, const QString &text, bool init_value); void addToggle(const QString &key, const QString &text, bool init_value);
virtual void toggleChangeEvent(QString key, bool value); virtual void toggleChangeEvent(const QString &key, bool value);
protected: protected:
virtual void updateData(); virtual void updateData();

View file

@ -63,3 +63,11 @@ Color CloudsCoveragePreviewRenderer::getColor2D(double x, double y, double scali
return clouds->getColor(this, COLOR_BLUE, start, end); return clouds->getColor(this, COLOR_BLUE, start, end);
} }
} }
void CloudsCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
{
if (key == "3d")
{
perspective = value;
}
}

View file

@ -17,6 +17,8 @@ public:
virtual void updateEvent() override; virtual void updateEvent() override;
virtual Color getColor2D(double x, double y, double scaling) override; virtual Color getColor2D(double x, double y, double scaling) override;
virtual void toggleChangeEvent(const std::string &key, bool value) override;
private: private:
bool perspective; bool perspective;
CloudLayerDefinition* layer; CloudLayerDefinition* layer;

View file

@ -0,0 +1,90 @@
#include "SceneryTopDownPreviewRenderer.h"
#include "CloudsDefinition.h"
#include "BasePreview.h"
#include "Scenery.h"
// TEMP
#include "atmosphere/public.h"
#include "tools/lighting.h"
#include "terrain/public.h"
#include "water/public.h"
static Vector3 _getCameraLocation(Renderer*, Vector3 location)
{
return v3Add(location, v3Scale(VECTOR_UP, 50.0));
}
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
{
AtmosphereResult result;
atmosphereInitResult(&result);
result.base = base;
result.final = base;
atmosphereUpdateResult(&result);
return result;
}
SceneryTopDownPreviewRenderer::SceneryTopDownPreviewRenderer(Scenery* scenery):
scenery(scenery)
{
clouds_enabled = true;
}
void SceneryTopDownPreviewRenderer::bindEvent(BasePreview* preview)
{
no_clouds = new CloudsDefinition(NULL);
clouds_enabled = true;
// TODO Translation
preview->addOsd("geolocation");
preview->addToggle("clouds", "Clouds", false);
preview->configHdrToneMapping(true);
preview->configScaling(0.5, 200.0, 3.0, 50.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
void SceneryTopDownPreviewRenderer::updateEvent()
{
setScenery(scenery);
if (not clouds_enabled)
{
getScenery()->getClouds()->clear();
}
prepare();
getCameraLocation = _getCameraLocation;
lightingManagerDisableSpecularity(lighting);
atmosphere->applyAerialPerspective = _applyAerialPerspective;
}
Color SceneryTopDownPreviewRenderer::getColor2D(double x, double y, double scaling)
{
Vector3 location;
double height = terrain->getHeight(this, x, y, 1);
if (height < water->getHeightInfo(this).max_height)
{
return water->getResult(this, x, y).final;
}
else
{
location.x = x;
location.y = height;
location.z = y;
return terrain->getFinalColor(this, location, scaling);
}
}
void SceneryTopDownPreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
{
if (key == "clouds")
{
clouds_enabled = value;
}
}

View file

@ -0,0 +1,31 @@
#ifndef SCENERYTOPDOWNPREVIEWRENDERER_H
#define SCENERYTOPDOWNPREVIEWRENDERER_H
#include "preview_global.h"
#include "Base2dPreviewRenderer.h"
namespace paysages {
namespace preview {
class PREVIEWSHARED_EXPORT SceneryTopDownPreviewRenderer : public Base2dPreviewRenderer
{
public:
SceneryTopDownPreviewRenderer(Scenery* scenery);
protected:
virtual void bindEvent(BasePreview* preview) override;
virtual void updateEvent() override;
virtual Color getColor2D(double x, double y, double scaling) override;
virtual void toggleChangeEvent(const std::string &key, bool value) override;
private:
Scenery* scenery;
bool clouds_enabled;
CloudsDefinition* no_clouds;
};
}
}
#endif // SCENERYTOPDOWNPREVIEWRENDERER_H

View file

@ -70,7 +70,6 @@ static void _alterPreviewRenderer(Renderer* renderer)
TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terrain) TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terrain)
{ {
_terrain = terrain; _terrain = terrain;
_highlight_enabled = true;
_alterPreviewRenderer(this); _alterPreviewRenderer(this);
} }
@ -78,7 +77,6 @@ TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terr
void TerrainShapePreviewRenderer::bindEvent(BasePreview* preview) void TerrainShapePreviewRenderer::bindEvent(BasePreview* preview)
{ {
preview->addOsd(QString("geolocation")); preview->addOsd(QString("geolocation"));
//preview->addToggle("highlight", tr("Coverage highlight"), true);
preview->configScaling(20.0, 1000.0, 20.0, 200.0); preview->configScaling(20.0, 1000.0, 20.0, 200.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
@ -89,7 +87,7 @@ void TerrainShapePreviewRenderer::updateEvent()
TerrainRendererClass.bind(this, _terrain); TerrainRendererClass.bind(this, _terrain);
} }
Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double) Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double scaling)
{ {
double height; double height;
@ -100,24 +98,11 @@ Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double)
} }
else else
{ {
Color base; return getWaterColor(x, y, scaling);
}
}
base = water->getResult(this, x, y).final; Color TerrainShapePreviewRenderer::getWaterColor(double, double, double)
if (_highlight_enabled)
{ {
Color mask = {0.5, 0.5, 1.0, 0.5}; return COLOR_BLUE;
colorMask(&base, &mask);
}
return base;
}
}
void TerrainShapePreviewRenderer::toggleChangeEvent(QString key, bool value)
{
if (key == "highlight")
{
_highlight_enabled = value;
}
} }

View file

@ -14,15 +14,15 @@ public:
explicit TerrainShapePreviewRenderer(TerrainDefinition* terrain); explicit TerrainShapePreviewRenderer(TerrainDefinition* terrain);
protected: protected:
virtual void bindEvent(BasePreview* preview); virtual void bindEvent(BasePreview* preview) override;
virtual void updateEvent(); virtual void updateEvent() override;
virtual Color getColor2D(double x, double y, double scaling) override; virtual Color getColor2D(double x, double y, double scaling) override;
virtual void toggleChangeEvent(QString key, bool value);
virtual Color getWaterColor(double x, double y, double scaling);
TerrainDefinition* _terrain; TerrainDefinition* _terrain;
private: private:
bool _highlight_enabled;
double _water_height; double _water_height;
}; };

View file

@ -155,3 +155,19 @@ Color WaterAspectPreviewRenderer::getColor2D(double x, double y, double scaling)
return water->getResult(this, target_x, target_z).final; return water->getResult(this, target_x, target_z).final;
} }
void WaterAspectPreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
{
if (key == "light")
{
lighting = value;
}
}
void WaterAspectPreviewRenderer::choiceChangeEvent(const std::string &key, int position)
{
if (key == "bg")
{
background = position;
}
}

View file

@ -18,6 +18,9 @@ public:
virtual void cameraEvent(double x, double y, double scaling) override; virtual void cameraEvent(double x, double y, double scaling) override;
virtual Color getColor2D(double x, double y, double scaling) override; virtual Color getColor2D(double x, double y, double scaling) override;
virtual void toggleChangeEvent(const std::string &key, bool value) override;
virtual void choiceChangeEvent(const std::string &key, int position) override;
private: private:
WaterDefinition* definition; WaterDefinition* definition;
bool lighting; bool lighting;

View file

@ -22,33 +22,32 @@ WaterCoveragePreviewRenderer::~WaterCoveragePreviewRenderer()
void WaterCoveragePreviewRenderer::bindEvent(BasePreview* preview) void WaterCoveragePreviewRenderer::bindEvent(BasePreview* preview)
{ {
preview->addOsd("geolocation"); TerrainShapePreviewRenderer::bindEvent(preview);
// TODO Translation // TODO Translation
preview->addToggle("highlight", "Coverage highlight", true); preview->addToggle("highlight", "Coverage highlight", true);
preview->configScaling(20.0, 1000.0, 20.0, 200.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
// TODO Keep camera above center (for reflections) // TODO Keep camera above center (for reflections)
} }
void WaterCoveragePreviewRenderer::toggleChangeEvent(const std::string &key, bool value)
{
if (key == "highlight")
{
highlight = value;
}
}
void WaterCoveragePreviewRenderer::updateEvent() void WaterCoveragePreviewRenderer::updateEvent()
{ {
getScenery()->setWater(definition);
RenderingScenery::getCurrent()->getTerrain(_terrain); RenderingScenery::getCurrent()->getTerrain(_terrain);
TerrainShapePreviewRenderer::updateEvent(); TerrainShapePreviewRenderer::updateEvent();
getScenery()->setWater(definition);
WaterRendererClass.bind(this, definition);
} }
Color WaterCoveragePreviewRenderer::getColor2D(double x, double y, double scaling) Color WaterCoveragePreviewRenderer::getWaterColor(double x, double y, double)
{
double height;
height = terrain->getHeight(this, x, y, 1);
if (height > terrain->getWaterHeight(this))
{
return TerrainShapePreviewRenderer::getColor2D(x, y, scaling);
}
else
{ {
Color base; Color base;
@ -62,4 +61,3 @@ Color WaterCoveragePreviewRenderer::getColor2D(double x, double y, double scalin
return base; return base;
} }
}

View file

@ -16,7 +16,10 @@ public:
virtual void bindEvent(BasePreview* preview) override; virtual void bindEvent(BasePreview* preview) override;
virtual void updateEvent() override; virtual void updateEvent() override;
virtual Color getColor2D(double x, double y, double scaling) override;
virtual Color getWaterColor(double x, double y, double scaling) override;
virtual void toggleChangeEvent(const std::string &key, bool value) override;
private: private:
WaterDefinition* definition; WaterDefinition* definition;

View file

@ -22,7 +22,8 @@ SOURCES += Base2dPreviewRenderer.cpp \
CloudsAspectPreviewRenderer.cpp \ CloudsAspectPreviewRenderer.cpp \
WaterCoveragePreviewRenderer.cpp \ WaterCoveragePreviewRenderer.cpp \
WaterAspectPreviewRenderer.cpp \ WaterAspectPreviewRenderer.cpp \
TerrainShapePreviewRenderer.cpp TerrainShapePreviewRenderer.cpp \
SceneryTopDownPreviewRenderer.cpp
HEADERS += Base2dPreviewRenderer.h\ HEADERS += Base2dPreviewRenderer.h\
preview_global.h \ preview_global.h \
@ -35,7 +36,8 @@ HEADERS += Base2dPreviewRenderer.h\
CloudsAspectPreviewRenderer.h \ CloudsAspectPreviewRenderer.h \
WaterCoveragePreviewRenderer.h \ WaterCoveragePreviewRenderer.h \
WaterAspectPreviewRenderer.h \ WaterAspectPreviewRenderer.h \
TerrainShapePreviewRenderer.h TerrainShapePreviewRenderer.h \
SceneryTopDownPreviewRenderer.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {