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

  • 相关阅读:
    截取UIImagePickerController的拍照事件
    Xcode报错:run custom shell script '[cp] copy pods resource
    XCode报错:Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
    Mac环境下实现alias的重命名命令(永久生效)
    Swift 3.0在集合类数据结构上的一些新变化
    iOS几种简单有效的数组排序方法
    二分法查找、快速排序思想与实现
    iOS10 相册权限
    ios应用版本号设置规则
    iOS白名单设置
  • 原文地址:https://www.cnblogs.com/herd/p/11090903.html
Copyright © 2011-2022 走看看