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 renderer;
delete scenery;
}
QObject *MainModelerWindow::findQmlObject(const QString &objectName)

View file

@ -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) {

View file

@ -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();
}

View file

@ -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);

View file

@ -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;