19 #ifndef GUIOSGBoundingBoxCalculator_h 20 #define GUIOSGBoundingBoxCalculator_h 29 #include <osg/NodeVisitor> 30 #include <osg/BoundingBox> 31 #include <osg/BoundingSphere> 32 #include <osg/MatrixTransform> 33 #include <osg/Billboard> 47 class GUIOSGBoundingBoxCalculator :
public osg::NodeVisitor {
49 GUIOSGBoundingBoxCalculator() : NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) {
50 myTransformMatrix.makeIdentity();
53 virtual ~GUIOSGBoundingBoxCalculator() {}
55 void apply(osg::Geode& geode) {
56 osg::BoundingBox bbox;
57 for (
int i = 0; i < (int)geode.getNumDrawables(); ++i) {
58 #if OSG_MIN_VERSION_REQUIRED(3,4,0) 59 bbox.expandBy(geode.getDrawable(i)->getBoundingBox());
61 bbox.expandBy(geode.getDrawable(i)->getBound());
64 osg::BoundingBox bboxTrans;
65 for (
int i = 0; i < 8; ++i) {
66 osg::Vec3 xvec = bbox.corner(i) * myTransformMatrix;
67 bboxTrans.expandBy(xvec);
69 myBoundingBox.expandBy(bboxTrans);
73 void apply(osg::MatrixTransform& node) {
74 myTransformMatrix *= node.getMatrix();
78 void apply(osg::Billboard& node) {
82 osg::BoundingBox& getBoundingBox() {
88 osg::BoundingBox myBoundingBox;
89 osg::Matrix myTransformMatrix;