21 #ifndef GUIOSGBoundingBoxCalculator_h 22 #define GUIOSGBoundingBoxCalculator_h 35 #include <osg/NodeVisitor> 36 #include <osg/BoundingBox> 37 #include <osg/BoundingSphere> 38 #include <osg/MatrixTransform> 39 #include <osg/Billboard> 53 class GUIOSGBoundingBoxCalculator :
public osg::NodeVisitor {
55 GUIOSGBoundingBoxCalculator() : NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) {
56 myTransformMatrix.makeIdentity();
59 virtual ~GUIOSGBoundingBoxCalculator() {}
61 void apply(osg::Geode& geode) {
62 osg::BoundingBox bbox;
63 for (
int i = 0; i < (int)geode.getNumDrawables(); ++i) {
64 #if OSG_MIN_VERSION_REQUIRED(3,4,0) 65 bbox.expandBy(geode.getDrawable(i)->getBoundingBox());
67 bbox.expandBy(geode.getDrawable(i)->getBound());
70 osg::BoundingBox bboxTrans;
71 for (
int i = 0; i < 8; ++i) {
72 osg::Vec3 xvec = bbox.corner(i) * myTransformMatrix;
73 bboxTrans.expandBy(xvec);
75 myBoundingBox.expandBy(bboxTrans);
79 void apply(osg::MatrixTransform& node) {
80 myTransformMatrix *= node.getMatrix();
84 void apply(osg::Billboard& node) {
88 osg::BoundingBox& getBoundingBox() {
94 osg::BoundingBox myBoundingBox;
95 osg::Matrix myTransformMatrix;