]> git.mxchange.org Git - simgear.git/blob - simgear/bvh/BVHLineSegmentVisitor.hxx
canvas::Layout: support for contents margins.
[simgear.git] / simgear / 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
24 #include "BVHVisitor.hxx"
25 #include "BVHNode.hxx"
26
27 namespace simgear {
28
29 class BVHMaterial;
30
31 class BVHLineSegmentVisitor : public BVHVisitor {
32 public:
33     BVHLineSegmentVisitor(const SGLineSegmentd& lineSegment,
34                           const double& t = 0) :
35         _lineSegment(lineSegment),
36         _time(t),
37         _material(0),
38         _id(0),
39         _haveHit(false)
40     { }
41     virtual ~BVHLineSegmentVisitor()
42     { }
43     
44     bool empty() const
45     { return !_haveHit; }
46     
47     const SGLineSegmentd& getLineSegment() const
48     { return _lineSegment; }
49     
50     SGVec3d getPoint() const
51     { return _lineSegment.getEnd(); }
52     const SGVec3d& getNormal() const
53     { return _normal; }
54     const SGVec3d& getLinearVelocity() const
55     { return _linearVelocity; }
56     const SGVec3d& getAngularVelocity() const
57     { return _angularVelocity; }
58     const BVHMaterial* getMaterial() const
59     { return _material; }
60     BVHNode::Id getId() const
61     { return _id; }
62
63     virtual void apply(BVHGroup& group);
64     virtual void apply(BVHPageNode& node);
65     virtual void apply(BVHTransform& transform);
66     virtual void apply(BVHMotionTransform& transform);
67     virtual void apply(BVHLineGeometry&);
68     virtual void apply(BVHStaticGeometry& node);
69     
70     virtual void apply(const BVHStaticBinary&, const BVHStaticData&);
71     virtual void apply(const BVHStaticTriangle&, const BVHStaticData&);
72     
73 protected:
74     void setLineSegmentEnd(const SGVec3d& end)
75     {
76         // Ok, you need to make sure that the new end is in the previous
77         // direction and that the line segment is not enlarged by that call.
78 #ifndef _NDEBUG
79         // FIXME insert code to check this...
80 #endif
81         _lineSegment.set(_lineSegment.getStart(), end);
82     }
83     
84 private:
85     SGLineSegmentd _lineSegment;
86     double _time;
87     
88     // belongs in a derived class
89     SGVec3d _normal;
90     SGVec3d _linearVelocity;
91     SGVec3d _angularVelocity;
92     const BVHMaterial* _material;
93     BVHNode::Id _id;
94     
95     bool _haveHit;
96 };
97
98 }
99
100 #endif