2014-08-19 13:49:08 +00:00
|
|
|
#include "OpenGLView.h"
|
|
|
|
|
|
|
|
#include <QQuickWindow>
|
2014-08-27 16:19:48 +00:00
|
|
|
#include <QHoverEvent>
|
2014-08-28 08:29:12 +00:00
|
|
|
#include "MainModelerWindow.h"
|
|
|
|
#include "CameraDefinition.h"
|
2014-08-19 13:49:08 +00:00
|
|
|
#include "OpenGLRenderer.h"
|
|
|
|
#include "Scenery.h"
|
|
|
|
|
|
|
|
OpenGLView::OpenGLView(QQuickItem *parent) :
|
|
|
|
QQuickItem(parent)
|
|
|
|
{
|
|
|
|
initialized = false;
|
2014-08-27 16:19:48 +00:00
|
|
|
window = NULL;
|
2014-08-28 08:29:12 +00:00
|
|
|
renderer = NULL;
|
2014-08-19 13:49:08 +00:00
|
|
|
|
2014-08-27 16:19:48 +00:00
|
|
|
setAcceptedMouseButtons(Qt::AllButtons);
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
setKeepMouseGrab(true);
|
2014-08-19 13:49:08 +00:00
|
|
|
|
2014-08-27 16:19:48 +00:00
|
|
|
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
2014-09-18 15:38:37 +00:00
|
|
|
startTimer(50);
|
2014-08-19 13:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLView::handleWindowChanged(QQuickWindow *win)
|
|
|
|
{
|
|
|
|
if (win)
|
|
|
|
{
|
2014-08-28 08:29:12 +00:00
|
|
|
window = qobject_cast<MainModelerWindow *>(win);
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
renderer = window->getRenderer();
|
2014-08-27 16:19:48 +00:00
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
|
2014-08-19 13:49:08 +00:00
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
win->setClearBeforeRendering(false);
|
2014-08-19 13:49:08 +00:00
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
initialized = false;
|
|
|
|
}
|
2014-08-19 13:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLView::paint()
|
|
|
|
{
|
|
|
|
if (not initialized)
|
|
|
|
{
|
2014-08-28 08:29:12 +00:00
|
|
|
renderer->initialize();
|
2014-08-19 13:49:08 +00:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
renderer->resize(width(), height());
|
|
|
|
renderer->prepareOpenGLState();
|
|
|
|
renderer->paint();
|
2014-08-19 15:01:42 +00:00
|
|
|
|
2014-08-27 16:19:48 +00:00
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
window->resetOpenGLState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLView::hoverMoveEvent(QHoverEvent *event)
|
|
|
|
{
|
2014-08-28 08:29:12 +00:00
|
|
|
if (!renderer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
/*CameraDefinition camera;
|
2014-08-28 08:29:12 +00:00
|
|
|
renderer->getScenery()->getCamera(&camera);
|
2014-08-27 16:19:48 +00:00
|
|
|
|
|
|
|
QPointF diff = event->posF() - event->oldPosF();
|
|
|
|
camera.strafeRight(diff.x() * 0.1);
|
|
|
|
camera.strafeUp(diff.y() * 0.1);
|
|
|
|
camera.validate();
|
|
|
|
|
2014-08-28 08:29:12 +00:00
|
|
|
camera.copy(renderer->render_camera);
|
|
|
|
renderer->getScenery()->setCamera(&camera);
|
|
|
|
renderer->getScenery()->getCamera(&camera);
|
|
|
|
renderer->cameraChangeEvent(&camera);
|
2014-08-27 16:19:48 +00:00
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
window->update();
|
2014-09-18 15:38:37 +00:00
|
|
|
}*/
|
2014-08-27 16:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLView::timerEvent(QTimerEvent *)
|
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
window->update();
|
|
|
|
}
|
2014-08-19 13:49:08 +00:00
|
|
|
}
|