Added water rendering toggle in opengl

This commit is contained in:
Michaël Lemaire 2015-08-21 00:25:34 +02:00
parent 13c8816f9e
commit 28c9c08d74
9 changed files with 82 additions and 25 deletions

View file

@ -4,13 +4,27 @@
#include "Scenery.h" #include "Scenery.h"
#include "TerrainDefinition.h" #include "TerrainDefinition.h"
#include "FloatPropertyBind.h" #include "FloatPropertyBind.h"
#include "OpenGLRenderer.h"
#include "OpenGLWater.h"
WaterModeler::WaterModeler(MainModelerWindow *main) WaterModeler::WaterModeler(MainModelerWindow *ui):
ui(ui)
{ {
prop_water_height = new FloatPropertyBind(main, "water_height", "value", main->getScenery()->getTerrain()->propWaterHeight()); QObject *toggle_water = ui->findQmlObject("camera_toggle_water");
if (toggle_water)
{
connect(toggle_water, SIGNAL(changed(bool)), this, SLOT(enableRendering(bool)));
}
prop_water_height = new FloatPropertyBind(ui, "water_height", "value", ui->getScenery()->getTerrain()->propWaterHeight());
} }
WaterModeler::~WaterModeler() WaterModeler::~WaterModeler()
{ {
delete prop_water_height; delete prop_water_height;
} }
void WaterModeler::enableRendering(bool enable)
{
ui->getRenderer()->getWater()->setEnabled(enable);
}

View file

@ -1,18 +1,25 @@
#ifndef WATERMODELER_H #ifndef WATERMODELER_H
#define WATERMODELER_H #define WATERMODELER_H
#include <QObject>
#include "modeler_global.h" #include "modeler_global.h"
namespace paysages { namespace paysages {
namespace modeler { namespace modeler {
class WaterModeler class WaterModeler: public QObject
{ {
Q_OBJECT
public: public:
WaterModeler(MainModelerWindow *main); WaterModeler(MainModelerWindow *ui);
~WaterModeler(); ~WaterModeler();
public slots:
void enableRendering(bool enable);
private: private:
MainModelerWindow *ui;
FloatPropertyBind *prop_water_height; FloatPropertyBind *prop_water_height;
}; };

View file

@ -19,6 +19,15 @@ Toolbar {
hovertext: qsTr("Top-down camera") hovertext: qsTr("Top-down camera")
} }
ToolbarButton {
id: camera_toggle_water
objectName: "camera_toggle_water"
toggle: true
selected: true
picture: "images/toggle_water.png"
hovertext: qsTr("Toggle water rendering")
}
states: [ states: [
State { State {
name: "Render camera" name: "Render camera"

View file

@ -21,7 +21,10 @@ BaseRectangle {
{ {
for (var i = 0; i < children.length; i++) for (var i = 0; i < children.length; i++)
{ {
children[i].selected = false; if (!children[i].toggle)
{
children[i].selected = false;
}
} }
} }
} }

View file

@ -2,23 +2,28 @@ import QtQuick 2.0
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
Item { Item {
id: button
property string picture property string picture
property bool selected: false property bool selected: false
property bool hovered: false property bool hovered: false
property bool toggle: false
property string helptext property string helptext
property string hovertext property string hovertext
signal clicked signal clicked
signal changed(bool value)
width: image.width + 10 width: image.width + 10
height: image.height + 10 height: image.height + 10
onSelectedChanged: changed(selected)
Rectangle { Rectangle {
id: glow id: glow
anchors.fill: parent anchors.fill: parent
color: "#cccccc" color: parent.toggle ? "#bbccbb" : "#cccccc"
radius: 8 radius: 8
opacity: parent.selected ? 1.0 : (parent.hovered ? 0.5 : 0.0) opacity: button.selected ? 1.0 : (button.hovered ? 0.5 : 0.0)
Behavior on opacity { Behavior on opacity {
PropertyAnimation { PropertyAnimation {
duration: 200 duration: 200
@ -28,14 +33,14 @@ Item {
anchors.fill: glow anchors.fill: glow
glowRadius: 8 glowRadius: 8
spread: 0.2 spread: 0.2
color: "white" color: button.toggle ? "#99aa99" : "#ffffff"
cornerRadius: glow.radius + glowRadius cornerRadius: glow.radius + glowRadius
} }
} }
Image { Image {
id: image id: image
source: parent.picture source: button.picture
anchors.centerIn: parent anchors.centerIn: parent
width: 32 width: 32
height: 32 height: 32
@ -57,34 +62,37 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onEntered: { onEntered: {
parent.hovered = true; button.hovered = true;
tooltip_widget.hovertext = hovertext; tooltip_widget.hovertext = hovertext;
tooltip_widget.hovered = this; tooltip_widget.hovered = this;
} }
onExited: { onExited: {
parent.hovered = false; button.hovered = false;
tooltip_widget.hovertext = ""; tooltip_widget.hovertext = "";
} }
onClicked: { onClicked: {
parent.selected = !parent.selected; button.selected = !button.selected;
if (parent.selected) if (!button.toggle)
{ {
var toolbar = parent.parent; if (button.selected)
for (var i = 0; i < toolbar.children.length; ++i)
{ {
var child = toolbar.children[i] var toolbar = button.parent;
if (child !== parent) for (var i = 0; i < toolbar.children.length; ++i)
{ {
child.selected = false; var child = toolbar.children[i]
if (child !== button && !child.toggle)
{
child.selected = false;
}
} }
tooltip_widget.helptext = helptext;
}
else
{
tooltip_widget.helptext = "";
} }
tooltip_widget.helptext = helptext;
} }
else button.clicked();
{
tooltip_widget.helptext = "";
}
parent.clicked();
} }
} }
} }

View file

@ -37,5 +37,6 @@
<file>images/arrow_down.png</file> <file>images/arrow_down.png</file>
<file>images/arrow_up.png</file> <file>images/arrow_up.png</file>
<file>ClickableImage.qml</file> <file>ClickableImage.qml</file>
<file>images/toggle_water.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

View file

@ -15,6 +15,7 @@ OpenGLWater::OpenGLWater(OpenGLRenderer *renderer):
OpenGLPart(renderer) OpenGLPart(renderer)
{ {
vertices = new float[4 * 3]; vertices = new float[4 * 3];
enabled = true;
} }
OpenGLWater::~OpenGLWater() OpenGLWater::~OpenGLWater()
@ -54,7 +55,10 @@ void OpenGLWater::update()
void OpenGLWater::render() void OpenGLWater::render()
{ {
program->drawTriangleStrip(vertices, 4); if (enabled)
{
program->drawTriangleStrip(vertices, 4);
}
} }
void OpenGLWater::setVertex(int i, float x, float y, float z) void OpenGLWater::setVertex(int i, float x, float y, float z)
@ -71,3 +75,8 @@ void OpenGLWater::nodeChanged(const DefinitionNode *node, const DefinitionDiff *
renderer->getSharedState()->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset()); renderer->getSharedState()->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset());
} }
} }
void OpenGLWater::setEnabled(bool enabled)
{
this->enabled = enabled;
}

View file

@ -20,9 +20,15 @@ public:
virtual void render() override; virtual void render() override;
virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff) override; virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff) override;
/**
* Enable or disable the water surface rendering.
*/
void setEnabled(bool enabled);
private: private:
void setVertex(int i, float x, float y, float z); void setVertex(int i, float x, float y, float z);
bool enabled;
OpenGLShaderProgram* program; OpenGLShaderProgram* program;
float* vertices; float* vertices;
}; };