0.1. 資料 "泡泡機器人" "github example" "opengl中攝像機的位置,觀察的方向" "gluLookAt函數" 0.2. 使用說明 使用這個gluLookAt矩陣坐標觀察矩陣可以很高效地把所有世界坐標變換為觀察坐標LookAt矩陣 Github 下有個example有一些例 ...
0.1. 資料
0.2. 使用說明
使用這個gluLookAt矩陣坐標觀察矩陣可以很高效地把所有世界坐標變換為觀察坐標LookAt矩陣
find_package(Pangolin REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
target_link_libraries(pangolin_test ${Pangolin_LIBRARIES})
Github 下有個example有一些例子,簡單的參照著寫,複雜的估計需要查opengl.
0.3. HelloPangolin
#include <iostream>
#include <pangolin/pangolin.h>
int main(int argc, char **argv)
{
//創建一個視窗
pangolin::CreateWindowAndBind("Main",640,480);
//啟動深度測試
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
//對應的是gluLookAt,攝像機位置,參考點位置,up vector(上向量)
pangolin::ModelViewLookAt(0,-10,0.1,0,0,0,pangolin::AxisNegY)
);
// Create Interactive View in window
pangolin::Handler3D handler(s_cam);
//setBounds 跟opengl的viewport 有關
//看SimpleDisplay中邊界的設置就知道
pangolin::View &d_cam = pangolin::CreateDisplay().SetBounds(0.0,1.0,0.0,1.0,-640.0f/480.0f)
.SetHandler(&handler);
while(!pangolin::ShouldQuit())
{
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
// Render OpenGL Cube
// pangolin::glDrawColouredCube();\
//坐標軸的創建
pangolin::glDrawAxis(3);
//點的創建
glPointSize(10.0f);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,1.0);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1,0,0);
glVertex3f(0,2,0);
glEnd();
//把下麵的點都做一次旋轉變換
glPushMatrix();
//col major
std::vector<GLfloat > Twc = {1,0,0,0, 0,1,0,0 , 0,0,1,0 ,0,0,5,1};
glMultMatrixf(Twc.data());
//直線的創建
const float w = 2;
const float h = w*0.75;
const float z = w*0.6;
glLineWidth(2);
glColor3f(1.0,0,0);
glBegin(GL_LINES);
glVertex3f(0,0,0);
glVertex3f(w,h,z);
glVertex3f(0,0,0);
glVertex3f(w,-h,z);
glVertex3f(0,0,0);
glVertex3f(-w,-h,z);
glVertex3f(0,0,0);
glVertex3f(-w,h,z);
glVertex3f(w,h,z);
glVertex3f(-w,h,z);
glVertex3f(-w,h,z);
glVertex3f(-w,-h,z);
glVertex3f(-w,-h,z);
glVertex3f(w,-h,z);
glVertex3f(w,-h,z);
glVertex3f(w,h,z);
glEnd();
glPopMatrix();
// Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}
0.4. Plot data with ros
參照SimplePlot, !pangolin::ShouldQuit()
換成ros::ok()
,就可以
參照SimpleDisplay, 可以做出選項配置