From b5b3e401db7c205222d14623b14cd2c89ec1d33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 10 May 2013 15:40:49 +0000 Subject: [PATCH] paysages: WIP git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@568 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- Makefile | 5 +- data/ui_pictures.qrc | 1 + src/editing/terrain/dialogterrainpainting.cpp | 91 +++ src/editing/terrain/dialogterrainpainting.h | 4 + src/editing/terrain/dialogterrainpainting.ui | 613 ++++++++++++++++-- src/editing/terrain/mainterrainform.ui | 21 + src/editing/widgetheightmap.cpp | 25 +- src/editing/widgetheightmap.h | 2 + src/exploring/chunk.c | 88 +++ src/exploring/chunk.h | 22 + 10 files changed, 822 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 6e08bdf..e3308d6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -BUILDMODE=debug +BUILDMODE=release BUILDPATH=./build/${BUILDMODE} CC=gcc MAKE=make @@ -26,6 +26,9 @@ clean: rm -f ${BUILDPATH}/libpaysages_exploring.so rm -f ${BUILDPATH}/libpaysages_rendering.so +debug: + make BUILDMODE=debug all + release: make BUILDMODE=release all diff --git a/data/ui_pictures.qrc b/data/ui_pictures.qrc index 189785a..b16e299 100644 --- a/data/ui_pictures.qrc +++ b/data/ui_pictures.qrc @@ -5,6 +5,7 @@ images/revert.png images/explore.png images/render.png + images/about.png images/tab_atmosphere.png diff --git a/src/editing/terrain/dialogterrainpainting.cpp b/src/editing/terrain/dialogterrainpainting.cpp index 79bf742..e362a28 100644 --- a/src/editing/terrain/dialogterrainpainting.cpp +++ b/src/editing/terrain/dialogterrainpainting.cpp @@ -2,6 +2,9 @@ #include "ui_dialogterrainpainting.h" #include "tools.h" +#include +#include +#include DialogTerrainPainting::DialogTerrainPainting(QWidget*parent, TerrainDefinition* terrain) : QDialog(parent), @@ -12,6 +15,12 @@ DialogTerrainPainting::DialogTerrainPainting(QWidget*parent, TerrainDefinition* _terrain_original = terrain; _terrain_modified = (TerrainDefinition*)TerrainDefinitionClass.create(); + QWidget* widget = findChild("widget_commands"); + if (widget) + { + widget->hide(); + } + revert(); brushConfigChanged(); @@ -22,6 +31,88 @@ DialogTerrainPainting::~DialogTerrainPainting() delete ui; } +void DialogTerrainPainting::keyReleaseEvent(QKeyEvent* event) +{ + QComboBox* input_brush_mode = findChild("input_brush_mode"); + + switch (event->key()) + { + case Qt::Key_F2: + if (input_brush_mode) + { + input_brush_mode->setCurrentIndex(0); + } + event->accept(); + break; + case Qt::Key_F3: + if (input_brush_mode) + { + input_brush_mode->setCurrentIndex(1); + } + event->accept(); + break; + case Qt::Key_F4: + if (input_brush_mode) + { + input_brush_mode->setCurrentIndex(2); + } + event->accept(); + break; + case Qt::Key_F11: + if (input_brush_mode) + { + input_brush_mode->setCurrentIndex(3); + } + event->accept(); + break; + case Qt::Key_F12: + if (input_brush_mode) + { + input_brush_mode->setCurrentIndex(4); + } + event->accept(); + break; + default: + QDialog::keyReleaseEvent(event); + } +} + +void DialogTerrainPainting::wheelEvent(QWheelEvent* event) +{ + QSlider* input_brush_size = findChild("input_brush_size"); + QSlider* input_brush_smoothing = findChild("input_brush_smoothing"); + QSlider* input_brush_strength = findChild("input_brush_strength"); + + if (event->modifiers() & Qt::ControlModifier) + { + if (input_brush_size) + { + input_brush_size->setValue(input_brush_size->value() + (event->delta() > 0 ? 1 : -1)); + } + event->accept(); + } + else if (event->modifiers() & Qt::ShiftModifier) + { + if (input_brush_strength) + { + input_brush_strength->setValue(input_brush_strength->value() + (event->delta() > 0 ? 1 : -1)); + } + event->accept(); + } + else if (event->modifiers() & Qt::AltModifier) + { + if (input_brush_smoothing) + { + input_brush_smoothing->setValue(input_brush_smoothing->value() + (event->delta() > 0 ? 1 : -1)); + } + event->accept(); + } + else + { + event->ignore(); + } +} + void DialogTerrainPainting::accept() { TerrainDefinitionClass.copy(_terrain_modified, _terrain_original); diff --git a/src/editing/terrain/dialogterrainpainting.h b/src/editing/terrain/dialogterrainpainting.h index 74d546d..4cbf109 100644 --- a/src/editing/terrain/dialogterrainpainting.h +++ b/src/editing/terrain/dialogterrainpainting.h @@ -17,6 +17,10 @@ public: explicit DialogTerrainPainting(QWidget *parent, TerrainDefinition* terrain); ~DialogTerrainPainting(); +protected: + virtual void keyReleaseEvent(QKeyEvent* event); + virtual void wheelEvent(QWheelEvent* event); + public slots: void brushConfigChanged(); void heightmapChanged(); diff --git a/src/editing/terrain/dialogterrainpainting.ui b/src/editing/terrain/dialogterrainpainting.ui index 85a4e0c..e50addc 100644 --- a/src/editing/terrain/dialogterrainpainting.ui +++ b/src/editing/terrain/dialogterrainpainting.ui @@ -6,8 +6,8 @@ 0 0 - 949 - 618 + 1116 + 726 @@ -29,19 +29,487 @@ - + - + 1 - 0 + 1 - - - 400 - 400 - - + + + QLayout::SetDefaultConstraint + + + + + 20 + + + + + Water + + + true + + + + + + + Grid + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Commands + + + + :/buttons/logo/images/about.png:/buttons/logo/images/about.png + + + + 16 + 16 + + + + F1 + + + true + + + false + + + false + + + + + + + + + + + + + + + + 0 + 0 + + + + Shortcuts + + + true + + + + + + 16 + + + + + Switch to raise/lower tool + + + true + + + + + + + + 75 + true + + + + F3 + + + true + + + + + + + Show these commands + + + true + + + + + + + + 75 + true + + + + F4 + + + true + + + + + + + + 75 + true + + + + F1 + + + true + + + + + + + + 75 + true + + + + F2 + + + true + + + + + + + + 75 + true + + + + F11 + + + true + + + + + + + Switch to noise/smooth tool + + + true + + + + + + + Switch to flatten tool + + + true + + + + + + + Switch to magix fix tool + + + true + + + + + + + + 75 + true + + + + F12 + + + true + + + + + + + Switch to restore tool + + + true + + + + + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Brush control + + + true + + + + + + 16 + + + + + Set brush smoothing + + + true + + + + + + + + 75 + true + + + + SHIFT + Mouse wheel + + + true + + + + + + + Set brush size + + + true + + + + + + + + 75 + true + + + + CTRL + Mouse wheel + + + true + + + + + + + + 75 + true + + + + ALT + Mouse wheel + + + true + + + + + + + Set brush strength + + + true + + + + + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Camera control + + + true + + + + + + 16 + + + + + + 75 + true + + + + Mouse wheel + + + true + + + + + + + + 75 + true + + + + Borders + + + true + + + + + + + Scroll view + + + true + + + + + + + Zoom + + + true + + + + + + + + + + + + + + + + 1 + 1 + + + + + 400 + 400 + + + + + @@ -72,17 +540,17 @@ - Raise / Lower (F1) + Raise / Lower (F2) - Add noise / Smooth (F2) + Add noise / Smooth (F3) - Flatten terrain (F3) + Flatten terrain (F4) @@ -325,6 +793,8 @@ 1 heightmapChanged() + toggleWater(bool) + toggleGrid(bool) @@ -334,7 +804,9 @@ input_brush_smoothing input_brush_strength - + + + input_brush_smoothing @@ -343,8 +815,8 @@ brushConfigChanged() - 728 - 97 + 919 + 94 437 @@ -375,8 +847,8 @@ brushConfigChanged() - 762 - 135 + 919 + 115 437 @@ -391,8 +863,8 @@ brushConfigChanged() - 676 - 67 + 919 + 73 437 @@ -400,22 +872,6 @@ - - widget_heightmap - heightmapChanged() - DialogTerrainPainting - heightmapChanged() - - - 396 - 566 - - - 445 - 618 - - - widget_4 cancelClicked() @@ -423,12 +879,12 @@ reject() - 870 - 600 + 875 + 580 711 - 618 + 597 @@ -439,12 +895,12 @@ accept() - 816 - 593 + 943 + 587 683 - 615 + 597 @@ -455,12 +911,76 @@ revert() - 827 - 606 + 943 + 587 747 - 618 + 597 + + + + + checkBox + toggled(bool) + widget_heightmap + toggleWater(bool) + + + 40 + 21 + + + 39 + 160 + + + + + checkBox_2 + toggled(bool) + widget_heightmap + toggleGrid(bool) + + + 102 + 17 + + + 102 + 143 + + + + + widget_heightmap + heightmapChanged() + DialogTerrainPainting + heightmapChanged() + + + 465 + 523 + + + 481 + 569 + + + + + pushButton + toggled(bool) + widget_commands + setShown(bool) + + + 516 + 20 + + + 517 + 50 @@ -469,5 +989,6 @@ brushConfigChanged() heightmapChanged() revert() + displayCommands() diff --git a/src/editing/terrain/mainterrainform.ui b/src/editing/terrain/mainterrainform.ui index 10bba5b..96abd77 100644 --- a/src/editing/terrain/mainterrainform.ui +++ b/src/editing/terrain/mainterrainform.ui @@ -24,6 +24,9 @@ Infinite base shape + + true + @@ -76,6 +79,9 @@ Manual modifications + + true + @@ -115,6 +121,9 @@ Global modifiers + + true + @@ -181,6 +190,9 @@ Rendering control + + true + @@ -217,6 +229,9 @@ Links to other modules + + true + @@ -318,6 +333,9 @@ Result preview + + true + @@ -384,6 +402,9 @@ Actions + + true + diff --git a/src/editing/widgetheightmap.cpp b/src/editing/widgetheightmap.cpp index 2a7120c..fc8fa8c 100644 --- a/src/editing/widgetheightmap.cpp +++ b/src/editing/widgetheightmap.cpp @@ -90,6 +90,18 @@ void WidgetHeightMap::revert() updateGL(); } +void WidgetHeightMap::toggleWater(bool enabled) +{ + _water = enabled; + updateGL(); +} + +void WidgetHeightMap::toggleGrid(bool enabled) +{ + _wireframe = enabled; + updateGL(); +} + void WidgetHeightMap::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Up) @@ -124,11 +136,18 @@ void WidgetHeightMap::keyPressEvent(QKeyEvent* event) void WidgetHeightMap::wheelEvent(QWheelEvent* event) { - if (event->orientation() == Qt::Vertical) + if (event->modifiers() == Qt::NoModifier) { - zoomTopCamera(-0.05 * (double) event->delta()); + if (event->orientation() == Qt::Vertical) + { + zoomTopCamera(-0.05 * (double) event->delta()); + } + event->accept(); + } + else + { + event->ignore(); } - event->accept(); } void WidgetHeightMap::mousePressEvent(QMouseEvent* event) diff --git a/src/editing/widgetheightmap.h b/src/editing/widgetheightmap.h index 64a8781..f218e49 100644 --- a/src/editing/widgetheightmap.h +++ b/src/editing/widgetheightmap.h @@ -28,6 +28,8 @@ public: public slots: void revert(); + void toggleWater(bool enabled); + void toggleGrid(bool enabled); signals: void heightmapChanged(); diff --git a/src/exploring/chunk.c b/src/exploring/chunk.c index 3a07abc..d70e8dc 100644 --- a/src/exploring/chunk.c +++ b/src/exploring/chunk.c @@ -1 +1,89 @@ #include "chunk.h" + +#include + +struct ExplorerChunk +{ + /* Links */ + Renderer* renderer; + ColorProfile* color_profile; + + /* Protected override */ + ExplorerChunkOverride override; + + /* Bounding box */ + double xmin; + double xmax; + double ymin; + double ymax; + double zmin; + double zmax; + + /* General status */ + int reset_needed; + double distance_to_camera; + + /* Tesselation */ + Vector3* vertex_data; + int tessellation_max_size; + int tessellation_current_size; + double tessellation_step; + + /* Texture */ + /*GLuint texture_opengl_id; + int texture_changed; + int texture_current_size; + int texture_max_size;*/ +}; + +ExplorerChunk* exporerChunkCreate(Renderer* renderer, ColorProfile* color_profile, ExplorerChunkOverride override) +{ + ExplorerChunk* result; + + result = malloc(sizeof(ExplorerChunk)); + + result->renderer = renderer; + result->color_profile = color_profile; + + result->override = override; + + result->xmin = 0.0; + result->xmax = 0.0; + result->ymin = 0.0; + result->ymax = 0.0; + result->zmin = 0.0; + result->zmax = 0.0; + + result->reset_needed = 0; + result->distance_to_camera = 0.0; + + result->vertex_data = malloc(sizeof(Vector3) * 4); + result->tessellation_max_size = 1; + result->tessellation_current_size = 0; + + explorerChunkMarkForReset(result); + + /* TODO Insert in chunk list */ + + return result; +} + +void explorerChunkDelete(ExplorerChunk* chunk) +{ + free(chunk); +} + +void explorerChunkUpdateBoundingBox(ExplorerChunk* chunk, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) +{ + chunk->xmin = xmin; + chunk->xmax = xmax; + chunk->ymin = ymin; + chunk->ymax = ymax; + chunk->zmin = zmin; + chunk->zmax = zmax; +} + +void explorerChunkMarkForReset(ExplorerChunk* chunk) +{ + +} diff --git a/src/exploring/chunk.h b/src/exploring/chunk.h index b1368c6..2f27c1c 100644 --- a/src/exploring/chunk.h +++ b/src/exploring/chunk.h @@ -1,10 +1,32 @@ #ifndef _PAYSAGES_EXPLORING_CHUNK_H_ #define _PAYSAGES_EXPLORING_CHUNK_H_ +#include "rendering/tools/euclid.h" +#include "rendering/tools/color.h" +#include "rendering/renderer.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct ExplorerChunk ExplorerChunk; + +typedef struct +{ + void (*getStatus)(ExplorerChunk* chunk); + Vector3 (*getVertex)(ExplorerChunk* chunk, Renderer* renderer, double x, double y); + Color (*getColor)(ExplorerChunk* chunk, Renderer* renderer, double x, double y, Vector3 vertex); + void (*onBeforeDelete)(ExplorerChunk* chunk, void* private_data); + void* private_data; +} ExplorerChunkOverride; + +/* Public methods */ +ExplorerChunk* exporerChunkCreate(Renderer* renderer, ColorProfile* color_profile, ExplorerChunkOverride override); +void explorerChunkDelete(ExplorerChunk* chunk); + +/* Methods to call from an updateStatus() callback only (never to be called twice concurrently on the same chunk) */ +void explorerChunkUpdateBoundingBox(ExplorerChunk* chunk, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax); +void explorerChunkMarkForReset(ExplorerChunk* chunk); #ifdef __cplusplus }