quick ui : Added basic camera controls
This commit is contained in:
parent
57b90af132
commit
1cc3a4d625
5 changed files with 55 additions and 27 deletions
|
@ -19,6 +19,7 @@ public:
|
||||||
|
|
||||||
inline Scenery *getScenery() const {return scenery;}
|
inline Scenery *getScenery() const {return scenery;}
|
||||||
inline OpenGLRenderer *getRenderer() const {return renderer;}
|
inline OpenGLRenderer *getRenderer() const {return renderer;}
|
||||||
|
inline ModelerCameras *getCamera() const {return cameras;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void keyReleaseEvent(QKeyEvent *event) override;
|
virtual void keyReleaseEvent(QKeyEvent *event) override;
|
||||||
|
|
|
@ -32,11 +32,22 @@ ModelerCameras::~ModelerCameras()
|
||||||
delete topdown;
|
delete topdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelerCameras::processZoom(double value)
|
||||||
|
{
|
||||||
|
active->strafeForward(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelerCameras::processScroll(double xvalue, double yvalue)
|
||||||
|
{
|
||||||
|
active->strafeRight(xvalue);
|
||||||
|
active->strafeUp(yvalue);
|
||||||
|
}
|
||||||
|
|
||||||
void ModelerCameras::timerEvent(QTimerEvent *)
|
void ModelerCameras::timerEvent(QTimerEvent *)
|
||||||
{
|
{
|
||||||
OpenGLRenderer *renderer = parent->getRenderer();
|
OpenGLRenderer *renderer = parent->getRenderer();
|
||||||
|
|
||||||
current->transitionToAnother(active, 0.1);
|
current->transitionToAnother(active, 0.3);
|
||||||
renderer->setCamera(current);
|
renderer->setCamera(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,16 @@ public:
|
||||||
ModelerCameras(MainModelerWindow *parent);
|
ModelerCameras(MainModelerWindow *parent);
|
||||||
~ModelerCameras();
|
~ModelerCameras();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a zoom request.
|
||||||
|
*/
|
||||||
|
void processZoom(double value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a scroll request.
|
||||||
|
*/
|
||||||
|
void processScroll(double xvalue, double yvalue);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QHoverEvent>
|
#include <QHoverEvent>
|
||||||
#include "MainModelerWindow.h"
|
#include "MainModelerWindow.h"
|
||||||
#include "CameraDefinition.h"
|
|
||||||
#include "OpenGLRenderer.h"
|
#include "OpenGLRenderer.h"
|
||||||
#include "Scenery.h"
|
#include "ModelerCameras.h"
|
||||||
|
|
||||||
OpenGLView::OpenGLView(QQuickItem *parent) :
|
OpenGLView::OpenGLView(QQuickItem *parent) :
|
||||||
QQuickItem(parent)
|
QQuickItem(parent)
|
||||||
|
@ -15,8 +14,8 @@ OpenGLView::OpenGLView(QQuickItem *parent) :
|
||||||
renderer = NULL;
|
renderer = NULL;
|
||||||
|
|
||||||
setAcceptedMouseButtons(Qt::AllButtons);
|
setAcceptedMouseButtons(Qt::AllButtons);
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
setKeepMouseGrab(true);
|
mouse_button = Qt::NoButton;
|
||||||
|
|
||||||
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
||||||
startTimer(50);
|
startTimer(50);
|
||||||
|
@ -42,7 +41,7 @@ void OpenGLView::handleWindowChanged(QQuickWindow *win)
|
||||||
|
|
||||||
void OpenGLView::paint()
|
void OpenGLView::paint()
|
||||||
{
|
{
|
||||||
if (not initialized)
|
if (not initialized or not renderer)
|
||||||
{
|
{
|
||||||
renderer->initialize();
|
renderer->initialize();
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -58,29 +57,30 @@ void OpenGLView::paint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLView::hoverMoveEvent(QHoverEvent *event)
|
void OpenGLView::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (!renderer)
|
window->getCamera()->processZoom(0.1 * (double)event->angleDelta().y());
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*CameraDefinition camera;
|
void OpenGLView::mousePressEvent(QMouseEvent *event)
|
||||||
renderer->getScenery()->getCamera(&camera);
|
|
||||||
|
|
||||||
QPointF diff = event->posF() - event->oldPosF();
|
|
||||||
camera.strafeRight(diff.x() * 0.1);
|
|
||||||
camera.strafeUp(diff.y() * 0.1);
|
|
||||||
camera.validate();
|
|
||||||
|
|
||||||
camera.copy(renderer->render_camera);
|
|
||||||
renderer->getScenery()->setCamera(&camera);
|
|
||||||
renderer->getScenery()->getCamera(&camera);
|
|
||||||
renderer->cameraChangeEvent(&camera);
|
|
||||||
if (window)
|
|
||||||
{
|
{
|
||||||
window->update();
|
mouse_button = event->button();
|
||||||
}*/
|
mouse_pos = event->windowPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLView::mouseReleaseEvent(QMouseEvent *)
|
||||||
|
{
|
||||||
|
mouse_button = Qt::NoButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLView::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
QPointF diff = event->windowPos() - mouse_pos;
|
||||||
|
if (mouse_button == Qt::MidButton)
|
||||||
|
{
|
||||||
|
window->getCamera()->processScroll(-0.1 * diff.x(), 0.1 * diff.y());
|
||||||
|
}
|
||||||
|
mouse_pos = event->windowPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLView::timerEvent(QTimerEvent *)
|
void OpenGLView::timerEvent(QTimerEvent *)
|
||||||
|
|
|
@ -19,13 +19,19 @@ public slots:
|
||||||
void paint();
|
void paint();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void hoverMoveEvent(QHoverEvent *event) override;
|
virtual void wheelEvent(QWheelEvent *event) override;
|
||||||
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
virtual void timerEvent(QTimerEvent *event) override;
|
virtual void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized;
|
bool initialized;
|
||||||
MainModelerWindow *window;
|
MainModelerWindow *window;
|
||||||
OpenGLRenderer *renderer;
|
OpenGLRenderer *renderer;
|
||||||
|
|
||||||
|
Qt::MouseButton mouse_button;
|
||||||
|
QPointF mouse_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue