日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

osg::ComputeBoundsVisitor用法(一)

發布時間:2023/12/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 osg::ComputeBoundsVisitor用法(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

osg::ComputeBoundsVisitor用于獲取模型或繪制幾何體的最小包圍盒。如下代碼:

#include<osg/Geometry> #include<osg/Geode> #include<osgViewer/Viewer> #include<osgViewer/ViewerEventHandlers> #include <osg/Node> #include <osg/Geode> #include <osg/Group> #include <osgViewer/Viewer> #include <osgDB/ReadFile> #include <osgDB/WriteFile> #include<osg/DrawPixels> #include<osg/PositionAttitudeTransform> #include<osg/computeBoundsVisitor> #include<osg/MatrixTransform> #include<osg/ShapeDrawable> #include<osg/Shape> #include<osg/PolygonMode> int main(int argc, char *argv[]) {osg::ref_ptr<osgViewer::Viewer> spViewer = new osgViewer::Viewer();osg::ref_ptr<osg::Group> spGroup = new osg::Group();osg::ref_ptr<osg::Node> spNode = osgDB::readNodeFile("cow.osg");spGroup->addChild(spNode);spViewer->setSceneData(spGroup);osg::ComputeBoundsVisitor boundsVist;spNode->accept(boundsVist);osg::BoundingBox box = boundsVist.getBoundingBox();//OSG_NOTIFY(osg::ALWAYS) << "bound info:" << std::endl;;osg::notify(osg::ALWAYS) << "bouding box info" << std::endl;osg::notify(osg::ALWAYS) << "center x:" << box.center().x() << std::endl;osg::notify(osg::ALWAYS) << "center y:"<< box.center().y() << std::endl;;osg::notify(osg::ALWAYS) << "center z:" << box.center().z() << std::endl;;osg::notify(osg::ALWAYS) << "x max:" << box.xMax() << std::endl;osg::notify(osg::ALWAYS) << "x min:" << box.xMin() << std::endl;osg::notify(osg::ALWAYS) << "y max:" << box.yMax() << std::endl;osg::notify(osg::ALWAYS) << "y min:" << box.yMin() << std::endl;osg::notify(osg::ALWAYS) << "z max:" << box.zMax() << std::endl;osg::notify(osg::ALWAYS) << "z min:" << box.zMin() << std::endl;// 畫個外框osg::ref_ptr<osg::Geode>spGeodeBox = new osg::Geode();spGeodeBox->addDrawable(new osg::ShapeDrawable(new osg::Box(box.center(), box.xMax() - box.xMin(), box.yMax() - box.yMin(), box.zMax() - box.zMin())));osg::ref_ptr<osg::StateSet> spGeodeStateSet = spGeodeBox->getOrCreateStateSet();// 采用線框模式,以便能看見里面的模型即cow.osgosg::ref_ptr<osg::PolygonMode> spGeodePolygon = new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);spGeodeStateSet->setAttribute(spGeodePolygon);spGroup->addChild(spGeodeBox);spViewer->setUpViewInWindow(10, 10, 800, 600);spViewer->realize();spViewer->run();return 0; }

獲取cow.osg模型最小包圍盒的中心點及x、y、z坐標的最大、最小值,輸入如下:

注意:上面的osg::notify(osg::ALWAYS)輸出信息時,后面要加回車換行,否則日志信息只輸入到緩沖區,而不會立即輸出到控制臺

模型顯示效果如下:

?

?

?

?

總結

以上是生活随笔為你收集整理的osg::ComputeBoundsVisitor用法(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。