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

  • 相关阅读:
    知名网站的技术发展历程
    自己的代码仓库源码
    重构着讲解设计原则与模式——从DIP中“倒置”的含义说接口的正确使用
    jQuery Colorbox插件
    测试是否支持DOMAttrModified
    python(贪吃蛇)
    界面简洁,无广告,无插件,无网络却功能强播放器
    Asp.Net MVC 4 Web API
    理解MVC底层运行机制
    BS单点登陆(SSO)实现代码展示
  • 原文地址:https://www.cnblogs.com/herd/p/11090903.html
Copyright © 2011-2022 走看看