Pangolin使用——基础代码

Pangolin使用——基础代码

    #include<iostream>
    #include<pangolin/pangolin.h>
    int main(int argc,char **argv)
    {
        //新建一个窗口
        pangolin::CreateWindowAndBind("Main",640,480);
        //启动深度测试
        glEnable(GL_DEPTH_TEST);
        //定义投影和初始模型视图矩阵 
        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));
        //在窗口中创建交互式视图
        pangolin::Handler3D handler(s_cam);
        pangolin::View &d_cam = pangolin::CreateDisplay()
                                .SetBounds(0.0,1.0,0.0,1.0,-640.0f/480.0f)
                                .SetHandler(&handler);
        while(!pangolin::ShouldQuit())
        {
            //清除屏幕并激活要渲染到的视图 
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            d_cam.Activate(s_cam);
            pangolin::glDrawColouredCube();//画三维方块
            pangolin::glDrawAxis(3);//三维坐标轴,红——x轴,绿——y轴,蓝——z轴
            //glBegin(形状);    
    	//glVertex(顶点1);    
    	//glVertex(顶点2);    
    	   //……  
            //glEnd();
            //结束
            pangolin::FinishFrame();
        }
    }

形状可以设为:

GL_POINTS:点
GL_LINES:线
GL_LINE_STRIP:折线
GL_LINE_LOOP:封闭折线
GL_TRIANGLES:三角形
GL_POLYGON:多边形

glBegin()和glEnd()之间可以调用的函数有:

glVertex()设置顶点坐标
glColor()设置当前颜色
glIndex()设置当前颜色表
glNormal()设置法向坐标
glEvalCoord()产生坐标
glCallList(),glCallLists()执行显示列表
glTexCoord()设置纹理坐标
glEdgeFlag()控制边界绘制
glMaterial()设置材质

例如:

     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();

例如:

//新建一个窗口
    pangolin::CreateWindowAndBind("Main",640,480);
    //启动深度测试
    glEnable(GL_DEPTH_TEST);
    //定义投影和初始模型视图矩阵
    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));
    //在窗口中创建交互式视图
    pangolin::Handler3D handler(s_cam);
    pangolin::View &d_cam = pangolin::CreateDisplay()
            .SetBounds(0.0,1.0,0.0,1.0,-640.0f/480.0f)
            .SetHandler(&handler);

    while(!pangolin::ShouldQuit())
    {
        //清除屏幕并激活要渲染到的视图
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        d_cam.Activate(s_cam);
        pangolin::glDrawColouredCube();//画三维方块
        pangolin::glDrawAxis(2);//三维坐标轴,红——x轴,绿——y轴,蓝——z轴
        glBegin(GL_LINE_STRIP);

        for (i = 0; i < map_des1.size() ; ++i) {
            glVertex3d(map_des1[i][0],map_des1[i][1],0);
        }

        glEnd();

        glLineWidth(14);
        glBegin(GL_LINE_STRIP);
        glColor3f(0.0f, 1.0f, 0.0f);
        for (i = 0; i < map_des2.size() ; ++i) {
            glVertex3d(map_des2[i][0],map_des2[i][1],2);
        }
        glEnd();

        glPointSize(3);
        glBegin(GL_POINTS);
        glColor3f(1.0f, 0.0f, 0.0f);
        for (i = 0; i < map_des3.size() ; ++i) {
            glVertex3d(map_des3[i][0],map_des3[i][1],4);
        }
        glEnd();


        //结束
        pangolin::FinishFrame();
    }
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页