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 "TerrainDefinition.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()
{
delete prop_water_height;
}
void WaterModeler::enableRendering(bool enable)
{
ui->getRenderer()->getWater()->setEnabled(enable);
}

View file

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

View file

@ -19,6 +19,15 @@ Toolbar {
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: [
State {
name: "Render camera"

View file

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

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

View file

@ -15,6 +15,7 @@ OpenGLWater::OpenGLWater(OpenGLRenderer *renderer):
OpenGLPart(renderer)
{
vertices = new float[4 * 3];
enabled = true;
}
OpenGLWater::~OpenGLWater()
@ -54,7 +55,10 @@ void OpenGLWater::update()
void OpenGLWater::render()
{
program->drawTriangleStrip(vertices, 4);
if (enabled)
{
program->drawTriangleStrip(vertices, 4);
}
}
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());
}
}
void OpenGLWater::setEnabled(bool enabled)
{
this->enabled = enabled;
}

View file

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