Skip to content
Snippets Groups Projects
Commit 0fd7f78a authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Keyboard camera movement control

parent 8bd48cd0
No related branches found
No related tags found
No related merge requests found
Pipeline #10545 failed
...@@ -26,30 +26,41 @@ Display::Display(nlohmann::json &config) : config_(config) { ...@@ -26,30 +26,41 @@ Display::Display(nlohmann::json &config) : config_(config) {
pclviz_->registerKeyboardCallback ( pclviz_->registerKeyboardCallback (
[](const pcl::visualization::KeyboardEvent &event, void* viewer_void) { [](const pcl::visualization::KeyboardEvent &event, void* viewer_void) {
auto viewer = *static_cast<pcl::visualization::PCLVisualizer::Ptr*>(viewer_void); auto viewer = *static_cast<pcl::visualization::PCLVisualizer::Ptr*>(viewer_void);
LOG(INFO) << "Key " << event.getKeySym ();
pcl::visualization::Camera cam; pcl::visualization::Camera cam;
viewer->getCameraParameters(cam); viewer->getCameraParameters(cam);
Eigen::Vector3f pos(cam.pos[0], cam.pos[1], cam.pos[2]); Eigen::Vector3f pos(cam.pos[0], cam.pos[1], cam.pos[2]);
Eigen::Vector3f dir = Eigen::Vector3f(cam.focal[0], cam.focal[1], cam.focal[2]) - pos; //.normalize(); Eigen::Vector3f focal(cam.focal[0], cam.focal[1], cam.focal[2]);
Eigen::Vector3f dir = focal - pos; //.normalize();
dir.normalize(); dir.normalize();
const float speed = 40.0f;
if (event.getKeySym() == "Up") { if (event.getKeySym() == "Up") {
pos += 20.0f*dir; pos += speed*dir;
focal += speed*dir;
} else if (event.getKeySym() == "Down") { } else if (event.getKeySym() == "Down") {
pos -= 20.0f*dir; pos -= speed*dir;
focal -= speed*dir;
} else if (event.getKeySym() == "Left") { } else if (event.getKeySym() == "Left") {
// TODO Rotate -90 Eigen::Matrix3f m = Eigen::AngleAxisf(-0.5f*M_PI, Eigen::Vector3f::UnitY()).toRotationMatrix();
pos += 20.0f*dir; dir = m*dir;
pos += speed*dir;
focal += speed*dir;
} else if (event.getKeySym() == "Right") { } else if (event.getKeySym() == "Right") {
// TODO Rotate 90 Eigen::Matrix3f m = Eigen::AngleAxisf(0.5f*M_PI, Eigen::Vector3f::UnitY()).toRotationMatrix();
pos += 20.0f*dir; dir = m*dir;
pos += speed*dir;
focal += speed*dir;
} }
cam.pos[0] = pos[0]; cam.pos[0] = pos[0];
cam.pos[1] = pos[1]; cam.pos[1] = pos[1];
cam.pos[2] = pos[2]; cam.pos[2] = pos[2];
cam.focal[0] = focal[0];
cam.focal[1] = focal[1];
cam.focal[2] = focal[2];
viewer->setCameraParameters(cam); viewer->setCameraParameters(cam);
}, (void*)&pclviz_); }, (void*)&pclviz_);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment