zoukankan      html  css  js  c++  java
  • osg osgUtil::LineSegmentIntersector

    #ifdef _WIN32
    #include <Windows.h>
    #endif // _WIN32
    
    #include <osgViewer/Viewer>
    #include <osgViewer/ViewerEventHandlers> 
    #include <osgViewer/CompositeViewer> 
    #include <osgDB/ReadFile>
    #include <osg/Geode>
    #include <osg/Node>
    #include <osgGA/TrackballManipulator>
    #include <osg/GraphicsContext>
    #include <osg/ShapeDrawable>
    #include <osg/Material>
    #include <osg/Image>
    #include <osg/Texture2D>
    #include <osg/TexEnv>
    #include <osg/TexGen>
    #include <osg/MatrixTransform>
    #include <osg/PositionAttitudeTransform>
    #include <osg/AnimationPath>
    #include <osg/Matrixd>
    
    #include <osgGA/GUIEventHandler>
    #include <osgGA/CameraManipulator>
    #include <osgGA/StandardManipulator>
    #include <osgGA/OrbitManipulator>
    #include <osgGA/TrackballManipulator>
    #include <osgUtil/IntersectionVisitor>
    #include <osgUtil/LineSegmentIntersector>
    
    
    //创建盒子
    osg::ref_ptr<osg::Geode> createBox()
    {
        osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
        geode1->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0,0.0,0.0),10.0,8.0,6.0)));
        geode1->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0, 0.0, 0.0), 0.1, 0.1, 20)));
        return geode1;
    }
    
    int main()
    {
        osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
        osg::ref_ptr<osg::Group> group1 = new osg::Group;
        //osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\osg\build1.OSGB");
        //group1->addChild(node1.get());
    
        osg::ref_ptr<osgUtil::LineSegmentIntersector> lineSegmentIntesector = new osgUtil::LineSegmentIntersector(osg::Vec3(0,0,15),osg::Vec3(0,0,-15));
        osg::ref_ptr<osgUtil::IntersectionVisitor> intersectionVisitor1 = new osgUtil::IntersectionVisitor(lineSegmentIntesector);
    
    
        group1->addChild(createBox());
        group1->accept(*intersectionVisitor1.get());
    
        osgUtil::LineSegmentIntersector::Intersections intersections;
        //输出交点
        if (lineSegmentIntesector->containsIntersections())
        {
            intersections = lineSegmentIntesector->getIntersections();
            osgUtil::LineSegmentIntersector::Intersections::iterator iter;
            for (iter = intersections.begin(); iter != intersections.end(); ++iter)
            {
                std::cout << "x:"<<iter->getWorldIntersectPoint().x() << "    y:" << iter->getWorldIntersectPoint().y() << "    z:" << iter->getWorldIntersectPoint().z() << std::endl;
            }
        }
    
    
        viewer1->setSceneData(group1.get());
        viewer1->setUpViewInWindow(200, 200, 800, 600, 0);
    
        return viewer1->run();
    }

  • 相关阅读:
    freebsd ports update url
    Cisco交换机里IP和MAC地址互查找出对应端口
    实现不同vlan间的相互通信方法一:单臂路由
    文件共享③Samba实例
    RHEL6基础四十九之RHEL文件(夹)权限进阶篇
    windows下查找指定端口被哪个程序占用
    DNSmasq – 配置DNS和DHCP
    dnsmasq多vlan配置
    dnsmasq.conf 配置
    windows2003 DHCP中批处理绑定IP与MAC
  • 原文地址:https://www.cnblogs.com/herd/p/11090903.html
Copyright © 2011-2022 走看看