diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index c3122d8..0bf06c9 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -408,9 +408,9 @@ BaseInput* BaseForm::addInputMaterial(QString label, SurfaceMaterial* material) return addInput(new InputMaterial(_form, label, material)); } -BaseInput* BaseForm::addInputHeightMap(QString label, HeightMap* heightmap) +BaseInput* BaseForm::addInputHeightMap(QString label, HeightMap* heightmap, TerrainCanvas* canvas) { - return addInput(new InputHeightMap(_form, label, heightmap)); + return addInput(new InputHeightMap(_form, label, heightmap, canvas)); } BaseInput* BaseForm::addInputEnum(QString label, int* value, const QStringList& values) diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 6e94c3b..a4dc393 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -15,6 +15,7 @@ #include "../lib_paysages/layers.h" #include "../lib_paysages/heightmap.h" #include "../lib_paysages/pack.h" +#include "../lib_paysages/terraincanvas.h" class BaseForm:public QWidget { @@ -57,7 +58,7 @@ protected: BaseInput* addInputNoise(QString label, NoiseGenerator* value); BaseInput* addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); BaseInput* addInputMaterial(QString label, SurfaceMaterial* material); - BaseInput* addInputHeightMap(QString label, HeightMap* heightmap); + BaseInput* addInputHeightMap(QString label, HeightMap* heightmap, TerrainCanvas* canvas); BaseInput* addInputEnum(QString label, int* value, const QStringList& values); BaseInput* addInputLayers(QString label, Layers* value, FormLayerBuilder form_builder); diff --git a/gui_qt/dialogcurve.cpp b/gui_qt/dialogcurve.cpp index 93dcfd3..ba71309 100644 --- a/gui_qt/dialogcurve.cpp +++ b/gui_qt/dialogcurve.cpp @@ -83,7 +83,7 @@ bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xm return (result != 0) ? true : false; } -void DialogCurve::closeEvent(QCloseEvent* e) +void DialogCurve::closeEvent(QCloseEvent*) { reject(); } diff --git a/gui_qt/dialogheightmap.cpp b/gui_qt/dialogheightmap.cpp index b16f90f..0ec694f 100644 --- a/gui_qt/dialogheightmap.cpp +++ b/gui_qt/dialogheightmap.cpp @@ -6,11 +6,14 @@ #include #include #include +#include #include +#include "../lib_paysages/terrain.h" +#include "../lib_paysages/scenery.h" #include "widgetheightmap.h" /**************** Dialog form ****************/ -DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap) : DialogWithPreview(parent) +DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap, TerrainCanvas* canvas) : DialogWithPreview(parent) { QWidget* mainarea; QWidget* buttons; @@ -23,6 +26,7 @@ DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap) : Dialog QPushButton* button; QComboBox* combobox; + _canvas = canvas; _value_original = heightmap; _value_modified = heightmapCreate(); heightmapCopy(_value_original, &_value_modified); @@ -62,8 +66,15 @@ DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap) : Dialog viewer_layout->addWidget(slider, 0, 1); // Panel layout - button = new QPushButton(tr("Reset to terrain height"), panel); - connect(button, SIGNAL(clicked()), _3dview, SLOT(resetToTerrain())); + if (canvas) + { + button = new QPushButton(tr("Reset to terrain height"), panel); + connect(button, SIGNAL(clicked()), this, SLOT(resetToTerrain())); + panel->layout()->addWidget(button); + } + + button = new QPushButton(tr("Load from picture file"), panel); + connect(button, SIGNAL(clicked()), this, SLOT(loadFromFile())); panel->layout()->addWidget(button); combobox = new QComboBox(panel); @@ -115,11 +126,11 @@ DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap) : Dialog setWindowTitle(tr("Paysages 3D - Height map painting")); } -bool DialogHeightMap::editHeightMap(QWidget* parent, HeightMap* heightmap) +bool DialogHeightMap::editHeightMap(QWidget* parent, HeightMap* heightmap, TerrainCanvas* canvas) { int result; - DialogHeightMap* dialog = new DialogHeightMap(parent, heightmap); + DialogHeightMap* dialog = new DialogHeightMap(parent, heightmap, canvas); result = dialog->exec(); delete dialog; @@ -168,3 +179,30 @@ void DialogHeightMap::brushStrengthChanged(int value) { _3dview->setBrushStrength((double)value / 2000.0); } + +void DialogHeightMap::loadFromFile() +{ + QString filepath = QFileDialog::getOpenFileName(this, tr("Paysages 3D - Choose a picture to load"), QString(), tr("Images (*.jpg *.jpeg *.bmp *.png)")); + if (!filepath.isNull()) + { + heightmapImportFromPicture(&_value_modified, (char*) filepath.toStdString().c_str()); + _3dview->revert(); + } +} + +void DialogHeightMap::resetToTerrain() +{ + if (_canvas) + { + TerrainDefinition terrain; + + terrain = terrainCreateDefinition(); + sceneryGetTerrain(&terrain); + + heightmapRevertToTerrain(&_value_modified, &terrain, &_canvas->area); + + terrainDeleteDefinition(&terrain); + + _3dview->revert(); + } +} diff --git a/gui_qt/dialogheightmap.h b/gui_qt/dialogheightmap.h index b87ac34..e7c0b96 100644 --- a/gui_qt/dialogheightmap.h +++ b/gui_qt/dialogheightmap.h @@ -4,13 +4,14 @@ #include "tools.h" #include "widgetheightmap.h" #include "../lib_paysages/heightmap.h" +#include "../lib_paysages/terraincanvas.h" class DialogHeightMap : public DialogWithPreview { Q_OBJECT public: - explicit DialogHeightMap(QWidget* parent, HeightMap* heightmap); - static bool editHeightMap(QWidget* parent, HeightMap* heightmap); + explicit DialogHeightMap(QWidget* parent, HeightMap* heightmap, TerrainCanvas* canvas); + static bool editHeightMap(QWidget* parent, HeightMap* heightmap, TerrainCanvas* canvas); public slots: virtual void accept(); @@ -23,11 +24,14 @@ private slots: void brushSizeChanged(int value); void brushSmoothingChanged(int value); void brushStrengthChanged(int value); + void loadFromFile(); + void resetToTerrain(); private: HeightMap* _value_original; HeightMap _value_modified; WidgetHeightMap* _3dview; + TerrainCanvas* _canvas; }; #endif diff --git a/gui_qt/dialoglayers.cpp b/gui_qt/dialoglayers.cpp index 2954d58..fc5cf3f 100644 --- a/gui_qt/dialoglayers.cpp +++ b/gui_qt/dialoglayers.cpp @@ -56,7 +56,7 @@ bool DialogLayers::editLayers(QWidget* parent, Layers* layers, QString title, Fo return result != 0; } -void DialogLayers::closeEvent(QCloseEvent* e) +void DialogLayers::closeEvent(QCloseEvent*) { reject(); } diff --git a/gui_qt/formterraincanvas.cpp b/gui_qt/formterraincanvas.cpp index 047a4e1..3146604 100644 --- a/gui_qt/formterraincanvas.cpp +++ b/gui_qt/formterraincanvas.cpp @@ -44,7 +44,7 @@ FormTerrainCanvas::FormTerrainCanvas(QWidget *parent, Layers* layers): // TODO Area //addInputDouble(tr("Apply at height"), &_definition->offset_y, -20.0, 20.0, 0.1, 1.0); - addInputHeightMap(tr("Height map"), &_definition->height_map); + addInputHeightMap(tr("Height map"), &_definition->height_map, _definition); //addInputDouble(tr("Canvas height"), &_definition->height_factor, 0.0, 20.0, 0.1, 1.0); addInputNoise(tr("Detail noise"), _definition->detail_noise); addInputDouble(tr("Detail noise height"), &_definition->detail_height_factor, 0.0, 20.0, 0.1, 1.0); diff --git a/gui_qt/inputheightmap.cpp b/gui_qt/inputheightmap.cpp index 036db27..d3c599d 100644 --- a/gui_qt/inputheightmap.cpp +++ b/gui_qt/inputheightmap.cpp @@ -45,9 +45,10 @@ public: HeightMap* _value; }; -InputHeightMap::InputHeightMap(QWidget* form, QString label, HeightMap* value) : BaseInput(form, label) +InputHeightMap::InputHeightMap(QWidget* form, QString label, HeightMap* value, TerrainCanvas* canvas) : BaseInput(form, label) { _value = value; + _canvas = canvas; _preview = new SmallPreviewHeightMap(form, value); _preview->setMinimumSize(100, 100); @@ -77,7 +78,7 @@ void InputHeightMap::revert() void InputHeightMap::editHeightMap() { - if (DialogHeightMap::editHeightMap(_control, _value)) + if (DialogHeightMap::editHeightMap(_control, _value, _canvas)) { applyValue(); } diff --git a/gui_qt/inputheightmap.h b/gui_qt/inputheightmap.h index 2cd25cd..f25189d 100644 --- a/gui_qt/inputheightmap.h +++ b/gui_qt/inputheightmap.h @@ -5,13 +5,14 @@ #include "baseinput.h" #include "../lib_paysages/heightmap.h" +#include "../lib_paysages/terraincanvas.h" class InputHeightMap:public BaseInput { Q_OBJECT public: - InputHeightMap(QWidget* form, QString label, HeightMap* value); + InputHeightMap(QWidget* form, QString label, HeightMap* value, TerrainCanvas* canvas); public slots: virtual void updatePreview(); @@ -23,6 +24,7 @@ private slots: private: HeightMap* _value; + TerrainCanvas* _canvas; }; #endif diff --git a/gui_qt/widgetheightmap.cpp b/gui_qt/widgetheightmap.cpp index b2fad69..5e2f263 100644 --- a/gui_qt/widgetheightmap.cpp +++ b/gui_qt/widgetheightmap.cpp @@ -5,8 +5,6 @@ #include #include #include "tools.h" -#include "../lib_paysages/terrain.h" -#include "../lib_paysages/scenery.h" WidgetHeightMap::WidgetHeightMap(QWidget *parent, HeightMap* heightmap): QGLWidget(parent) @@ -18,7 +16,7 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, HeightMap* heightmap): startTimer(100); _heightmap = heightmap; - _vertexes = new _VertexInfo[heightmap->resolution_x * heightmap->resolution_z]; + _vertices = new _VertexInfo[heightmap->resolution_x * heightmap->resolution_z]; _dirty = true; @@ -47,7 +45,7 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, HeightMap* heightmap): WidgetHeightMap::~WidgetHeightMap() { noiseDeleteGenerator(_brush_noise); - delete[] _vertexes; + delete[] _vertices; } void WidgetHeightMap::setHorizontalViewAngle(double angle_h) @@ -100,28 +98,6 @@ void WidgetHeightMap::revert() updateGL(); } -void WidgetHeightMap::resetToTerrain() -{ - TerrainDefinition terrain; - - terrain = terrainCreateDefinition(); - sceneryGetTerrain(&terrain); - - // TODO Apply geoarea - int rx = _heightmap->resolution_x; - int rz = _heightmap->resolution_z; - for (int x = 0; x < rx; x++) - { - for (int z = 0; z < rz; z++) - { - _heightmap->data[z * rx + x] = terrainGetHeight(&terrain, 80.0 * (double)x / (double)(rx - 1) - 40.0, 80.0 * (double)z / (double)(rz - 1) - 40.0); - } - } - - terrainDeleteDefinition(&terrain); - revert(); -} - void WidgetHeightMap::mousePressEvent(QMouseEvent* event) { _last_mouse_x = event->x(); @@ -312,7 +288,7 @@ void WidgetHeightMap::paintGL() glBegin(GL_QUAD_STRIP); for (int z = 0; z < rz; z++) { - _VertexInfo* vertex = _vertexes + z * rx + x; + _VertexInfo* vertex = _vertices + z * rx + x; double diff_x, diff_z, diff; diff_x = (vertex + 1)->point.x - _brush_x; @@ -371,13 +347,17 @@ void WidgetHeightMap::updateVertexInfo() { int rx = _heightmap->resolution_x; int rz = _heightmap->resolution_z; + + _VertexInfo* old_vertices = _vertices; + _vertices = new _VertexInfo[rx * rz]; + delete[] old_vertices; // Update positions for (int x = 0; x < rx; x++) { for (int z = 0; z < rz; z++) { - _VertexInfo* vertex = _vertexes + z * rx + x; + _VertexInfo* vertex = _vertices + z * rx + x; vertex->point.x = 80.0 * (double)x / (double)(rx - 1) - 40.0; vertex->point.y = _heightmap->data[z * rx + x]; @@ -390,7 +370,7 @@ void WidgetHeightMap::updateVertexInfo() { for (int z = 0; z < rz; z++) { - _VertexInfo* vertex = _vertexes + z * rx + x; + _VertexInfo* vertex = _vertices + z * rx + x; if (x == rx - 1) { diff --git a/gui_qt/widgetheightmap.h b/gui_qt/widgetheightmap.h index a954eae..b48e95b 100644 --- a/gui_qt/widgetheightmap.h +++ b/gui_qt/widgetheightmap.h @@ -34,7 +34,6 @@ public: public slots: void revert(); - void resetToTerrain(); protected: void mousePressEvent(QMouseEvent* event); @@ -52,7 +51,7 @@ private: private: HeightMap* _heightmap; - _VertexInfo* _vertexes; + _VertexInfo* _vertices; bool _dirty; diff --git a/lib_paysages/geoarea.c b/lib_paysages/geoarea.c new file mode 100644 index 0000000..9571b05 --- /dev/null +++ b/lib_paysages/geoarea.c @@ -0,0 +1,53 @@ +#include "geoarea.h" + +#include "tools.h" + +GeoArea geoareaCreate() +{ + GeoArea result; + + result.location_x = -40.0; + result.location_z = -40.0; + result.size_x = 80.0; + result.size_z = 80.0; + + return result; +} + +void geoareaDelete(GeoArea* geoarea) +{ + UNUSED(geoarea); +} + +void geoareaCopy(GeoArea* source, GeoArea* destination) +{ + *destination = *source; +} + +void geoareaValidate(GeoArea* geoarea) +{ + if (geoarea->size_x < 0.000000001) + { + geoarea->size_x = 0.000000001; + } + if (geoarea->size_z < 0.000000001) + { + geoarea->size_z = 0.000000001; + } +} + +void geoareaSave(PackStream* stream, GeoArea* geoarea) +{ + packWriteDouble(stream, &geoarea->location_x); + packWriteDouble(stream, &geoarea->location_z); + packWriteDouble(stream, &geoarea->size_x); + packWriteDouble(stream, &geoarea->size_z); +} + +void geoareaLoad(PackStream* stream, GeoArea* geoarea) +{ + packReadDouble(stream, &geoarea->location_x); + packReadDouble(stream, &geoarea->location_z); + packReadDouble(stream, &geoarea->size_x); + packReadDouble(stream, &geoarea->size_z); +} diff --git a/lib_paysages/geoarea.h b/lib_paysages/geoarea.h new file mode 100644 index 0000000..e18f1e2 --- /dev/null +++ b/lib_paysages/geoarea.h @@ -0,0 +1,32 @@ +#ifndef _PAYSAGES_GEOAREA_H_ +#define _PAYSAGES_GEOAREA_H_ + +/* Geographic area definition */ + +#include "pack.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + double location_x; + double location_z; + double size_x; + double size_z; +} GeoArea; + +GeoArea geoareaCreate(); +void geoareaDelete(GeoArea* geoarea); +void geoareaCopy(GeoArea* source, GeoArea* destination); +void geoareaValidate(GeoArea* geoarea); + +void geoareaSave(PackStream* stream, GeoArea* geoarea); +void geoareaLoad(PackStream* stream, GeoArea* geoarea); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib_paysages/heightmap.c b/lib_paysages/heightmap.c index d5a9016..adc16de 100644 --- a/lib_paysages/heightmap.c +++ b/lib_paysages/heightmap.c @@ -1,12 +1,12 @@ #include "heightmap.h" -#include "tools.h" -#include "system.h" -#include "noise.h" #include #include #include #include +#include "tools.h" +#include "system.h" +#include "noise.h" HeightMap heightmapCreate() { @@ -34,6 +34,7 @@ void heightmapCopy(HeightMap* source, HeightMap* destination) void heightmapValidate(HeightMap* heightmap) { + UNUSED(heightmap); } void heightmapSave(PackStream* stream, HeightMap* heightmap) @@ -69,25 +70,6 @@ static void _loadFromFilePixel(HeightMap* heightmap, int x, int y, Color col) heightmap->data[y * heightmap->resolution_x + x] = (col.r + col.g + col.b) / 3.0; } -void heightmapImportFromPicture(HeightMap* heightmap, const char* picturepath) -{ - systemLoadPictureFile(picturepath, (PictureCallbackLoadStarted)heightmapChangeResolution, (PictureCallbackLoadPixel)_loadFromFilePixel, heightmap); -} - -void heightmapChangeResolution(HeightMap* heightmap, int resolution_x, int resolution_z) -{ - int i; - - heightmap->resolution_x = resolution_x; - heightmap->resolution_z = resolution_z; - heightmap->data = realloc(heightmap->data, sizeof(double) * heightmap->resolution_x * heightmap->resolution_z); - - for (i = 0; i < heightmap->resolution_x * heightmap->resolution_z; i++) - { - heightmap->data[i] = 0.0; - } -} - void heightmapGetLimits(HeightMap* heightmap, double* ymin, double* ymax) { double y; @@ -161,6 +143,44 @@ double heightmapGetValue(HeightMap* heightmap, double x, double z) return toolsBicubicInterpolate(stencil, x * xmax - (double)xlow, z * zmax - (double)zlow); } + +void heightmapImportFromPicture(HeightMap* heightmap, const char* picturepath) +{ + systemLoadPictureFile(picturepath, (PictureCallbackLoadStarted)heightmapChangeResolution, (PictureCallbackLoadPixel)_loadFromFilePixel, heightmap); +} + +void heightmapChangeResolution(HeightMap* heightmap, int resolution_x, int resolution_z) +{ + int i; + + heightmap->resolution_x = resolution_x; + heightmap->resolution_z = resolution_z; + heightmap->data = realloc(heightmap->data, sizeof(double) * heightmap->resolution_x * heightmap->resolution_z); + + for (i = 0; i < heightmap->resolution_x * heightmap->resolution_z; i++) + { + heightmap->data[i] = 0.0; + } +} + +void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain, GeoArea* area) +{ + int rx, rz; + int x, z; + + rx = heightmap->resolution_x; + rz = heightmap->resolution_z; + for (x = 0; x < rx; x++) + { + for (z = 0; z < rz; z++) + { + /* FIXME Apply geoarea */ + heightmap->data[z * rx + x] = terrainGetHeight(terrain, 80.0 * (double)x / (double)(rx - 1) - 40.0, 80.0 * (double)z / (double)(rz - 1) - 40.0); + } + } +} + + static inline void _getBrushBoundaries(HeightMapBrush* brush, int rx, int rz, int* x1, int* x2, int* z1, int* z2) { double cx = brush->relative_x * rx; @@ -211,10 +231,9 @@ typedef double (*BrushCallback)(HeightMap* heightmap, HeightMapBrush* brush, dou static inline void _applyBrush(HeightMap* heightmap, HeightMapBrush* brush, double force, void* data, BrushCallback callback) { int x, x1, x2, z, z1, z2; - double dx, dz, distance, influence, brush_size; + double dx, dz, distance, influence; _getBrushBoundaries(brush, heightmap->resolution_x - 1, heightmap->resolution_z - 1, &x1, &x2, &z1, &z2); - brush_size = brush->hard_radius + brush->smoothed_size; for (x = x1; x <= x2; x++) { diff --git a/lib_paysages/heightmap.h b/lib_paysages/heightmap.h index 23e070a..2b06c83 100644 --- a/lib_paysages/heightmap.h +++ b/lib_paysages/heightmap.h @@ -5,6 +5,8 @@ #include "pack.h" #include "noise.h" +#include "geoarea.h" +#include "terrain.h" #ifdef __cplusplus extern "C" { @@ -40,6 +42,7 @@ double heightmapGetValue(HeightMap* heightmap, double x, double z); void heightmapChangeResolution(HeightMap* heightmap, int resolution_x, int resolution_z); void heightmapImportFromPicture(HeightMap* heightmap, const char* picturepath); +void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain, GeoArea* area); void heightmapBrushElevation(HeightMap* heightmap, HeightMapBrush* brush, double value); void heightmapBrushSmooth(HeightMap* heightmap, HeightMapBrush* brush, double value); diff --git a/lib_paysages/terraincanvas.c b/lib_paysages/terraincanvas.c index 7f82edf..3bb0aaa 100644 --- a/lib_paysages/terraincanvas.c +++ b/lib_paysages/terraincanvas.c @@ -1,4 +1,5 @@ #include "terraincanvas.h" +#include "scenery.h" #include #include @@ -8,11 +9,7 @@ TerrainCanvas* terrainCanvasCreate() { TerrainCanvas* result = malloc(sizeof(TerrainCanvas)); - result->area.bounded = 1; - result->area.location_x = -40.0; - result->area.location_z = -40.0; - result->area.size_x = 80.0; - result->area.size_z = 80.0; + result->area = geoareaCreate(); result->offset_y = 0.0; result->height_map = heightmapCreate(); heightmapChangeResolution(&result->height_map, 256, 256); @@ -24,10 +21,7 @@ TerrainCanvas* terrainCanvasCreate() result->detail_scaling = 0.4; result->mask.mode = INTEGRATIONMASK_MODE_CIRCLE; result->mask.smoothing = 0.1; - - /* DEBUG */ - /*heightmapImportFromPicture(&result->height_map, "output/height.png");*/ - + return result; } @@ -40,7 +34,7 @@ void terrainCanvasDelete(TerrainCanvas* canvas) void terrainCanvasCopy(TerrainCanvas* source, TerrainCanvas* destination) { - destination->area = source->area; + geoareaCopy(&source->area, &destination->area); destination->offset_y = source->offset_y; destination->height_factor = source->height_factor; heightmapCopy(&source->height_map, &destination->height_map); @@ -56,6 +50,7 @@ void terrainCanvasValidate(TerrainCanvas* canvas) { canvas->detail_scaling = 0.00001; } + geoareaValidate(&canvas->area); heightmapValidate(&canvas->height_map); noiseValidate(canvas->detail_noise); } @@ -76,11 +71,7 @@ LayerType terrainCanvasGetLayerType() void terrainCanvasSave(PackStream* stream, TerrainCanvas* canvas) { - packWriteInt(stream, &canvas->area.bounded); - packWriteDouble(stream, &canvas->area.location_x); - packWriteDouble(stream, &canvas->area.location_z); - packWriteDouble(stream, &canvas->area.size_x); - packWriteDouble(stream, &canvas->area.size_z); + geoareaSave(stream, &canvas->area); packWriteDouble(stream, &canvas->offset_y); heightmapSave(stream, &canvas->height_map); packWriteDouble(stream, &canvas->height_factor); @@ -93,11 +84,7 @@ void terrainCanvasSave(PackStream* stream, TerrainCanvas* canvas) void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas) { - packReadInt(stream, &canvas->area.bounded); - packReadDouble(stream, &canvas->area.location_x); - packReadDouble(stream, &canvas->area.location_z); - packReadDouble(stream, &canvas->area.size_x); - packReadDouble(stream, &canvas->area.size_z); + geoareaLoad(stream, &canvas->area); packReadDouble(stream, &canvas->offset_y); heightmapLoad(stream, &canvas->height_map); packReadDouble(stream, &canvas->height_factor); @@ -116,8 +103,16 @@ void terrainCanvasGetLimits(TerrainCanvas* canvas, double* ymin, double* ymax) *ymax += noise_max; } -void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked) +void terrainCanvasRevertToTerrain(TerrainCanvas* canvas) { + TerrainDefinition terrain; + + terrain = terrainCreateDefinition(); + sceneryGetTerrain(&terrain); + + heightmapRevertToTerrain(&canvas->height_map, &terrain, &canvas->area); + + terrainDeleteDefinition(&terrain); } Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location) diff --git a/lib_paysages/terraincanvas.h b/lib_paysages/terraincanvas.h index 835160e..e61c8d2 100644 --- a/lib_paysages/terraincanvas.h +++ b/lib_paysages/terraincanvas.h @@ -8,20 +8,12 @@ #include "terrain.h" #include "layers.h" #include "heightmap.h" +#include "geoarea.h" #ifdef __cplusplus extern "C" { #endif -typedef struct -{ - int bounded; - double location_x; - double location_z; - double size_x; - double size_z; -} GeoArea; - typedef struct { int mode; @@ -53,7 +45,7 @@ void terrainCanvasSave(PackStream* stream, TerrainCanvas* canvas); void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas); void terrainCanvasGetLimits(TerrainCanvas* canvas, double* ymin, double* ymax); -void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked); +void terrainCanvasRevertToTerrain(TerrainCanvas* canvas); Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location); #ifdef __cplusplus diff --git a/lib_paysages/tools.h b/lib_paysages/tools.h index 012192e..80daa4d 100644 --- a/lib_paysages/tools.h +++ b/lib_paysages/tools.h @@ -7,6 +7,8 @@ #ifdef __cplusplus extern "C" { #endif + +#define UNUSED(_x_) ((void)(_x_)) double toolsRandom(); double toolsBicubicInterpolate(double stencil[16], double x, double y);