/* -*-c++-*- OpenSceneGraph Cookbook
* Chapter 2 Recipe 3
* Author: Wang Rui <wangray84 at gmail dot com>
*/
#include <osg/ComputeBoundsVisitor>
#include <osg/ShapeDrawable>
#include <osg/AnimationPath>
#include <osg/MatrixTransform>
#include <osg/PolygonMode>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/StateSet>
#include <osg/LineWidth>
osg::ref_ptr<osg::Geode> createboundingbox(osg::Node* node)
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ComputeBoundsVisitor boundvisitor ;
node->accept(boundvisitor);
osg::BoundingBox bb = boundvisitor.getBoundingBox();
float lengthx = bb.xMax()-bb.xMin();
float lengthy = bb.yMax()-bb.yMin();
float lengthz = bb.zMax()-bb.zMin();
osg::Vec3 center= osg::Vec3((bb.xMax()+bb.xMin())/2,(bb.yMax()+bb.yMin())/2,(bb.zMax()+bb.zMin())/2);
osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeD
绘制模型最小包围盒轮廓
最新推荐文章于 2024-07-10 10:42:59 发布
该博客介绍了一种方法,通过OpenSceneGraph库来创建并显示一个3D模型的最小包围盒轮廓。首先,利用ComputeBoundsVisitor计算模型的边界框,然后创建一个Box对象,并设置其为线框模式以突出显示轮廓。最后,在场景中添加这个包围盒,以便在视图中看到模型的边界。

最低0.47元/天 解锁文章
1840

被折叠的 条评论
为什么被折叠?



