]> git.mxchange.org Git - flightgear.git/blob - src/FDM/groundcache.hxx
1db7fb0b628fefca1230fdef5c93dceff07b78f2
[flightgear.git] / src / FDM / groundcache.hxx
1 // groundcache.hxx -- carries a small subset of the scenegraph near the vehicle
2 //
3 // Written by Mathias Froehlich, started Nov 2004.
4 //
5 // Copyright (C) 2004  Mathias Froehlich - Mathias.Froehlich@web.de
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifndef _GROUNDCACHE_HXX
24 #define _GROUNDCACHE_HXX
25
26 #include <osg/Group>
27 #include <osg/ref_ptr>
28
29 #include <simgear/compiler.h>
30 #include <simgear/constants.h>
31 #include <simgear/math/SGMath.hxx>
32 #include <simgear/math/SGGeometry.hxx>
33 #include <simgear/scene/bvh/BVHNode.hxx>
34 #include <simgear/structure/SGSharedPtr.hxx>
35
36 class SGMaterial;
37 namespace simgear {
38 class BVHLineGeometry;
39 }
40
41 class FGGroundCache {
42 public:
43     FGGroundCache();
44     ~FGGroundCache();
45
46     //////////////////////////////////////////////////////////////////////////
47     // Ground handling routines
48     //////////////////////////////////////////////////////////////////////////
49
50     // Prepare the ground cache for the wgs84 position pt_*.
51     // That is take all vertices in the ball with radius rad around the
52     // position given by the pt_* and store them in a local scene graph.
53     bool prepare_ground_cache(double startSimTime, double endSimTime,
54                               const SGVec3d& pt, double rad);
55
56     // Returns true if the cache is valid.
57     // Also the reference time, point and radius values where the cache
58     // is valid for are returned.
59     bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
60
61     // Returns the unit down vector at the ground cache
62     const SGVec3d& get_down() const
63     { return down; }
64
65     double get_cache_time_offset() const
66     { return cache_time_offset; }
67     void set_cache_time_offset(double time_offset)
68     { cache_time_offset = time_offset; }
69
70     bool get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel,
71                   SGVec3d& angularVel, simgear::BVHNode::Id id);
72
73     // Return the nearest catapult to the given point
74     // pt in wgs84 coordinates.
75     double get_cat(double t, const SGVec3d& pt,
76                    SGVec3d end[2], SGVec3d vel[2]);
77   
78
79     // Return the altitude above ground below the wgs84 point pt
80     // Search for highest triangle not higher than pt + max_altoff.
81     // Return ground properties like the maximum load
82     // this kind kind of ground can carry, the friction factor between
83     // 0 and 1 which can be used to model lower friction with wet runways.
84     bool get_agl(double t, const SGVec3d& pt, SGVec3d& contact,
85                  SGVec3d& normal, SGVec3d& linearVel, SGVec3d& angularVel,
86                  simgear::BVHNode::Id& id, const SGMaterial*& material);
87
88     bool get_nearest(double t, const SGVec3d& pt, double maxDist,
89                      SGVec3d& contact, SGVec3d& linearVel, SGVec3d& angularVel,
90                      simgear::BVHNode::Id& id, const SGMaterial*& material);
91
92     // Return 1 if the hook intersects with a wire.
93     // That test is done by checking if the quad spanned by the points pt*
94     // intersects with the line representing the wire.
95     // If the wire is caught, the cache will trace this wires endpoints until
96     // the FDM calls release_wire().
97     bool caught_wire(double t, const SGVec3d pt[4]);
98   
99     // Return the location and speed of the wire endpoints.
100     bool get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2]);
101
102     // Tell the cache code that it does no longer need to care for
103     // the wire end position.
104     void release_wire(void);
105
106 private:
107     class CacheFill;
108     class BodyFinder;
109     class CatapultFinder;
110     class WireIntersector;
111     class WireFinder;
112
113     // Approximate ground radius.
114     // In case the aircraft is too high above ground.
115     double _altitude;
116     // the simgear material reference, contains friction coeficients ...
117     const SGMaterial* _material;
118     // The time reference for later call to intersection test routines.
119     // Is required since we will have moving triangles in carriers.
120     double cache_ref_time;
121     // The time the cache was initialized.
122     double cache_time_offset;
123     // The wire to track.
124     const simgear::BVHLineGeometry* _wire;
125
126     // The point and radius where the cache is built around.
127     // That are the arguments that were given to prepare_ground_cache.
128     SGVec3d reference_wgs84_point;
129     double reference_vehicle_radius;
130     SGVec3d down;
131     bool found_ground;
132
133     SGSharedPtr<simgear::BVHNode> _localBvhTree;
134 };
135
136 #endif