]> git.mxchange.org Git - simgear.git/blob - simgear/scene/bvh/BVHLineSegmentVisitor.hxx
Initial commit of the bounding volume tree implementation.
[simgear.git] / simgear / scene / bvh / BVHLineSegmentVisitor.hxx
1 // Copyright (C) 2008 - 2009  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifndef BVHLineSegmentVisitor_hxx
19 #define BVHLineSegmentVisitor_hxx
20
21 #include <simgear/math/SGGeometry.hxx>
22 #include <simgear/structure/SGSharedPtr.hxx>
23 #include <simgear/scene/material/mat.hxx>
24
25 #include "BVHVisitor.hxx"
26
27 namespace simgear {
28
29 class BVHLineSegmentVisitor : public BVHVisitor {
30 public:
31     BVHLineSegmentVisitor(const SGLineSegmentd& lineSegment,
32                           const double& t = 0) :
33         _lineSegment(lineSegment),
34         _time(t),
35         _material(0),
36         _haveHit(false)
37     { }
38     virtual ~BVHLineSegmentVisitor()
39     { }
40     
41     bool empty() const
42     { return !_haveHit; }
43     
44     const SGLineSegmentd& getLineSegment() const
45     { return _lineSegment; }
46     
47     SGVec3d getPoint() const
48     { return _lineSegment.getEnd(); }
49     const SGVec3d& getNormal() const
50     { return _normal; }
51     const SGVec3d& getLinearVelocity() const
52     { return _linearVelocity; }
53     const SGVec3d& getAngularVelocity() const
54     { return _angularVelocity; }
55     const SGMaterial* getMaterial() const
56     { return _material; }
57
58     virtual void apply(BVHGroup& group);
59     virtual void apply(BVHTransform& transform);
60     virtual void apply(BVHMotionTransform& transform);
61     virtual void apply(BVHLineGeometry&);
62     virtual void apply(BVHStaticGeometry& node);
63     
64     virtual void apply(const BVHStaticBinary&, const BVHStaticData&);
65     virtual void apply(const BVHStaticLeaf&, const BVHStaticData&);
66     virtual void apply(const BVHStaticTriangle&, const BVHStaticData&);
67     
68 protected:
69     bool setLineSegmentEnd(const SGVec3d& end)
70     {
71         // Ok, you need to make sure that the new end is in the previous
72         // direction and that the line segment is not enlarged by that call.
73 #ifndef _NDEBUG
74         // FIXME insert code to check this...
75 #endif
76         _lineSegment.set(_lineSegment.getStart(), end);
77     }
78     
79 private:
80     SGLineSegmentd _lineSegment;
81     double _time;
82     
83     // belongs in a derived class
84     SGVec3d _normal;
85     SGVec3d _linearVelocity;
86     SGVec3d _angularVelocity;
87     const SGMaterial* _material;
88     
89     bool _haveHit;
90 };
91
92 }
93
94 #endif