diff --git a/TODO b/TODO index 8478596..286adc6 100644 --- a/TODO +++ b/TODO @@ -12,7 +12,6 @@ Technology Preview 2 : => Add areas marking. - Improve terrain canvas editor. => Add GeoArea editor. - => Apply GeoArea to revertToTerrain. => Resample map on changing resolution. => Map loading should not choose arbitrary resolution. - Improve textures (current model is greatly incorrect). diff --git a/gui_qt/baseformlayer.cpp b/gui_qt/baseformlayer.cpp index 7cc98f6..7b7d9e8 100644 --- a/gui_qt/baseformlayer.cpp +++ b/gui_qt/baseformlayer.cpp @@ -28,6 +28,10 @@ void BaseFormLayer::applyConfig() BaseForm::applyConfig(); } +void BaseFormLayer::afterLayerAdded(void*) +{ +} + void BaseFormLayer::configChangeEvent() { layerApply(layersGetLayer(_layers_modified, currentLayer())); @@ -57,7 +61,10 @@ void BaseFormLayer::layerAddedEvent() if (layer >= 0) { layersSetName(_layers_modified, layer, layer_name.toUtf8().data()); + BaseForm::layerAddedEvent(); + + afterLayerAdded(layersGetLayer(_layers_modified, layer)); } } } diff --git a/gui_qt/baseformlayer.h b/gui_qt/baseformlayer.h index 8244b63..9d30536 100644 --- a/gui_qt/baseformlayer.h +++ b/gui_qt/baseformlayer.h @@ -21,6 +21,7 @@ public slots: protected: virtual void layerGetCopy(void* layer_definition) = 0; virtual void layerApply(void* layer_definition) = 0; + virtual void afterLayerAdded(void* layer_definition); private: virtual QStringList getLayers(); diff --git a/gui_qt/dialogheightmap.cpp b/gui_qt/dialogheightmap.cpp index 2a732da..53a2c6d 100644 --- a/gui_qt/dialogheightmap.cpp +++ b/gui_qt/dialogheightmap.cpp @@ -241,27 +241,27 @@ void DialogHeightMap::changeResolution() result = QInputDialog::getItem(this, tr("Paysages 3D - Change heightmap resolution"), tr("Choose the new heightmap resolution. Beware that lowering the resolution may imply a loss of accuracy."), items, current, false); if (!result.isEmpty()) { - int new_res_x, new_res_y; + int new_res_x, new_res_z; if (result == QString("64 x 64")) { - new_res_x = new_res_y = 64; + new_res_x = new_res_z = 64; } else if (result == QString("256 x 256")) { - new_res_x = new_res_y = 256; + new_res_x = new_res_z = 256; } else if (result == QString("512 x 512")) { - new_res_x = new_res_y = 512; + new_res_x = new_res_z = 512; } else { - new_res_x = new_res_y = 128; + new_res_x = new_res_z = 128; } - if (new_res_x != _value_modified.resolution_x or new_res_y != _value_modified.resolution_z) + if (new_res_x != _value_modified.resolution_x or new_res_z != _value_modified.resolution_z) { - heightmapChangeResolution(&_value_modified, 64, 64); + heightmapChangeResolution(&_value_modified, new_res_x, new_res_z); _3dview->revert(); updateResolutionLabel(); } diff --git a/gui_qt/formterraincanvas.cpp b/gui_qt/formterraincanvas.cpp index 3146604..757a6d2 100644 --- a/gui_qt/formterraincanvas.cpp +++ b/gui_qt/formterraincanvas.cpp @@ -72,3 +72,8 @@ void FormTerrainCanvas::layerApply(void* layer_definition) { terrainCanvasCopy(_definition, (TerrainCanvas*)layer_definition); } + +void FormTerrainCanvas::afterLayerAdded(void* layer_definition) +{ + terrainCanvasRevertToTerrain((TerrainCanvas*)layer_definition); +} diff --git a/gui_qt/formterraincanvas.h b/gui_qt/formterraincanvas.h index bb372b2..f9f7915 100644 --- a/gui_qt/formterraincanvas.h +++ b/gui_qt/formterraincanvas.h @@ -17,6 +17,7 @@ public: protected: virtual void layerGetCopy(void* layer_definition); virtual void layerApply(void* layer_definition); + virtual void afterLayerAdded(void* layer_definition); private: TerrainCanvas* _definition; diff --git a/lib_paysages/geoarea.c b/lib_paysages/geoarea.c index 9571b05..af55ef2 100644 --- a/lib_paysages/geoarea.c +++ b/lib_paysages/geoarea.c @@ -51,3 +51,15 @@ void geoareaLoad(PackStream* stream, GeoArea* geoarea) packReadDouble(stream, &geoarea->size_x); packReadDouble(stream, &geoarea->size_z); } + +void geoareaToLocal(GeoArea* geoarea, double absolute_x, double absolute_z, double* local_x, double* local_z) +{ + *local_x = (absolute_x - geoarea->location_x) / geoarea->size_x; + *local_z = (absolute_z - geoarea->location_z) / geoarea->size_z; +} + +void geoareaFromLocal(GeoArea* geoarea, double local_x, double local_z, double* absolute_x, double* absolute_z) +{ + *absolute_x = geoarea->location_x + local_x * geoarea->size_x; + *absolute_z = geoarea->location_z + local_z * geoarea->size_z; +} diff --git a/lib_paysages/geoarea.h b/lib_paysages/geoarea.h index e18f1e2..19207b9 100644 --- a/lib_paysages/geoarea.h +++ b/lib_paysages/geoarea.h @@ -24,6 +24,9 @@ void geoareaValidate(GeoArea* geoarea); void geoareaSave(PackStream* stream, GeoArea* geoarea); void geoareaLoad(PackStream* stream, GeoArea* geoarea); + +void geoareaToLocal(GeoArea* geoarea, double absolute_x, double absolute_z, double* local_x, double* local_z); +void geoareaFromLocal(GeoArea* geoarea, double local_x, double local_z, double* absolute_x, double* absolute_z); #ifdef __cplusplus } diff --git a/lib_paysages/heightmap.c b/lib_paysages/heightmap.c index adc16de..0957fb2 100644 --- a/lib_paysages/heightmap.c +++ b/lib_paysages/heightmap.c @@ -167,6 +167,7 @@ void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain, { int rx, rz; int x, z; + double dx, dz; rx = heightmap->resolution_x; rz = heightmap->resolution_z; @@ -174,8 +175,10 @@ void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain, { 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); + dx = (double)x / (double)(rx - 1); + dz = (double)z / (double)(rz - 1); + geoareaFromLocal(area, dx, dz, &dx, &dz); + heightmap->data[z * rx + x] = terrainGetHeight(terrain, dx, dz); } } }