diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index c82ceaf..c21b459 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -5,6 +5,7 @@ #include "OpenGLRenderer.h" #include "AtmosphereModeler.h" #include "WaterModeler.h" +#include "ModelerCameras.h" #include "RenderPreviewProvider.h" #include "RenderProcess.h" #include "RenderConfig.h" @@ -28,6 +29,7 @@ MainModelerWindow::MainModelerWindow() setResizeMode(QQuickView::SizeRootObjectToView); setSource(QUrl("qrc:///main.qml")); + cameras = new ModelerCameras(this); atmosphere = new AtmosphereModeler(this); water = new WaterModeler(this); } @@ -36,6 +38,7 @@ MainModelerWindow::~MainModelerWindow() { delete atmosphere; delete water; + delete cameras; delete render_preview_provider; delete render_process; diff --git a/src/interface/modeler/quickapp/MainModelerWindow.h b/src/interface/modeler/quickapp/MainModelerWindow.h index bc159c2..841d230 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.h +++ b/src/interface/modeler/quickapp/MainModelerWindow.h @@ -30,6 +30,8 @@ private: AtmosphereModeler *atmosphere; WaterModeler *water; + ModelerCameras *cameras; + RenderPreviewProvider *render_preview_provider; RenderProcess *render_process; }; diff --git a/src/interface/modeler/quickapp/ModelerCameras.cpp b/src/interface/modeler/quickapp/ModelerCameras.cpp new file mode 100644 index 0000000..90ecc47 --- /dev/null +++ b/src/interface/modeler/quickapp/ModelerCameras.cpp @@ -0,0 +1,53 @@ +#include "ModelerCameras.h" + +#include "MainModelerWindow.h" +#include "OpenGLRenderer.h" +#include "Scenery.h" +#include "CameraDefinition.h" + +ModelerCameras::ModelerCameras(MainModelerWindow *parent): + QObject(parent), parent(parent) +{ + render = new CameraDefinition(); + topdown = new CameraDefinition(); + current = new CameraDefinition(); + active = render; + + topdown->strafeForward(-10.0); + topdown->strafeUp(25.0); + topdown->rotatePitch(-0.8); + + // Watch GUI choice + QObject *widget = parent->findQmlObject("camera_choice"); + connect(widget, SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString))); + + // Start update timer + startTimer(50); +} + +ModelerCameras::~ModelerCameras() +{ + delete current; + delete render; + delete topdown; +} + +void ModelerCameras::timerEvent(QTimerEvent *) +{ + OpenGLRenderer *renderer = parent->getRenderer(); + + current->transitionToAnother(active, 0.1); + renderer->setCamera(current); +} + +void ModelerCameras::changeActiveCamera(const QString &name) +{ + if (name == "Render camera") + { + active = render; + } + else if (name == "Top-down camera") + { + active = topdown; + } +} diff --git a/src/interface/modeler/quickapp/ModelerCameras.h b/src/interface/modeler/quickapp/ModelerCameras.h new file mode 100644 index 0000000..dffaf81 --- /dev/null +++ b/src/interface/modeler/quickapp/ModelerCameras.h @@ -0,0 +1,39 @@ +#ifndef MODELERCAMERAS_H +#define MODELERCAMERAS_H + +#include "modeler_global.h" + +#include + +namespace paysages { +namespace modeler { + +/** + * Storage for modeler cameras. + */ +class ModelerCameras: public QObject +{ + Q_OBJECT + +public: + ModelerCameras(MainModelerWindow *parent); + ~ModelerCameras(); + +protected: + void timerEvent(QTimerEvent *event); + +public slots: + void changeActiveCamera(const QString &name); + +private: + MainModelerWindow *parent; + CameraDefinition *active; + CameraDefinition *current; + CameraDefinition *render; + CameraDefinition *topdown; +}; + +} +} + +#endif // MODELERCAMERAS_H diff --git a/src/interface/modeler/quickapp/OpenGLView.cpp b/src/interface/modeler/quickapp/OpenGLView.cpp index 23f0211..6d8c960 100644 --- a/src/interface/modeler/quickapp/OpenGLView.cpp +++ b/src/interface/modeler/quickapp/OpenGLView.cpp @@ -19,7 +19,7 @@ OpenGLView::OpenGLView(QQuickItem *parent) : setKeepMouseGrab(true); connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); - startTimer(250); + startTimer(50); } void OpenGLView::handleWindowChanged(QQuickWindow *win) @@ -65,7 +65,7 @@ void OpenGLView::hoverMoveEvent(QHoverEvent *event) return; } - CameraDefinition camera; + /*CameraDefinition camera; renderer->getScenery()->getCamera(&camera); QPointF diff = event->posF() - event->oldPosF(); @@ -80,7 +80,7 @@ void OpenGLView::hoverMoveEvent(QHoverEvent *event) if (window) { window->update(); - } + }*/ } void OpenGLView::timerEvent(QTimerEvent *) diff --git a/src/interface/modeler/quickapp/modeler_global.h b/src/interface/modeler/quickapp/modeler_global.h index d2749ac..135e12b 100644 --- a/src/interface/modeler/quickapp/modeler_global.h +++ b/src/interface/modeler/quickapp/modeler_global.h @@ -15,6 +15,8 @@ namespace modeler { class RenderPreviewProvider; class RenderProcess; + + class ModelerCameras; } } diff --git a/src/interface/modeler/quickapp/qml/CameraChoice.qml b/src/interface/modeler/quickapp/qml/CameraChoice.qml new file mode 100644 index 0000000..8df3ae4 --- /dev/null +++ b/src/interface/modeler/quickapp/qml/CameraChoice.qml @@ -0,0 +1,39 @@ +import QtQuick 2.0 + +Rectangle { + id: camera_choice + width: 200 + height: 50 + color: "#90888888" + objectName: "camera_choice" + + Row { + id: inner_space + anchors.centerIn: parent + spacing: 15 + + ToolbarButton { + id: camera_choice_render + picture: "images/tab_display.png" + hovertext: qsTr("Switch to the final camera") + selected: true + } + + ToolbarButton { + id: camera_choice_topdown + picture: "images/display_topdown.png" + hovertext: qsTr("Switch to the top-down camera") + } + } + + states: [ + State { + name: "Render camera" + when: camera_choice_render.selected + }, + State { + name: "Top-down camera" + when: camera_choice_topdown.selected + } + ] +} diff --git a/src/interface/modeler/quickapp/qml/app.qrc b/src/interface/modeler/quickapp/qml/app.qrc index 6abd781..dc6d8a4 100644 --- a/src/interface/modeler/quickapp/qml/app.qrc +++ b/src/interface/modeler/quickapp/qml/app.qrc @@ -26,5 +26,6 @@ BaseChoice.qml BaseChoiceItem.qml RenderDialog.qml + CameraChoice.qml diff --git a/src/interface/modeler/quickapp/qml/main.qml b/src/interface/modeler/quickapp/qml/main.qml index 38048fd..bc18a73 100644 --- a/src/interface/modeler/quickapp/qml/main.qml +++ b/src/interface/modeler/quickapp/qml/main.qml @@ -91,6 +91,12 @@ OpenGLView { } } + CameraChoice { + id: camera_choice + anchors.bottom: main_ui.bottom + anchors.horizontalCenter: main_ui.horizontalCenter + } + RenderDialog { id: render_dialog opacity: 0 diff --git a/src/interface/modeler/quickapp/quickapp.pro b/src/interface/modeler/quickapp/quickapp.pro index 989f285..9257aecc 100644 --- a/src/interface/modeler/quickapp/quickapp.pro +++ b/src/interface/modeler/quickapp/quickapp.pro @@ -10,7 +10,8 @@ SOURCES += main.cpp \ WaterModeler.cpp \ AtmosphereModeler.cpp \ RenderPreviewProvider.cpp \ - RenderProcess.cpp + RenderProcess.cpp \ + ModelerCameras.cpp RESOURCES += \ qml/app.qrc @@ -30,7 +31,8 @@ HEADERS += \ WaterModeler.h \ AtmosphereModeler.h \ RenderPreviewProvider.h \ - RenderProcess.h + RenderProcess.h \ + ModelerCameras.h win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../system/release/ -lpaysages_system else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../system/debug/ -lpaysages_system @@ -74,4 +76,5 @@ OTHER_FILES += \ qml/BaseSlider.qml \ qml/BaseChoice.qml \ qml/BaseChoiceItem.qml \ - qml/RenderDialog.qml + qml/RenderDialog.qml \ + qml/CameraChoice.qml diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 1361795..00a80bb 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -106,6 +106,14 @@ void OpenGLRenderer::prepareOpenGLState() } } +void OpenGLRenderer::setCamera(CameraDefinition *camera) +{ + camera->copy(render_camera); + getScenery()->setCamera(camera); + getScenery()->getCamera(camera); + cameraChangeEvent(camera); +} + void OpenGLRenderer::resize(int width, int height) { vp_width = width; diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index 57ef059..9954d5e 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -26,6 +26,12 @@ public: void resize(int width, int height); void paint(); + /** + * Change the camera location. + * + * This may change the camera passed as argument (to stay above ground for example). + */ + void setCamera(CameraDefinition *camera); void cameraChangeEvent(CameraDefinition* camera); inline OpenGLFunctions* getOpenGlFunctions() const {return functions;}