paysages : Heightmap editor - Added resolution control.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@404 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-08-08 14:25:01 +00:00 committed by ThunderK
parent 11d48cc3c3
commit bca21193c3
3 changed files with 75 additions and 1 deletions

6
TODO
View file

@ -10,7 +10,11 @@ Technology Preview 2 :
- Improve previews. - Improve previews.
=> Add user markers on OSD. => Add user markers on OSD.
=> Add areas marking. => Add areas marking.
- Start a terrain editor (see mockup). - 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). - Improve textures (current model is greatly incorrect).
=> Separate models (basic texture and covering texture). => Separate models (basic texture and covering texture).
=> Covering texture height should inpact terrain height. => Covering texture height should inpact terrain height.

View file

@ -7,6 +7,7 @@
#include <QComboBox> #include <QComboBox>
#include <QSlider> #include <QSlider>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog>
#include <math.h> #include <math.h>
#include "../lib_paysages/terrain.h" #include "../lib_paysages/terrain.h"
#include "../lib_paysages/scenery.h" #include "../lib_paysages/scenery.h"
@ -77,6 +78,14 @@ DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap, TerrainC
connect(button, SIGNAL(clicked()), this, SLOT(loadFromFile())); connect(button, SIGNAL(clicked()), this, SLOT(loadFromFile()));
panel->layout()->addWidget(button); panel->layout()->addWidget(button);
button = new QPushButton(tr("Change resolution"), panel);
connect(button, SIGNAL(clicked()), this, SLOT(changeResolution()));
panel->layout()->addWidget(button);
_resolution_label = new QLabel("", panel);
panel->layout()->addWidget(_resolution_label);
updateResolutionLabel();
combobox = new QComboBox(panel); combobox = new QComboBox(panel);
combobox->addItem(tr("Raise / lower")); combobox->addItem(tr("Raise / lower"));
combobox->addItem(tr("Add noise / smooth")); combobox->addItem(tr("Add noise / smooth"));
@ -148,6 +157,7 @@ void DialogHeightMap::revert()
{ {
heightmapCopy(_value_original, &_value_modified); heightmapCopy(_value_original, &_value_modified);
_3dview->revert(); _3dview->revert();
updateResolutionLabel();
} }
void DialogHeightMap::angleHChanged(int value) void DialogHeightMap::angleHChanged(int value)
@ -187,6 +197,7 @@ void DialogHeightMap::loadFromFile()
{ {
heightmapImportFromPicture(&_value_modified, (char*) filepath.toStdString().c_str()); heightmapImportFromPicture(&_value_modified, (char*) filepath.toStdString().c_str());
_3dview->revert(); _3dview->revert();
updateResolutionLabel();
} }
} }
@ -206,3 +217,58 @@ void DialogHeightMap::resetToTerrain()
_3dview->revert(); _3dview->revert();
} }
} }
void DialogHeightMap::changeResolution()
{
QString result;
QStringList items;
int current;
items << QString("64 x 64") << QString("128 x 128") << QString("256 x 256") << QString("512 x 512");
current = 1;
if (_value_modified.resolution_x == 64 && _value_modified.resolution_z == 64)
{
current = 0;
}
else if (_value_modified.resolution_x == 256 && _value_modified.resolution_z == 256)
{
current = 2;
}
else if (_value_modified.resolution_x == 512 && _value_modified.resolution_z == 512)
{
current = 3;
}
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;
if (result == QString("64 x 64"))
{
new_res_x = new_res_y = 64;
}
else if (result == QString("256 x 256"))
{
new_res_x = new_res_y = 256;
}
else if (result == QString("512 x 512"))
{
new_res_x = new_res_y = 512;
}
else
{
new_res_x = new_res_y = 128;
}
if (new_res_x != _value_modified.resolution_x or new_res_y != _value_modified.resolution_z)
{
heightmapChangeResolution(&_value_modified, 64, 64);
_3dview->revert();
updateResolutionLabel();
}
}
}
void DialogHeightMap::updateResolutionLabel()
{
_resolution_label->setText(tr("Map resolution : %1 x %2").arg(_value_modified.resolution_x).arg(_value_modified.resolution_z));
}

View file

@ -1,6 +1,7 @@
#ifndef _PAYSAGES_QT_DIALOGHEIGHTMAP_H_ #ifndef _PAYSAGES_QT_DIALOGHEIGHTMAP_H_
#define _PAYSAGES_QT_DIALOGHEIGHTMAP_H_ #define _PAYSAGES_QT_DIALOGHEIGHTMAP_H_
#include <QLabel>
#include "tools.h" #include "tools.h"
#include "widgetheightmap.h" #include "widgetheightmap.h"
#include "../lib_paysages/heightmap.h" #include "../lib_paysages/heightmap.h"
@ -26,11 +27,14 @@ private slots:
void brushStrengthChanged(int value); void brushStrengthChanged(int value);
void loadFromFile(); void loadFromFile();
void resetToTerrain(); void resetToTerrain();
void changeResolution();
void updateResolutionLabel();
private: private:
HeightMap* _value_original; HeightMap* _value_original;
HeightMap _value_modified; HeightMap _value_modified;
WidgetHeightMap* _3dview; WidgetHeightMap* _3dview;
QLabel* _resolution_label;
TerrainCanvas* _canvas; TerrainCanvas* _canvas;
}; };