paysages : Small improvements.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@405 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-08-08 14:44:37 +00:00 committed by ThunderK
parent bca21193c3
commit 7d446591c9
9 changed files with 41 additions and 10 deletions

1
TODO
View file

@ -12,7 +12,6 @@ Technology Preview 2 :
=> Add areas marking. => Add areas marking.
- Improve terrain canvas editor. - Improve terrain canvas editor.
=> Add GeoArea editor. => Add GeoArea editor.
=> Apply GeoArea to revertToTerrain.
=> Resample map on changing resolution. => Resample map on changing resolution.
=> Map loading should not choose arbitrary resolution. => Map loading should not choose arbitrary resolution.
- Improve textures (current model is greatly incorrect). - Improve textures (current model is greatly incorrect).

View file

@ -28,6 +28,10 @@ void BaseFormLayer::applyConfig()
BaseForm::applyConfig(); BaseForm::applyConfig();
} }
void BaseFormLayer::afterLayerAdded(void*)
{
}
void BaseFormLayer::configChangeEvent() void BaseFormLayer::configChangeEvent()
{ {
layerApply(layersGetLayer(_layers_modified, currentLayer())); layerApply(layersGetLayer(_layers_modified, currentLayer()));
@ -57,7 +61,10 @@ void BaseFormLayer::layerAddedEvent()
if (layer >= 0) if (layer >= 0)
{ {
layersSetName(_layers_modified, layer, layer_name.toUtf8().data()); layersSetName(_layers_modified, layer, layer_name.toUtf8().data());
BaseForm::layerAddedEvent(); BaseForm::layerAddedEvent();
afterLayerAdded(layersGetLayer(_layers_modified, layer));
} }
} }
} }

View file

@ -21,6 +21,7 @@ public slots:
protected: protected:
virtual void layerGetCopy(void* layer_definition) = 0; virtual void layerGetCopy(void* layer_definition) = 0;
virtual void layerApply(void* layer_definition) = 0; virtual void layerApply(void* layer_definition) = 0;
virtual void afterLayerAdded(void* layer_definition);
private: private:
virtual QStringList getLayers(); virtual QStringList getLayers();

View file

@ -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); 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()) if (!result.isEmpty())
{ {
int new_res_x, new_res_y; int new_res_x, new_res_z;
if (result == QString("64 x 64")) 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")) 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")) else if (result == QString("512 x 512"))
{ {
new_res_x = new_res_y = 512; new_res_x = new_res_z = 512;
} }
else 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(); _3dview->revert();
updateResolutionLabel(); updateResolutionLabel();
} }

View file

@ -72,3 +72,8 @@ void FormTerrainCanvas::layerApply(void* layer_definition)
{ {
terrainCanvasCopy(_definition, (TerrainCanvas*)layer_definition); terrainCanvasCopy(_definition, (TerrainCanvas*)layer_definition);
} }
void FormTerrainCanvas::afterLayerAdded(void* layer_definition)
{
terrainCanvasRevertToTerrain((TerrainCanvas*)layer_definition);
}

View file

@ -17,6 +17,7 @@ public:
protected: protected:
virtual void layerGetCopy(void* layer_definition); virtual void layerGetCopy(void* layer_definition);
virtual void layerApply(void* layer_definition); virtual void layerApply(void* layer_definition);
virtual void afterLayerAdded(void* layer_definition);
private: private:
TerrainCanvas* _definition; TerrainCanvas* _definition;

View file

@ -51,3 +51,15 @@ void geoareaLoad(PackStream* stream, GeoArea* geoarea)
packReadDouble(stream, &geoarea->size_x); packReadDouble(stream, &geoarea->size_x);
packReadDouble(stream, &geoarea->size_z); 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;
}

View file

@ -25,6 +25,9 @@ void geoareaValidate(GeoArea* geoarea);
void geoareaSave(PackStream* stream, GeoArea* geoarea); void geoareaSave(PackStream* stream, GeoArea* geoarea);
void geoareaLoad(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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -167,6 +167,7 @@ void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain,
{ {
int rx, rz; int rx, rz;
int x, z; int x, z;
double dx, dz;
rx = heightmap->resolution_x; rx = heightmap->resolution_x;
rz = heightmap->resolution_z; rz = heightmap->resolution_z;
@ -174,8 +175,10 @@ void heightmapRevertToTerrain(HeightMap* heightmap, TerrainDefinition* terrain,
{ {
for (z = 0; z < rz; z++) for (z = 0; z < rz; z++)
{ {
/* FIXME Apply geoarea */ dx = (double)x / (double)(rx - 1);
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); dz = (double)z / (double)(rz - 1);
geoareaFromLocal(area, dx, dz, &dx, &dz);
heightmap->data[z * rx + x] = terrainGetHeight(terrain, dx, dz);
} }
} }
} }