00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef BVHBoundingBoxVisitor_hxx
00019 #define BVHBoundingBoxVisitor_hxx
00020
00021 #include <simgear/math/SGGeometry.hxx>
00022
00023 #include "BVHVisitor.hxx"
00024 #include "BVHNode.hxx"
00025 #include "BVHGroup.hxx"
00026 #include "BVHTransform.hxx"
00027 #include "BVHMotionTransform.hxx"
00028 #include "BVHLineGeometry.hxx"
00029
00030 #include "BVHStaticData.hxx"
00031
00032 #include "BVHStaticNode.hxx"
00033 #include "BVHStaticTriangle.hxx"
00034 #include "BVHStaticBinary.hxx"
00035 #include "BVHStaticGeometry.hxx"
00036
00037 namespace simgear {
00038
00039 class BVHBoundingBoxVisitor : public BVHVisitor {
00040 public:
00041 virtual ~BVHBoundingBoxVisitor() {}
00042
00043 void clear()
00044 { _box.clear(); }
00045
00046 virtual void apply(BVHGroup& node)
00047 { expandBy(node.getBoundingSphere()); }
00048 virtual void apply(BVHTransform& node)
00049 { expandBy(node.getBoundingSphere()); }
00050 virtual void apply(BVHMotionTransform& node)
00051 { expandBy(node.getBoundingSphere()); }
00052 virtual void apply(BVHLineGeometry& node)
00053 { expandBy(node.getBoundingSphere()); }
00054 virtual void apply(BVHStaticGeometry& node)
00055 { expandBy(node.getBoundingSphere()); }
00056
00057 virtual void apply(const BVHStaticBinary& node, const BVHStaticData& data)
00058 { expandBy(node.getBoundingBox()); }
00059 virtual void apply(const BVHStaticTriangle& node, const BVHStaticData& data)
00060 { expandBy(node.computeBoundingBox(data)); }
00061
00062 const SGBoxf& getBox() const
00063 { return _box; }
00064
00065 private:
00066 void expandBy(const SGSphered& sphere)
00067 {
00068 SGVec3f v0(sphere.getCenter() - sphere.getRadius()*SGVec3d(1, 1, 1));
00069 SGVec3f v1(sphere.getCenter() + sphere.getRadius()*SGVec3d(1, 1, 1));
00070 _box.expandBy(SGBoxf(v0, v1));
00071 }
00072 void expandBy(const SGBoxf& box)
00073 { _box.expandBy(box); }
00074
00075 SGBoxf _box;
00076 };
00077
00078 }
00079
00080 #endif