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