pangolin简单学习

0.1. 资料

泡泡机器人

github example

opengl中摄像机的位置,观察的方向

gluLookAt函数

pangolin简单学习_第1张图片

0.2. 使用说明

使用这个gluLookAt矩阵坐标观察矩阵可以很高效地把所有世界坐标变换为观察坐标LookAt矩阵

 
  1. find_package(Pangolin REQUIRED)

  2. include_directories(${Pangolin_INCLUDE_DIRS})

  3.  
  4. target_link_libraries(pangolin_test ${Pangolin_LIBRARIES})

Github 下有个example有一些例子,简单的参照着写,复杂的估计需要查opengl.

0.3. HelloPangolin

 
  1. #include

  2. #include

  3.  
  4. int main(int argc, char **argv)

  5. {

  6. //创建一个窗口

  7. pangolin::CreateWindowAndBind("Main",640,480);

  8. //启动深度测试

  9. glEnable(GL_DEPTH_TEST);

  10.  
  11. // Define Projection and initial ModelView matrix

  12. pangolin::OpenGlRenderState s_cam(

  13. pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),

  14. //对应的是gluLookAt,摄像机位置,参考点位置,up vector(上向量)

  15. pangolin::ModelViewLookAt(0,-10,0.1,0,0,0,pangolin::AxisNegY)

  16. );

  17.  
  18. // Create Interactive View in window

  19. pangolin::Handler3D handler(s_cam);

  20. //setBounds 跟opengl的viewport 有关

  21. //看SimpleDisplay中边界的设置就知道

  22. pangolin::View &d_cam = pangolin::CreateDisplay().SetBounds(0.0,1.0,0.0,1.0,-640.0f/480.0f)

  23. .SetHandler(&handler);

  24.  
  25. while(!pangolin::ShouldQuit())

  26. {

  27. // Clear screen and activate view to render into

  28. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  29. d_cam.Activate(s_cam);

  30.  
  31. // Render OpenGL Cube

  32. // pangolin::glDrawColouredCube();\

  33. //坐标轴的创建

  34. pangolin::glDrawAxis(3);

  35.  
  36. //点的创建

  37. glPointSize(10.0f);

  38. glBegin(GL_POINTS);

  39. glColor3f(1.0,1.0,1.0);

  40. glVertex3f(0.0f,0.0f,0.0f);

  41. glVertex3f(1,0,0);

  42. glVertex3f(0,2,0);

  43. glEnd();

  44.  
  45. //把下面的点都做一次旋转变换

  46. glPushMatrix();

  47. //col major

  48. std::vector Twc = {1,0,0,0, 0,1,0,0 , 0,0,1,0 ,0,0,5,1};

  49. glMultMatrixf(Twc.data());

  50.  
  51. //直线的创建

  52. const float w = 2;

  53. const float h = w*0.75;

  54. const float z = w*0.6;

  55. glLineWidth(2);

  56. glColor3f(1.0,0,0);

  57. glBegin(GL_LINES);

  58.  
  59. glVertex3f(0,0,0);

  60. glVertex3f(w,h,z);

  61. glVertex3f(0,0,0);

  62. glVertex3f(w,-h,z);

  63. glVertex3f(0,0,0);

  64. glVertex3f(-w,-h,z);

  65. glVertex3f(0,0,0);

  66. glVertex3f(-w,h,z);

  67. glVertex3f(w,h,z);

  68. glVertex3f(-w,h,z);

  69. glVertex3f(-w,h,z);

  70. glVertex3f(-w,-h,z);

  71. glVertex3f(-w,-h,z);

  72. glVertex3f(w,-h,z);

  73. glVertex3f(w,-h,z);

  74. glVertex3f(w,h,z);

  75. glEnd();

  76.  
  77. glPopMatrix();

  78.  
  79. // Swap frames and Process Events

  80. pangolin::FinishFrame();

  81. }

  82.  
  83. return 0;

  84.  
  85. }

0.4. Plot data with ros

参照SimplePlot, !pangolin::ShouldQuit()换成ros::ok(),就可以

参照SimpleDisplay, 可以做出选项配置

你可能感兴趣的:(slam)