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 (
unsigned int i = 0; i < geode.getNumDrawables(); ++i) {
65 bbox.expandBy(geode.getDrawable(i)->getBound());
67 osg::BoundingBox bboxTrans;
68 for (
unsigned int i = 0; i < 8; ++i) {
69 osg::Vec3 xvec = bbox.corner(i) * myTransformMatrix;
70 bboxTrans.expandBy(xvec);
72 myBoundingBox.expandBy(bboxTrans);
76 void apply(osg::MatrixTransform& node) {
77 myTransformMatrix *= node.getMatrix();
81 void apply(osg::Billboard& node) {
85 osg::BoundingBox& getBoundingBox() {
91 osg::BoundingBox myBoundingBox;
92 osg::Matrix myTransformMatrix;