diff --git a/applications/gui/src/main.cpp b/applications/gui/src/main.cpp index be2ac713acbdd7dc37a0424067daaefa438f660c..3df95ca79874cebcf2c9b96439e5d60cf268adb5 100644 --- a/applications/gui/src/main.cpp +++ b/applications/gui/src/main.cpp @@ -161,7 +161,24 @@ class FTLApplication : public nanogui::Screen { } else { auto src_ = swindow_->getSource(); if (src_ && src_->isReady() && down) { - Eigen::Vector4f camPos = src_->point(p[0],p[1]); + Eigen::Vector2f screenSize = size().cast<float>(); + auto mScale = (screenSize.cwiseQuotient(imageSize).minCoeff()); + Eigen::Vector2f scaleFactor = mScale * imageSize.cwiseQuotient(screenSize); + Eigen::Vector2f positionInScreen(0.0f, 0.0f); + auto mOffset = (screenSize - (screenSize.cwiseProduct(scaleFactor))) / 2; + Eigen::Vector2f positionAfterOffset = positionInScreen + mOffset; + + float sx = ((float)p[0] - positionAfterOffset[0]) / mScale; + float sy = ((float)p[1] - positionAfterOffset[1]) / mScale; + + Eigen::Vector4f camPos; + + try { + camPos = src_->point(sx,sy); + } catch(...) { + return true; + } + camPos *= -1.0f; Eigen::Vector4f worldPos = src_->getPose() * camPos; lookPoint_ = Eigen::Vector3f(worldPos[0],worldPos[1],worldPos[2]); @@ -195,7 +212,7 @@ class FTLApplication : public nanogui::Screen { using namespace Eigen; auto src_ = swindow_->getSource(); - Vector2f imageSize(0, 0); + imageSize = {0, 0}; float now = (float)glfwGetTime(); float delta = now - ftime_; @@ -273,6 +290,7 @@ class FTLApplication : public nanogui::Screen { float lerpSpeed_; bool depth_; float ftime_; + Eigen::Vector2f imageSize; }; int main(int argc, char **argv) { diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp index bd68b0ae86bdb79b3ec18b80afa3be09005637ad..2f51b6fdcf32f9661fead5ac550eb9f007ca072e 100644 --- a/components/rgbd-sources/src/source.cpp +++ b/components/rgbd-sources/src/source.cpp @@ -128,8 +128,8 @@ void Source::getFrames(cv::Mat &rgb, cv::Mat &depth) { Eigen::Vector4f Source::point(uint ux, uint uy) { const auto ¶ms = parameters(); - const float x = ((float)ux-params.width/2) / (float)params.fx; - const float y = ((float)uy-params.height/2) / (float)params.fy; + const float x = ((float)ux-(float)params.cx) / (float)params.fx; + const float y = ((float)uy-(float)params.cy) / (float)params.fy; shared_lock<shared_mutex> lk(mutex_); const float depth = depth_.at<float>(uy,ux);