Changeset 347 for trunk/avango-osg/python/avango/osg/OSGNode.cpp
- Timestamp:
- 03/12/10 09:55:04 (2 years ago)
- File:
-
- 1 edited
-
trunk/avango-osg/python/avango/osg/OSGNode.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/avango-osg/python/avango/osg/OSGNode.cpp
r1 r347 29 29 #include "OSGNode.h" 30 30 31 #include <osg/NodeVisitor> 32 #include <osg/BoundingBox> 33 #include <osg/BoundingSphere> 34 #include <osg/MatrixTransform> 35 #include <osg/Billboard> 36 37 31 38 using namespace boost::python; 32 39 using namespace av::python; … … 43 50 } 44 51 52 53 namespace { 54 class CalculateBoundingBox : public ::osg::NodeVisitor 55 { 56 public: 57 CalculateBoundingBox() : 58 NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) 59 { 60 m_transformMatrix.makeIdentity(); 61 } 62 63 virtual ~CalculateBoundingBox() 64 { 65 } 66 67 virtual 68 void apply(::osg::Geode &geode) 69 { 70 ::osg::BoundingBox bbox; 71 for (unsigned int i = 0; i < geode.getNumDrawables(); ++i) 72 { 73 bbox.expandBy(geode.getDrawable(i)->getBound()); 74 } 75 ::osg::BoundingBox bboxTrans; 76 for (unsigned int i = 0; i < 8; ++i) 77 { 78 ::osg::Vec3 xvec = bbox.corner(i) * m_transformMatrix; 79 bboxTrans.expandBy(xvec); 80 } 81 m_boundingBox.expandBy(bboxTrans); 82 traverse(geode); 83 } 84 85 virtual 86 void apply(::osg::MatrixTransform &node) 87 { 88 m_transformMatrix *= node.getMatrix(); 89 traverse(node); 90 } 91 92 virtual 93 void apply(::osg::Billboard &node) 94 { 95 traverse(node); 96 } 97 98 ::osg::BoundingBox &getBoundBox() 99 { 100 return m_boundingBox; 101 } 102 103 protected: 104 ::osg::BoundingBox m_boundingBox; // the overall resultant bounding box 105 ::osg::Matrix m_transformMatrix; // the current transform matrix 106 }; 107 108 109 osg::BoundingBox CalcBoundingBox(av::osg::Node* node) 110 { 111 CalculateBoundingBox bbox; 112 node->getOsgNode()->accept( bbox ); 113 return bbox.getBoundBox(); 114 } 115 116 } 117 118 119 120 45 121 void init_OSGNode(void) 46 122 { … … 52 128 .def("get_absolute_transform", &av::osg::Node::getAbsoluteTransform) 53 129 ; 130 131 def("calc_bounding_box", CalcBoundingBox); 54 132 }
Note: See TracChangeset
for help on using the changeset viewer.
