From 804ee6943f3ab05c7f03fa66ecc2dabdd3f2e6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 16 Jan 2013 14:26:46 +0000 Subject: [PATCH] paysages : HDR on previews + small fixes. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@496 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/basepreview.cpp | 120 +++++++++++++++++------------ gui_qt/basepreview.h | 17 ++-- gui_qt/dialognoise.cpp | 15 ++-- gui_qt/formatmosphere.cpp | 10 ++- gui_qt/formclouds.cpp | 12 +-- gui_qt/formrender.cpp | 6 +- gui_qt/formterrain.cpp | 4 +- gui_qt/formtextures.cpp | 12 +-- gui_qt/formwater.cpp | 16 ++-- gui_qt/inputnoise.cpp | 2 +- gui_qt/previewcolorgradation.cpp | 6 +- gui_qt/previewmaterial.cpp | 16 ++-- gui_qt/previewmaterial.h | 14 ++-- gui_qt/widgetcurveeditor.cpp | 44 +++++------ gui_qt/widgetexplorer.cpp | 2 +- lib_paysages/atmosphere/bruneton.c | 9 +-- lib_paysages/atmosphere/preview.c | 5 ++ lib_paysages/tools/memory.c | 2 +- 18 files changed, 169 insertions(+), 143 deletions(-) diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index a856c5d..c366e77 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -23,38 +23,38 @@ public: _ystart = ystart; _xsize = xsize; _ysize = ysize; - + _need_render = true; _rendering = false; _alive = true; _priority = xstart; } - + inline BasePreview* preview() { return _preview; } - + inline int priority() { return _priority; } - + inline bool isOnFront() { return _preview->isVisible() && _preview->window()->isActiveWindow(); } - + bool isFrom(BasePreview* preview) { return _preview == preview; } - + void interrupt() { _alive = false; } - + void update() { _priority = _xstart; @@ -65,15 +65,15 @@ public: { bool changed = false; int revision; - + if (_rendering) { return false; } - + _rendering = true; _alive = true; - + if (_need_render) { if (!isOnFront()) @@ -82,9 +82,9 @@ public: _rendering = false; return false; } - + _need_render = false; - + QImage pixbuf = _preview->startChunkTransaction(_xstart, _ystart, _xsize, _ysize, &revision); for (int x = 0; x < _xsize; x++) @@ -103,14 +103,14 @@ public: { QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y); newcol.setAlpha(255); - + pixbuf.setPixel(x, y, newcol.rgb()); - + changed = true; } } } - + if (changed) { _need_render = not _preview->commitChunkTransaction(&pixbuf, _xstart, _ystart, _xsize, _ysize, revision); @@ -120,12 +120,12 @@ public: _preview->rollbackChunkTransaction(); } } - + if (not _need_render) { _priority = -1; } - + _rendering = false; return _need_render; } @@ -219,12 +219,12 @@ void PreviewDrawingManager::removeChunks(BasePreview* preview) _chunks.remove(i); _updateQueue.removeAll(chunk); _lock.unlock(); - + removed++; i--; } } - + logDebug(QString("[Previews] %1 chunks removed, %2 remaining").arg(removed).arg(_chunks.size())); } @@ -317,7 +317,7 @@ void PreviewDrawingManager::performOneThreadJob() } _lock.unlock(); } - } + } } int PreviewDrawingManager::chunkCount() @@ -353,11 +353,14 @@ QWidget(parent) _revision = 0; _transactions_count = 0; _redraw_requested = false; - + _info = new QLabel(this); _info->setVisible(false); _info->setStyleSheet("QLabel { background-color: white; color: black; }"); + _hdr_enabled = false; + _hdr_profile = colorProfileCreate(); + this->alive = true; QObject::connect(this, SIGNAL(contentChange()), this, SLOT(update())); @@ -365,7 +368,7 @@ QWidget(parent) this->setMinimumSize(256, 256); this->setMaximumSize(256, 256); this->resize(256, 256); - + startTimer(50); } @@ -373,6 +376,8 @@ BasePreview::~BasePreview() { alive = false; + colorProfileDelete(_hdr_profile); + _drawing_manager->removeChunks(this); delete _info; @@ -380,6 +385,12 @@ BasePreview::~BasePreview() delete _lock_drawing; } +void BasePreview::configHdrToneMapping(bool active) +{ + _hdr_enabled = active; + redraw(); +} + void BasePreview::addOsd(QString name) { _osd.append(PreviewOsd::getInstance(name)); @@ -391,7 +402,7 @@ void BasePreview::savePack(PackStream* stream) packWriteDouble(stream, &this->xoffset); packWriteDouble(stream, &this->yoffset); packWriteDouble(stream, &this->scalingbase); - + // TODO Save choices and toggles } @@ -400,9 +411,9 @@ void BasePreview::loadPack(PackStream* stream) packReadDouble(stream, &this->xoffset); packReadDouble(stream, &this->yoffset); packReadDouble(stream, &this->scalingbase); - + // TODO Save choices and toggles - + updateScaling(); emit contentChange(); } @@ -427,9 +438,9 @@ void BasePreview::updateData() { } -QColor BasePreview::getColor(double, double) +Color BasePreview::getColor(double, double) { - return QColor(0, 0, 0); + return COLOR_BLACK; } void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic) @@ -473,9 +484,9 @@ void BasePreview::addChoice(const QString& key, const QString& title, const QStr choice.title = title; choice.items << choices; choice.current = init_value; - + _choices.insert(key, choice); - + choiceChangeEvent(key, init_value); } @@ -488,9 +499,9 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v _ContextToggle toggle; toggle.title = text; toggle.value = init_value; - + _toggles.insert(key, toggle); - + toggleChangeEvent(key, init_value); } @@ -507,24 +518,24 @@ void BasePreview::redraw() QImage BasePreview::startChunkTransaction(int x, int y, int w, int h, int* revision) { QImage result; - + _lock_drawing->lock(); - + *revision = _revision; result = _pixbuf->copy(x, y, w, h); _transactions_count++; - + _lock_drawing->unlock(); - + return result; } bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision) { bool result; - + _lock_drawing->lock(); - + if (revision == _revision) { for (int ix = 0; ix < w; ix++) @@ -541,26 +552,35 @@ bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int { result = false; } - + _transactions_count--; - + _lock_drawing->unlock(); - + return result; } void BasePreview::rollbackChunkTransaction() { _lock_drawing->lock(); - + _transactions_count--; - + _lock_drawing->unlock(); } QColor BasePreview::getPixelColor(int x, int y) { - return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset); + Color col = getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset); + if (_hdr_enabled) + { + col = colorProfileApply(_hdr_profile, col); + } + else + { + colorNormalize(&col); + } + return colorToQColor(col); } void BasePreview::timerEvent(QTimerEvent*) @@ -647,7 +667,7 @@ void BasePreview::paintEvent(QPaintEvent*) { QPainter painter(this); painter.drawImage(0, 0, *this->_pixbuf); - + QImage osd(_pixbuf->size(), _pixbuf->format()); osd.fill(0x00000000); for (int i = 0; i < _osd.size(); i++) @@ -705,10 +725,10 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event) { menu.addSeparator(); } - + iter1.next(); menu.addAction(QString(" %1 ").arg(iter1.value().title))->setDisabled(true); - + QStringList list = iter1.value().items; for (int i = 0; i < list.count(); i++) { @@ -732,7 +752,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event) { menu.addSeparator(); } - + iter2.next(); QAction* action = menu.addAction(iter2.value().title); @@ -749,7 +769,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event) if (not menu.isEmpty()) { connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(choiceSelected(QAction*))); - + menu.exec(event->globalPos()); event->accept(); } @@ -767,7 +787,7 @@ void BasePreview::mousePressEvent(QMouseEvent* event) void BasePreview::mouseMoveEvent(QMouseEvent* event) { int width, height; - + width = this->width(); height = this->height(); @@ -775,7 +795,7 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event) { int dx, dy; int ndx, ndy; - + dx = event->x() - mousex; dy = event->y() - mousey; diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index e5290d0..4dacad1 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -33,16 +33,16 @@ class BasePreview : public QWidget { public: BasePreview(QWidget* parent); ~BasePreview(); - + virtual void savePack(PackStream* stream); virtual void loadPack(PackStream* stream); - + static void initDrawers(); static void stopDrawers(); static void reviveAll(); - + void redraw(); - + QImage startChunkTransaction(int x, int y, int w, int h, int* revision); bool commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision); void rollbackChunkTransaction(); @@ -51,8 +51,9 @@ public: protected: virtual void updateData(); - virtual QColor getColor(double x, double y); + virtual Color getColor(double x, double y); + void configHdrToneMapping(bool active); void configScaling(double min, double max, double step, double init, bool logarithmic = true); void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit); @@ -89,12 +90,12 @@ private: QVector _osd; QHash _choices; QHash _toggles; - + QLabel* _info; int _width; int _height; - + int _revision; int _transactions_count; bool _redraw_requested; @@ -105,6 +106,8 @@ private: double scalingbase; bool alive; + bool _hdr_enabled; + ColorProfile* _hdr_profile; double conf_scroll_xmin; double conf_scroll_xmax; diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index 1465369..5695341 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -1,5 +1,6 @@ #include "dialognoise.h" +#include #include #include #include @@ -9,7 +10,7 @@ #include #include #include -#include +#include "../lib_paysages/color.h" /**************** Previews ****************/ class PreviewLevel:public BasePreview @@ -34,15 +35,15 @@ protected: { noiseCopy(_noise_original, _noise_preview); } - QColor getColor(double x, double y) + Color getColor(double x, double y) { if ((_level >= 0) && (-y > noiseGet1DLevel(_noise_preview, _level, x))) { - return Qt::black; + return COLOR_WHITE; } else { - return Qt::white; + return COLOR_BLACK; } } private: @@ -66,15 +67,15 @@ protected: { noiseCopy(_noise_original, _noise_preview); } - QColor getColor(double x, double y) + Color getColor(double x, double y) { if (-y > noiseGet1DTotal(_noise_preview, x)) { - return Qt::black; + return COLOR_WHITE; } else { - return Qt::white; + return COLOR_BLACK; } } private: diff --git a/gui_qt/formatmosphere.cpp b/gui_qt/formatmosphere.cpp index a8abca3..fbd149b 100644 --- a/gui_qt/formatmosphere.cpp +++ b/gui_qt/formatmosphere.cpp @@ -21,12 +21,13 @@ public: { _renderer = atmosphereCreatePreviewRenderer(); + configHdrToneMapping(true); configScaling(0.5, 5.0, 0.5, 2.5); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { - return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, M_PI_2)); + return atmosphereGetPreview(&_renderer, x, -y, M_PI_2); } void updateData() { @@ -44,12 +45,13 @@ public: { _renderer = atmosphereCreatePreviewRenderer(); + configHdrToneMapping(true); configScaling(0.5, 5.0, 0.5, 2.5); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { - return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, -M_PI_2)); + return atmosphereGetPreview(&_renderer, x, -y, -M_PI_2); } void updateData() { diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 760f9c7..6c3f9aa 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -27,10 +27,9 @@ public: cloudsLayerDeleteDefinition(_preview_layer); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 eye, look; - Color color_layer; eye.x = 0.0; eye.y = scaling; @@ -40,8 +39,7 @@ protected: look.z = 1.0; look = v3Normalize(look); - color_layer = cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0))); - return colorToQColor(color_layer); + return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0))); } void updateData() { @@ -90,10 +88,9 @@ public: configScaling(0.5, 2.0, 0.1, 2.0); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 start, end; - Color color_layer; start.x = x * _preview_layer->thickness * 0.5; start.y = -y * _preview_layer->thickness * 0.5; @@ -103,8 +100,7 @@ protected: end.y = -y * _preview_layer->thickness * 0.5; end.z = -_preview_layer->thickness * 0.5; - color_layer = cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end); - return colorToQColor(color_layer); + return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end); } void updateData() { diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 756d3d9..9cc13fb 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -39,7 +39,7 @@ public: configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 down = {0.0, -1.0, 0.0}; Vector3 location; @@ -50,14 +50,14 @@ protected: location.x = x; location.y = _water.height; location.z = y; - return colorToQColor(waterGetColor(&_water, &_renderer, location, down)); + return waterGetColor(&_water, &_renderer, location, down); } else { location.x = x; location.y = height; location.z = y; - return colorToQColor(_renderer.terrain->getFinalColor(&_renderer, location, scaling)); + return _renderer.terrain->getFinalColor(&_renderer, location, scaling); } } void updateData() diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 493536b..b3844e5 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -22,9 +22,9 @@ public: configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { - return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling)); + return terrainGetPreviewColor(&_renderer, x, -y, scaling); } void updateData() { diff --git a/gui_qt/formtextures.cpp b/gui_qt/formtextures.cpp index 8b511a7..18e27ff 100644 --- a/gui_qt/formtextures.cpp +++ b/gui_qt/formtextures.cpp @@ -35,15 +35,15 @@ public: texturesLayerDeleteDefinition(_preview_layer); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 location; - double coverage; + Color result; location.x = x; location.y = _renderer.terrain->getHeight(&_renderer, x, y, 1); location.z = y; - coverage = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling); - return QColor::fromRgbF(coverage, coverage, coverage, 1.0); + result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling); + return result; } void updateData() { @@ -99,13 +99,13 @@ public: texturesLayerDeleteDefinition(_preview_layer); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 location; location.x = x; location.y = 0.0; location.z = y; - return colorToQColor(texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling)); + return texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling); } void updateData() { diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index d4fbf8d..9a40b6d 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -31,14 +31,14 @@ public: configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { double height; height = _renderer.terrain->getHeight(&_renderer, x, -y, 1); if (height > _definition.height) { - return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling)); + return terrainGetPreviewColor(&_renderer, x, -y, scaling); } else { @@ -61,7 +61,7 @@ protected: colorMask(&base, &mask); } - return colorToQColor(base); + return base; } } void updateData() @@ -127,7 +127,7 @@ public: } int _background; protected: - QColor getColor(double x, double y) + Color getColor(double x, double y) { Vector3 eye, look, location; @@ -141,7 +141,7 @@ protected: if (look.y > -0.0001) { - return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color); + return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color; } location.x = eye.x - look.x * eye.y / look.y; @@ -150,10 +150,10 @@ protected: if (location.z > 0.0) { - return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color); + return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color; } - return colorToQColor(waterGetColor(&_water, &_renderer, location, look)); + return waterGetColor(&_water, &_renderer, location, look); } void updateData() { @@ -183,7 +183,7 @@ private: LightingDefinition _lighting; bool _lighting_enabled; - static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) + static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int) { RayCastingResult result; PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[2]; diff --git a/gui_qt/inputnoise.cpp b/gui_qt/inputnoise.cpp index 728e1be..0c1c4c0 100644 --- a/gui_qt/inputnoise.cpp +++ b/gui_qt/inputnoise.cpp @@ -16,7 +16,7 @@ public: { } - void paintEvent(QPaintEvent* event) + void paintEvent(QPaintEvent*) { if (!noise) { diff --git a/gui_qt/previewcolorgradation.cpp b/gui_qt/previewcolorgradation.cpp index 1675be7..dd368b4 100644 --- a/gui_qt/previewcolorgradation.cpp +++ b/gui_qt/previewcolorgradation.cpp @@ -18,8 +18,8 @@ PreviewColorGradation::PreviewColorGradation(QWidget* parent, ColorGradation* gr this->gradation = gradation; this->band = band; } - -void PreviewColorGradation::paintEvent(QPaintEvent* event) + +void PreviewColorGradation::paintEvent(QPaintEvent*) { Curve* curve; @@ -67,7 +67,7 @@ void PreviewColorGradation::paintEvent(QPaintEvent* event) curveDelete(curve); } -void PreviewColorGradation::mouseReleaseEvent(QMouseEvent* event) +void PreviewColorGradation::mouseReleaseEvent(QMouseEvent*) { emit clicked(); } diff --git a/gui_qt/previewmaterial.cpp b/gui_qt/previewmaterial.cpp index f85d0fc..0811cce 100644 --- a/gui_qt/previewmaterial.cpp +++ b/gui_qt/previewmaterial.cpp @@ -38,7 +38,7 @@ SmallMaterialPreview::~SmallMaterialPreview() rendererDelete(&_renderer); } -QColor SmallMaterialPreview::getColor(double x, double y) +Color SmallMaterialPreview::getColor(double x, double y) { double dist = sqrt(x * x + y * y); Vector3 point; @@ -46,7 +46,7 @@ QColor SmallMaterialPreview::getColor(double x, double y) if (dist >= 1.0) { - return colorToQColor(COLOR_TRANSPARENT); + return COLOR_TRANSPARENT; } else { @@ -67,17 +67,17 @@ QColor SmallMaterialPreview::getColor(double x, double y) { color.a = (1.0 - dist) / 0.05; } - return colorToQColor(color); + return color; } } -void SmallMaterialPreview::paintEvent(QPaintEvent* event) +void SmallMaterialPreview::paintEvent(QPaintEvent*) { QPainter painter(this); int width = this->width(); int height = this->height(); double factor, dx, dy; - + if (width > height) { factor = 2.0 / (double)height; @@ -93,7 +93,7 @@ void SmallMaterialPreview::paintEvent(QPaintEvent* event) { for (int y = 0; y < height; y++) { - painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy)); + painter.setPen(colorToQColor(getColor((double)x * factor - dx, (double)y * factor - dy))); painter.drawPoint(x, y); } } @@ -105,7 +105,7 @@ PreviewMaterial::PreviewMaterial(QWidget* parent, SurfaceMaterial* material) : B { _small = new SmallMaterialPreview(this, material); _small->hide(); - + configScaling(0.05, 2.0, 0.05, 2.0); } @@ -114,7 +114,7 @@ PreviewMaterial::~PreviewMaterial() delete _small; } -QColor PreviewMaterial::getColor(double x, double y) +Color PreviewMaterial::getColor(double x, double y) { return _small->getColor(x, y); } diff --git a/gui_qt/previewmaterial.h b/gui_qt/previewmaterial.h index e4dadda..5cc711e 100644 --- a/gui_qt/previewmaterial.h +++ b/gui_qt/previewmaterial.h @@ -11,12 +11,12 @@ class SmallMaterialPreview:public QWidget public: SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material); ~SmallMaterialPreview(); - - QColor getColor(double x, double y); - + + Color getColor(double x, double y); + protected: virtual void paintEvent(QPaintEvent* event); - + private: SurfaceMaterial* _material; LightingDefinition _lighting; @@ -26,13 +26,13 @@ private: class PreviewMaterial:public BasePreview { Q_OBJECT - + public: PreviewMaterial(QWidget* parent, SurfaceMaterial* material); ~PreviewMaterial(); - + protected: - virtual QColor getColor(double x, double y); + virtual Color getColor(double x, double y); private: SmallMaterialPreview* _small; diff --git a/gui_qt/widgetcurveeditor.cpp b/gui_qt/widgetcurveeditor.cpp index fb69c68..f4a55a3 100644 --- a/gui_qt/widgetcurveeditor.cpp +++ b/gui_qt/widgetcurveeditor.cpp @@ -10,12 +10,12 @@ WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, _curve = curveCreate(); _dragged = -1; _pen = QColor(0, 0, 0); - + _xmin = xmin; _xmax = xmax; _ymin = ymin; _ymax = ymax; - + setMinimumSize(300, 300); } @@ -47,22 +47,22 @@ void WidgetCurveEditor::setPenColor(QColor color) update(); } -void WidgetCurveEditor::paintEvent(QPaintEvent* event) +void WidgetCurveEditor::paintEvent(QPaintEvent*) { int i, n; int width, height; double dwidth, dheight; CurvePoint point; double position, value, prev_value, next_value; - + width = this->width(); height = this->height(); dheight = (double)(height - 1); dwidth = (double)(width - 1); - + QPainter painter(this); painter.fillRect(rect(), Qt::white); - + // Draw grid painter.setPen(QPen(Qt::lightGray)); for (int x = 0; x <= 10; x++) @@ -72,7 +72,7 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event) vx = (x == 10) ? height - 1 : x * height / 10; painter.drawLine(0, vx, width - 1, vx); } - + // Draw labels painter.setPen(QColor(50, 50, 50)); if (not _xlabel.isEmpty()) @@ -87,21 +87,21 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event) painter.translate(height, 0.0); painter.rotate(90.0); } - + // Draw curve path painter.setPen(_pen); for (int x = 0; x < width; x++) { position = ((double)x / dwidth) * (_xmax - _xmin) + _xmin; - + value = (curveGetValue(_curve, position) - _ymin) / (_ymax - _ymin); prev_value = curveGetValue(_curve, position - (_xmax - _xmin) / dwidth); next_value = curveGetValue(_curve, position + (_xmax - _xmin) / dwidth); - + painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * dheight), x, height - 1 - (int)((value + (next_value - value) / 2.0) * dheight)); painter.drawPoint(x, height - 1 - (int)(value * dheight)); } - + // Draw handles n = curveGetPointCount(_curve); painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true); @@ -118,37 +118,37 @@ void WidgetCurveEditor::mousePressEvent(QMouseEvent* event) { _dragged = getPointAt(event->x(), event->y()); } - + event->accept(); } void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event) { CurvePoint point; - + if (_dragged >= 0 && (event->buttons() & Qt::LeftButton)) { screenToCurve(event->x(), event->y(), &point.position, &point.value); - + point.position = (point.position < _xmin) ? _xmin : point.position; point.position = (point.position > _xmax) ? _xmax : point.position; point.value = (point.value < _ymin) ? _ymin : point.value; point.value = (point.value > _ymax) ? _ymax : point.value; - + curveSetPoint(_curve, _dragged, &point); update(); - + emit liveChanged(); } - + event->accept(); } void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event) { int clicked; - + if (event->button() == Qt::RightButton) { clicked = getPointAt(event->x(), event->y()); @@ -165,14 +165,14 @@ void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event) curveValidate(_curve); update(); } - + event->accept(); } void WidgetCurveEditor::mouseDoubleClickEvent(QMouseEvent* event) { CurvePoint point; - + if (event->button() == Qt::LeftButton && _dragged < 0) { if (getPointAt(event->x(), event->y()) < 0) @@ -205,7 +205,7 @@ int WidgetCurveEditor::getPointAt(int x, int y) double distance, ndistance; CurvePoint point; int dx, dy; - + n = curveGetPointCount(_curve); if (n < 1) { @@ -226,7 +226,7 @@ int WidgetCurveEditor::getPointAt(int x, int y) nearest = i; } } - + if (nearest >= 0 && distance < 5.0) { return nearest; diff --git a/gui_qt/widgetexplorer.cpp b/gui_qt/widgetexplorer.cpp index ecbb7f9..6d34eb4 100644 --- a/gui_qt/widgetexplorer.cpp +++ b/gui_qt/widgetexplorer.cpp @@ -339,7 +339,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event) event->accept(); } -void WidgetExplorer::timerEvent(QTimerEvent *event) +void WidgetExplorer::timerEvent(QTimerEvent*) { if (_updated) { diff --git a/lib_paysages/atmosphere/bruneton.c b/lib_paysages/atmosphere/bruneton.c index 074f900..c5e82c1 100644 --- a/lib_paysages/atmosphere/bruneton.c +++ b/lib_paysages/atmosphere/bruneton.c @@ -212,7 +212,7 @@ static double _opticalDepth(double H, double r, double mu, double d) double ayq = ay * ay; double x = ays > axs ? exp(axq) : 0.0; double yx = axs / (2.3193 * fabs(ax) + sqrt(1.52 * axq + 4.0)); - double yy = ays / (2.3193 * fabs(ay) + sqrt(1.52 * ayq + 4.0)) * exp(-d / H * (d / (2.0 * r) + mu)); + double yy = ays / (2.3193 * fabs(ay) + sqrt(1.52 * ayq + 4.0)) * exp(-d / H * (d / (2.0 * r) + mu)); return sqrt((6.2831 * H) * r) * exp((Rg - r) / H) * (x + yx - yy); } @@ -286,11 +286,10 @@ static double _limit(double r, double mu) static Vector3 _analyticTransmittance(double r, double mu, double d) { Vector3 result; - double opt = _opticalDepth(HR, r, mu, d); - result.x = exp(-betaR.r * opt) - betaMEx.x * opt; - result.y = exp(-betaR.g * opt) - betaMEx.y * opt; - result.z = exp(-betaR.b * opt) - betaMEx.z * opt; + result.x = exp(-betaR.r * _opticalDepth(HR, r, mu, d) - betaMEx.x * _opticalDepth(HM, r, mu, d)); + result.y = exp(-betaR.g * _opticalDepth(HR, r, mu, d) - betaMEx.y * _opticalDepth(HM, r, mu, d)); + result.z = exp(-betaR.b * _opticalDepth(HR, r, mu, d) - betaMEx.z * _opticalDepth(HM, r, mu, d)); return result; } diff --git a/lib_paysages/atmosphere/preview.c b/lib_paysages/atmosphere/preview.c index 1b09359..bad529f 100644 --- a/lib_paysages/atmosphere/preview.c +++ b/lib_paysages/atmosphere/preview.c @@ -135,6 +135,11 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin normal = m4Transform(rotation, normal); hit = m4Transform(rotation, hit); + if (y == 0.0) + { + y = 0.0; + } + renderer->getLightStatus(renderer, &light, hit); color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL); diff --git a/lib_paysages/tools/memory.c b/lib_paysages/tools/memory.c index 4da8dd7..874f772 100644 --- a/lib_paysages/tools/memory.c +++ b/lib_paysages/tools/memory.c @@ -1,6 +1,6 @@ #include "memory.h" -#include +#include void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset) {