22 #ifndef GUIOSGBoundingBoxCalculator_h 23 #define GUIOSGBoundingBoxCalculator_h 36 #include <osg/NodeVisitor> 37 #include <osg/BoundingBox> 38 #include <osg/BoundingSphere> 39 #include <osg/MatrixTransform> 40 #include <osg/Billboard> 54 class GUIOSGBoundingBoxCalculator :
public osg::NodeVisitor {
56 GUIOSGBoundingBoxCalculator() : NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) {
57 myTransformMatrix.makeIdentity();
60 virtual ~GUIOSGBoundingBoxCalculator() {}
62 void apply(osg::Geode& geode) {
63 osg::BoundingBox bbox;
64 for (
int i = 0; i < (int)geode.getNumDrawables(); ++i) {
65 #if OSG_MIN_VERSION_REQUIRED(3,4,0) 66 bbox.expandBy(geode.getDrawable(i)->getBoundingBox());
68 bbox.expandBy(geode.getDrawable(i)->getBound());
71 osg::BoundingBox bboxTrans;
72 for (
int i = 0; i < 8; ++i) {
73 osg::Vec3 xvec = bbox.corner(i) * myTransformMatrix;
74 bboxTrans.expandBy(xvec);
76 myBoundingBox.expandBy(bboxTrans);
80 void apply(osg::MatrixTransform& node) {
81 myTransformMatrix *= node.getMatrix();
85 void apply(osg::Billboard& node) {
89 osg::BoundingBox& getBoundingBox() {
95 osg::BoundingBox myBoundingBox;
96 osg::Matrix myTransformMatrix;