paysages : Small improvements.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@402 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-08-02 19:26:22 +00:00 committed by ThunderK
parent 42daf819df
commit 77397d35bd
6 changed files with 77 additions and 19 deletions

View file

@ -485,4 +485,9 @@ void BaseForm::layerSelectedEvent(int layer)
{
_previews_list[i]->redraw();
}
_layer_del->setEnabled(layer >= 0);
_layer_rename->setEnabled(layer >= 0);
_layer_down->setEnabled(layer > 0);
_layer_up->setEnabled(layer >= 0 and layer < _layer_count - 1);
}

View file

@ -1,5 +1,7 @@
#include "baseformlayer.h"
#include <QInputDialog>
BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true)
{
_layers_original = layers;
@ -48,12 +50,16 @@ QStringList BaseFormLayer::getLayers()
void BaseFormLayer::layerAddedEvent()
{
QString layer_name = QInputDialog::getText(this, tr("Create layer"), tr("Layer name :"), QLineEdit::Normal, tr("Unnamed layer"));
if (not layer_name.isEmpty())
{
int layer = layersAddLayer(_layers_modified, NULL);
if (layer >= 0)
{
layersSetName(_layers_modified, layer, tr("Unnamed").toUtf8().data());
layersSetName(_layers_modified, layer, layer_name.toUtf8().data());
BaseForm::layerAddedEvent();
}
}
}
void BaseFormLayer::layerDeletedEvent(int layer)

View file

@ -153,8 +153,8 @@ FormTerrain::FormTerrain(QWidget *parent):
previewHeight = new PreviewTerrainHeight(this);
previewColor = new PreviewTerrainColor(this);
addPreview(previewHeight, QString(tr("Height preview (normalized)")));
addPreview(previewColor, QString(tr("Lighted preview (no texture)")));
addPreview(previewHeight, tr("Height preview (normalized)"));
addPreview(previewColor, tr("Lighted preview (no texture)"));
addInputNoise(tr("Noise"), _definition.height_noise);
addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0);

View file

@ -1,5 +1,41 @@
#include "formterraincanvas.h"
/**************** Form ****************/
class PreviewTerrainCanvasHeight:public BasePreview
{
public:
PreviewTerrainCanvasHeight(QWidget* parent, TerrainCanvas* canvas):BasePreview(parent)
{
_base_canvas = canvas;
_preview_canvas = terrainCanvasCreate();
//addOsd(QString("geolocation"));
configScaling(0.5, 200.0, 3.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewTerrainCanvasHeight()
{
terrainCanvasDelete(_preview_canvas);
}
protected:
QColor getColor(double x, double y)
{
double height;
height = 0.0; // TODO
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
}
void updateData()
{
terrainCanvasCopy(_base_canvas, _preview_canvas);
}
private:
TerrainCanvas* _base_canvas;
TerrainCanvas* _preview_canvas;
};
/**************** Form ****************/
FormTerrainCanvas::FormTerrainCanvas(QWidget *parent, Layers* layers):
BaseFormLayer(parent, layers)
@ -7,15 +43,18 @@ FormTerrainCanvas::FormTerrainCanvas(QWidget *parent, Layers* layers):
_definition = terrainCanvasCreate();
// TODO Area
addInputDouble(tr("Apply at height"), &_definition->offset_y, -20.0, 20.0, 0.1, 1.0);
//addInputDouble(tr("Apply at height"), &_definition->offset_y, -20.0, 20.0, 0.1, 1.0);
addInputHeightMap(tr("Height map"), &_definition->height_map);
addInputDouble(tr("Canvas height"), &_definition->height_factor, 0.0, 20.0, 0.1, 1.0);
//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);
addInputDouble(tr("Detail noise scaling"), &_definition->detail_scaling, 0.0, 20.0, 0.1, 1.0);
addInputEnum(tr("Mask shape"), &_definition->mask.mode, QStringList(tr("Square")) << tr("Circle"));
addInputDouble(tr("Mask smoothing"), &_definition->mask.smoothing, 0.0, 1.0, 0.01, 0.1);
_previewHeight = new PreviewTerrainCanvasHeight(this, _definition);
addPreview(_previewHeight, tr("Height preview (normalized)"));
revertConfig();
}

View file

@ -20,8 +20,8 @@ protected:
private:
TerrainCanvas* _definition;
// BasePreview* previewHeight;
// BasePreview* previewColor;
BasePreview* _previewHeight;
BasePreview* _previewColor;
};
#endif

View file

@ -4,7 +4,6 @@
#include <QMouseEvent>
#include <math.h>
#include <GL/glu.h>
#include <qt4/QtCore/qlocale.h>
#include "tools.h"
#include "../lib_paysages/terrain.h"
#include "../lib_paysages/scenery.h"
@ -42,7 +41,7 @@ WidgetHeightMap::WidgetHeightMap(QWidget *parent, HeightMap* heightmap):
_brush_strength = 1.0;
_brush_noise = noiseCreateGenerator();
noiseGenerateBaseNoise(_brush_noise, 102400);
noiseAddLevelsSimple(_brush_noise, 6, 1.0, 1.0);
noiseAddLevelsSimple(_brush_noise, 10, 1.0, 1.0);
}
WidgetHeightMap::~WidgetHeightMap()
@ -188,7 +187,7 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
case HEIGHTMAP_BRUSH_SMOOTH:
if (_last_brush_action < 0)
{
heightmapBrushSmooth(_heightmap, &brush, brush_strength);
heightmapBrushSmooth(_heightmap, &brush, brush_strength * 0.1);
}
else
{
@ -209,15 +208,19 @@ void WidgetHeightMap::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
GLfloat light_position[] = { 40.0, 40.0, 40.0, 0.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_diffuse[] = { 0.75, 0.74, 0.7, 1.0 };
GLfloat light_specular[] = { 0.0, 0.0, 0.0, 0.0 };
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
light_diffuse[0] = 0.3;
light_diffuse[1] = 0.3;
light_diffuse[2] = 0.4;
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);
//glFrontFace(GL_CCW);
@ -255,8 +258,6 @@ void WidgetHeightMap::paintGL()
double frame_time;
int rx, rz;
start_time = QTime::currentTime();
// Update vertex cache
if (_dirty)
{
@ -293,6 +294,13 @@ void WidgetHeightMap::paintGL()
glLoadIdentity();
gluLookAt(50.0 * cos(_angle_h) * cos(_angle_v), 50.0 * sin(_angle_v), -50.0 * sin(_angle_h) * cos(_angle_v), 0.0, 0.0, 0.0, -cos(_angle_h) * sin(_angle_v), cos(_angle_v), sin(_angle_h) * sin(_angle_v));
// Place lights
GLfloat light_position[] = { 40.0, 40.0, 40.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
light_position[0] = -40.0;
light_position[2] = -60.0;
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
// Background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);