Added progressive camera change to opengl view
This commit is contained in:
parent
872e191fea
commit
57b90af132
12 changed files with 168 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "OpenGLRenderer.h"
|
#include "OpenGLRenderer.h"
|
||||||
#include "AtmosphereModeler.h"
|
#include "AtmosphereModeler.h"
|
||||||
#include "WaterModeler.h"
|
#include "WaterModeler.h"
|
||||||
|
#include "ModelerCameras.h"
|
||||||
#include "RenderPreviewProvider.h"
|
#include "RenderPreviewProvider.h"
|
||||||
#include "RenderProcess.h"
|
#include "RenderProcess.h"
|
||||||
#include "RenderConfig.h"
|
#include "RenderConfig.h"
|
||||||
|
@ -28,6 +29,7 @@ MainModelerWindow::MainModelerWindow()
|
||||||
setResizeMode(QQuickView::SizeRootObjectToView);
|
setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
setSource(QUrl("qrc:///main.qml"));
|
setSource(QUrl("qrc:///main.qml"));
|
||||||
|
|
||||||
|
cameras = new ModelerCameras(this);
|
||||||
atmosphere = new AtmosphereModeler(this);
|
atmosphere = new AtmosphereModeler(this);
|
||||||
water = new WaterModeler(this);
|
water = new WaterModeler(this);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +38,7 @@ MainModelerWindow::~MainModelerWindow()
|
||||||
{
|
{
|
||||||
delete atmosphere;
|
delete atmosphere;
|
||||||
delete water;
|
delete water;
|
||||||
|
delete cameras;
|
||||||
|
|
||||||
delete render_preview_provider;
|
delete render_preview_provider;
|
||||||
delete render_process;
|
delete render_process;
|
||||||
|
|
|
@ -30,6 +30,8 @@ private:
|
||||||
AtmosphereModeler *atmosphere;
|
AtmosphereModeler *atmosphere;
|
||||||
WaterModeler *water;
|
WaterModeler *water;
|
||||||
|
|
||||||
|
ModelerCameras *cameras;
|
||||||
|
|
||||||
RenderPreviewProvider *render_preview_provider;
|
RenderPreviewProvider *render_preview_provider;
|
||||||
RenderProcess *render_process;
|
RenderProcess *render_process;
|
||||||
};
|
};
|
||||||
|
|
53
src/interface/modeler/quickapp/ModelerCameras.cpp
Normal file
53
src/interface/modeler/quickapp/ModelerCameras.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
39
src/interface/modeler/quickapp/ModelerCameras.h
Normal file
39
src/interface/modeler/quickapp/ModelerCameras.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef MODELERCAMERAS_H
|
||||||
|
#define MODELERCAMERAS_H
|
||||||
|
|
||||||
|
#include "modeler_global.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
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
|
|
@ -19,7 +19,7 @@ OpenGLView::OpenGLView(QQuickItem *parent) :
|
||||||
setKeepMouseGrab(true);
|
setKeepMouseGrab(true);
|
||||||
|
|
||||||
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
||||||
startTimer(250);
|
startTimer(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLView::handleWindowChanged(QQuickWindow *win)
|
void OpenGLView::handleWindowChanged(QQuickWindow *win)
|
||||||
|
@ -65,7 +65,7 @@ void OpenGLView::hoverMoveEvent(QHoverEvent *event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraDefinition camera;
|
/*CameraDefinition camera;
|
||||||
renderer->getScenery()->getCamera(&camera);
|
renderer->getScenery()->getCamera(&camera);
|
||||||
|
|
||||||
QPointF diff = event->posF() - event->oldPosF();
|
QPointF diff = event->posF() - event->oldPosF();
|
||||||
|
@ -80,7 +80,7 @@ void OpenGLView::hoverMoveEvent(QHoverEvent *event)
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
window->update();
|
window->update();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLView::timerEvent(QTimerEvent *)
|
void OpenGLView::timerEvent(QTimerEvent *)
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace modeler {
|
||||||
|
|
||||||
class RenderPreviewProvider;
|
class RenderPreviewProvider;
|
||||||
class RenderProcess;
|
class RenderProcess;
|
||||||
|
|
||||||
|
class ModelerCameras;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
src/interface/modeler/quickapp/qml/CameraChoice.qml
Normal file
39
src/interface/modeler/quickapp/qml/CameraChoice.qml
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -26,5 +26,6 @@
|
||||||
<file>BaseChoice.qml</file>
|
<file>BaseChoice.qml</file>
|
||||||
<file>BaseChoiceItem.qml</file>
|
<file>BaseChoiceItem.qml</file>
|
||||||
<file>RenderDialog.qml</file>
|
<file>RenderDialog.qml</file>
|
||||||
|
<file>CameraChoice.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -91,6 +91,12 @@ OpenGLView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CameraChoice {
|
||||||
|
id: camera_choice
|
||||||
|
anchors.bottom: main_ui.bottom
|
||||||
|
anchors.horizontalCenter: main_ui.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
RenderDialog {
|
RenderDialog {
|
||||||
id: render_dialog
|
id: render_dialog
|
||||||
opacity: 0
|
opacity: 0
|
||||||
|
|
|
@ -10,7 +10,8 @@ SOURCES += main.cpp \
|
||||||
WaterModeler.cpp \
|
WaterModeler.cpp \
|
||||||
AtmosphereModeler.cpp \
|
AtmosphereModeler.cpp \
|
||||||
RenderPreviewProvider.cpp \
|
RenderPreviewProvider.cpp \
|
||||||
RenderProcess.cpp
|
RenderProcess.cpp \
|
||||||
|
ModelerCameras.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
qml/app.qrc
|
qml/app.qrc
|
||||||
|
@ -30,7 +31,8 @@ HEADERS += \
|
||||||
WaterModeler.h \
|
WaterModeler.h \
|
||||||
AtmosphereModeler.h \
|
AtmosphereModeler.h \
|
||||||
RenderPreviewProvider.h \
|
RenderPreviewProvider.h \
|
||||||
RenderProcess.h
|
RenderProcess.h \
|
||||||
|
ModelerCameras.h
|
||||||
|
|
||||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../system/release/ -lpaysages_system
|
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
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../system/debug/ -lpaysages_system
|
||||||
|
@ -74,4 +76,5 @@ OTHER_FILES += \
|
||||||
qml/BaseSlider.qml \
|
qml/BaseSlider.qml \
|
||||||
qml/BaseChoice.qml \
|
qml/BaseChoice.qml \
|
||||||
qml/BaseChoiceItem.qml \
|
qml/BaseChoiceItem.qml \
|
||||||
qml/RenderDialog.qml
|
qml/RenderDialog.qml \
|
||||||
|
qml/CameraChoice.qml
|
||||||
|
|
|
@ -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)
|
void OpenGLRenderer::resize(int width, int height)
|
||||||
{
|
{
|
||||||
vp_width = width;
|
vp_width = width;
|
||||||
|
|
|
@ -26,6 +26,12 @@ public:
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
void paint();
|
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);
|
void cameraChangeEvent(CameraDefinition* camera);
|
||||||
|
|
||||||
inline OpenGLFunctions* getOpenGlFunctions() const {return functions;}
|
inline OpenGLFunctions* getOpenGlFunctions() const {return functions;}
|
||||||
|
|
Loading…
Reference in a new issue