Osg-Osg几何绘制(Qt5.14.2+osgE3.6.5+win10)-No22-GeodeAndGeometry
.pro
1 QT += core gui widgets 2 TARGET = TestOsgQt 3 TEMPLATE = app 4 DEFINES += QT_DEPRECATED_WARNINGS 5 CONFIG += c++11 6 7 QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO 8 QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO 9 10 SOURCES += \ 11 main.cpp 12 13 HEADERS += 14 15 OsgDir = D:\\Gitee\\osg365R 16 CONFIG(release, debug|release) { 17 LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \ 18 -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \ 19 -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \ 20 -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \ 21 -losgWidget 22 } else { 23 LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \ 24 -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \ 25 -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \ 26 -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \ 27 } 28 29 30 INCLUDEPATH += $${OsgDir}/include 31 DEPENDPATH += $${OsgDir}/include
main.cpp
1 #include <osgViewer/Viewer> 2 #include <osgDB/ReadFile> 3 #include <osg/Shape> 4 #include <osg/ShapeDrawable> 5 #include <osg/MatrixTransform> 6 #include <osg/Program> 7 #include <osgDB/ReadFile> 8 #include <osgDB/FileUtils> 9 10 int main() 11 { 12 // 加载牛 13 osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer; 14 osg::ref_ptr<osg::Node> geode = osgDB::readNodeFile("D:/Gitee/OsgTestQt/src/No21-OsgShader/cow.osg");//CreateNode(); 15 osg::Group * root = new osg::Group; 16 root->addChild(geode); 17 // 加载几何 18 osg::ref_ptr<osg::Geode> pGeode = new osg::Geode; 19 osg::ref_ptr<osg::Geometry> pGeometry = new osg::Geometry; 20 osg::ref_ptr<osg::Vec3Array> pVecArray = new osg::Vec3Array; 21 // 压入顶点 22 pVecArray->push_back(osg::Vec3(0, 0, 0)); 23 pVecArray->push_back(osg::Vec3(100, 0, 0)); 24 pVecArray->push_back(osg::Vec3(100, 100, 0)); 25 pVecArray->push_back(osg::Vec3(0, 100, 0)); 26 pVecArray->push_back(osg::Vec3(-100, 100, 0)); 27 pVecArray->push_back(osg::Vec3(-100, 0, 0)); 28 pVecArray->push_back(osg::Vec3(-100, -100, 0)); 29 pVecArray->push_back(osg::Vec3(100, -100, 0)); 30 pVecArray->push_back(osg::Vec3(100, 0, 0)); 31 pGeometry->setVertexArray(pVecArray); 32 //设置顶点数组 33 pGeometry->setVertexArray(pVecArray.get()); 34 //设置顶点组织形式,从哪个点开始,和长度 35 pGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::Mode::LINES_ADJACENCY, 0, pVecArray->size())); 36 //添加可绘制体 37 pGeode->addDrawable(pGeometry); 38 //添加进根节点 39 root->addChild(pGeode); 40 41 viewer->setSceneData(root); 42 viewer->setUpViewInWindow(35, 35, 500, 500); 43 44 return viewer->run(); 45 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我