From 9a177352bad6709336136b711339a90738c6c6b8 Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Tue, 18 Aug 2015 22:47:18 +0200 Subject: [PATCH] Fixed OpenGL camera management --- src/interface/modeler/quickapp/MainModelerWindow.cpp | 1 + src/interface/modeler/quickapp/ModelerCameras.cpp | 8 +++++--- src/render/opengl/OpenGLRenderer.cpp | 11 +++++------ src/render/opengl/OpenGLRenderer.h | 2 -- src/render/software/SoftwareRenderer.cpp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index 320ad45..1d37d72 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -51,6 +51,7 @@ MainModelerWindow::~MainModelerWindow() delete render_process; delete renderer; + delete scenery; } QObject *MainModelerWindow::findQmlObject(const QString &objectName) diff --git a/src/interface/modeler/quickapp/ModelerCameras.cpp b/src/interface/modeler/quickapp/ModelerCameras.cpp index 5340aaa..e2994f4 100644 --- a/src/interface/modeler/quickapp/ModelerCameras.cpp +++ b/src/interface/modeler/quickapp/ModelerCameras.cpp @@ -21,6 +21,9 @@ ModelerCameras::ModelerCameras(MainModelerWindow *parent): QObject *widget = parent->findQmlObject("camera_choice"); connect(widget, SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString))); + // Validate to apply initial camera to scenery + validate(); + // Start update timer startTimer(50); } @@ -57,14 +60,13 @@ void ModelerCameras::processPanning(double xvalue, double yvalue) void ModelerCameras::timerEvent(QTimerEvent *) { - OpenGLRenderer *renderer = parent->getRenderer(); - current->transitionToAnother(active, 0.3); - renderer->setCamera(current); + parent->getRenderer()->setCamera(current); } void ModelerCameras::validate() { + parent->getScenery()->keepCameraAboveGround(current); parent->getScenery()->keepCameraAboveGround(active); if (active == render) { diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 5db4b9d..0ff88af 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -69,7 +69,7 @@ void OpenGLRenderer::initialize() terrain->initialize(); terrain->updateScenery(); - cameraChangeEvent(getScenery()->getCamera()); + cameraChangeEvent(render_camera); } else { @@ -110,9 +110,8 @@ void OpenGLRenderer::prepareOpenGLState() void OpenGLRenderer::setCamera(CameraDefinition *camera) { camera->copy(render_camera); - getScenery()->setCamera(camera); - getScenery()->getCamera(camera); - cameraChangeEvent(camera); + getScenery()->keepCameraAboveGround(render_camera); + cameraChangeEvent(render_camera); } void OpenGLRenderer::resize(int width, int height) @@ -120,10 +119,10 @@ void OpenGLRenderer::resize(int width, int height) vp_width = width; vp_height = height; - getScenery()->getCamera()->setRenderSize(width, height); + getScenery()->getCamera()->setRenderSize(width, height); // FIXME Should not be needed render_camera->setRenderSize(width, height); - cameraChangeEvent(getScenery()->getCamera()); + cameraChangeEvent(render_camera); prepareOpenGLState(); } diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index bbcb3e0..c3f840b 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -39,8 +39,6 @@ public: /** * 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); diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index b1f6b00..2b9519a 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -26,6 +26,8 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery): render_quality = 5; render_camera = new CameraDefinition; + scenery->getCamera()->copy(render_camera); + atmosphere_renderer = new BaseAtmosphereRenderer(this); clouds_renderer = new CloudsRenderer(this); terrain_renderer = new TerrainRenderer(this); @@ -60,8 +62,6 @@ SoftwareRenderer::~SoftwareRenderer() void SoftwareRenderer::prepare() { - scenery->getCamera()->copy(render_camera); - // Prepare sub renderers // TODO Don't recreate the renderer each time delete atmosphere_renderer;