Fixed OpenGL camera management

This commit is contained in:
Michaël Lemaire 2015-08-18 22:47:18 +02:00
parent 56dae1e38e
commit 9a177352ba
5 changed files with 13 additions and 13 deletions

View file

@ -51,6 +51,7 @@ MainModelerWindow::~MainModelerWindow()
delete render_process; delete render_process;
delete renderer; delete renderer;
delete scenery;
} }
QObject *MainModelerWindow::findQmlObject(const QString &objectName) QObject *MainModelerWindow::findQmlObject(const QString &objectName)

View file

@ -21,6 +21,9 @@ ModelerCameras::ModelerCameras(MainModelerWindow *parent):
QObject *widget = parent->findQmlObject("camera_choice"); QObject *widget = parent->findQmlObject("camera_choice");
connect(widget, SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString))); connect(widget, SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString)));
// Validate to apply initial camera to scenery
validate();
// Start update timer // Start update timer
startTimer(50); startTimer(50);
} }
@ -57,14 +60,13 @@ void ModelerCameras::processPanning(double xvalue, double yvalue)
void ModelerCameras::timerEvent(QTimerEvent *) void ModelerCameras::timerEvent(QTimerEvent *)
{ {
OpenGLRenderer *renderer = parent->getRenderer();
current->transitionToAnother(active, 0.3); current->transitionToAnother(active, 0.3);
renderer->setCamera(current); parent->getRenderer()->setCamera(current);
} }
void ModelerCameras::validate() void ModelerCameras::validate()
{ {
parent->getScenery()->keepCameraAboveGround(current);
parent->getScenery()->keepCameraAboveGround(active); parent->getScenery()->keepCameraAboveGround(active);
if (active == render) { if (active == render) {

View file

@ -69,7 +69,7 @@ void OpenGLRenderer::initialize()
terrain->initialize(); terrain->initialize();
terrain->updateScenery(); terrain->updateScenery();
cameraChangeEvent(getScenery()->getCamera()); cameraChangeEvent(render_camera);
} }
else else
{ {
@ -110,9 +110,8 @@ void OpenGLRenderer::prepareOpenGLState()
void OpenGLRenderer::setCamera(CameraDefinition *camera) void OpenGLRenderer::setCamera(CameraDefinition *camera)
{ {
camera->copy(render_camera); camera->copy(render_camera);
getScenery()->setCamera(camera); getScenery()->keepCameraAboveGround(render_camera);
getScenery()->getCamera(camera); cameraChangeEvent(render_camera);
cameraChangeEvent(camera);
} }
void OpenGLRenderer::resize(int width, int height) void OpenGLRenderer::resize(int width, int height)
@ -120,10 +119,10 @@ void OpenGLRenderer::resize(int width, int height)
vp_width = width; vp_width = width;
vp_height = height; vp_height = height;
getScenery()->getCamera()->setRenderSize(width, height); getScenery()->getCamera()->setRenderSize(width, height); // FIXME Should not be needed
render_camera->setRenderSize(width, height); render_camera->setRenderSize(width, height);
cameraChangeEvent(getScenery()->getCamera()); cameraChangeEvent(render_camera);
prepareOpenGLState(); prepareOpenGLState();
} }

View file

@ -39,8 +39,6 @@ public:
/** /**
* Change the camera location. * Change the camera location.
*
* This may change the camera passed as argument (to stay above ground for example).
*/ */
void setCamera(CameraDefinition *camera); void setCamera(CameraDefinition *camera);
void cameraChangeEvent(CameraDefinition* camera); void cameraChangeEvent(CameraDefinition* camera);

View file

@ -26,6 +26,8 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery):
render_quality = 5; render_quality = 5;
render_camera = new CameraDefinition; render_camera = new CameraDefinition;
scenery->getCamera()->copy(render_camera);
atmosphere_renderer = new BaseAtmosphereRenderer(this); atmosphere_renderer = new BaseAtmosphereRenderer(this);
clouds_renderer = new CloudsRenderer(this); clouds_renderer = new CloudsRenderer(this);
terrain_renderer = new TerrainRenderer(this); terrain_renderer = new TerrainRenderer(this);
@ -60,8 +62,6 @@ SoftwareRenderer::~SoftwareRenderer()
void SoftwareRenderer::prepare() void SoftwareRenderer::prepare()
{ {
scenery->getCamera()->copy(render_camera);
// Prepare sub renderers // Prepare sub renderers
// TODO Don't recreate the renderer each time // TODO Don't recreate the renderer each time
delete atmosphere_renderer; delete atmosphere_renderer;