From 14031615e41f964eea2cb1792c7efbc7a941c8bb Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nicolas.pope@utu.fi>
Date: Sun, 2 Feb 2020 09:14:45 +0200
Subject: [PATCH] Resolves #191 gui camera pose bug

---
 applications/gui/src/camera.cpp | 10 ++++++++++
 applications/gui/src/camera.hpp |  5 +++++
 applications/gui/src/screen.cpp |  2 ++
 3 files changed, 17 insertions(+)

diff --git a/applications/gui/src/camera.cpp b/applications/gui/src/camera.cpp
index a6f578179..a541d910d 100644
--- a/applications/gui/src/camera.cpp
+++ b/applications/gui/src/camera.cpp
@@ -576,6 +576,16 @@ bool ftl::gui::Camera::thumbnail(cv::Mat &thumb) {
 	return true;
 }
 
+void ftl::gui::Camera::active(bool a) {
+	if (a) {
+
+	} else {
+		neye_[0] = eye_[0];
+		neye_[1] = eye_[1];
+		neye_[2] = eye_[2];
+	}
+}
+
 const GLTexture &ftl::gui::Camera::captureFrame() {
 	float now = (float)glfwGetTime();
 	delta_ = now - ftime_;
diff --git a/applications/gui/src/camera.hpp b/applications/gui/src/camera.hpp
index b92f24154..fd4f91d5a 100644
--- a/applications/gui/src/camera.hpp
+++ b/applications/gui/src/camera.hpp
@@ -66,6 +66,11 @@ class Camera {
 
 	void draw(std::vector<ftl::rgbd::FrameSet*> &fss);
 
+	/**
+	 * @internal. Used to inform the camera if it is the active camera or not.
+	 */
+	void active(bool);
+
 	const GLTexture &captureFrame();
 	const GLTexture &getLeft() const { return texture1_; }
 	const GLTexture &getRight() const { return texture2_; }
diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp
index 70a79163b..2d2274058 100644
--- a/applications/gui/src/screen.cpp
+++ b/applications/gui/src/screen.cpp
@@ -360,6 +360,7 @@ ftl::gui::Screen::~Screen() {
 }
 
 void ftl::gui::Screen::setActiveCamera(ftl::gui::Camera *cam) {
+	if (camera_) camera_->active(false);
 	camera_ = cam;
 
 	if (cam) {
@@ -367,6 +368,7 @@ void ftl::gui::Screen::setActiveCamera(ftl::gui::Camera *cam) {
 		mwindow_->setVisible(true);
 		mwindow_->cameraChanged();
 		swindow_->setVisible(false);
+		cam->active(true);
 	} else {
 		mwindow_->setVisible(false);
 		swindow_->setVisible(true);
-- 
GitLab