helpers.cpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007  ** Includes
00008  *****************************************************************************/
00009 
00010 #include "../../include/qglv/gl/headers.hpp"
00011 #include "../../include/qglv/gl/helpers.hpp"
00012 
00013 /*****************************************************************************
00014  ** Namespaces
00015  *****************************************************************************/
00016 
00017 namespace qglv {
00018 
00019 /*****************************************************************************
00020  ** Implementation
00021  *****************************************************************************/
00022 
00023 void moveTo(const Sophus::SE3f& T)
00024 {
00025   Sophus::SE3f pose = T.inverse();
00026   const Eigen::Vector3f & center = pose.translation();
00027   translate(center);
00028   Eigen::Vector3f axis_angle = pose.so3().log();
00029   double angle = axis_angle.norm();
00030   if (angle != 0.)
00031   {
00032     glRotatef(angle * 180.0 / M_PI,
00033               static_cast<float>(axis_angle[0]),
00034               static_cast<float>(axis_angle[1]),
00035               static_cast<float>(axis_angle[2])
00036               );
00037   }
00038 }
00039 
00040 void seeWhatISee(const Sophus::SE3f& pose, const unsigned int& image_width, const unsigned int& image_height,
00041                  const float &focal_length)
00042 {
00043   // https://www.opengl.org/archives/resources/faq/technical/viewing.htm
00044 
00045   float aspect_ratio(static_cast<float>(image_width) / static_cast<float>(image_height));
00046   float fovy = ::atan2f(static_cast<float>(image_height) * 0.5f, focal_length) * 180.0f / M_PI * 2.0f;
00047 
00048   glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
00049   glLoadIdentity();
00050   gluPerspective(fovy, aspect_ratio, 0.1, 10000.0); // angle fov, aspect ratio, nearz, farz
00051 
00052   glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
00053   glLoadIdentity();
00054 
00055   float distance = 10.0;
00056   Eigen::Vector3f up;
00057   up << 0, 1, 0;
00058   Eigen::Vector3f tmp_eye = pose.translation();
00059   Eigen::Vector3f tmp_look = tmp_eye + pose.so3() * Eigen::Vector3f(0, 0, distance);
00060   Eigen::Vector3f tup = pose.so3() * up;
00061   gluLookAt(tmp_eye.x(), tmp_eye.y(), tmp_eye.z(), tmp_look.x(), tmp_look.y(), tmp_look.z(), tup.x(), tup.y(), tup.z());
00062 }
00063 
00064 } // namespace qglv


qglv_opengl
Author(s): Daniel Stonier
autogenerated on Sat Jun 18 2016 08:19:28