]> git.mxchange.org Git - flightgear.git/blob - src/FDM/groundcache.hxx
- Added ultra-light traffic is now a separate traffic class that can have its
[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 <simgear/compiler.h>
27 #include <simgear/constants.h>
28 #include <simgear/math/SGMath.hxx>
29 #include <simgear/math/SGGeometry.hxx>
30
31 class SGMaterial;
32 class GroundCacheFillVisitor;
33
34 class FGGroundCache {
35 public:
36     FGGroundCache();
37     ~FGGroundCache();
38
39     //////////////////////////////////////////////////////////////////////////
40     // Ground handling routines
41     //////////////////////////////////////////////////////////////////////////
42
43     // Prepare the ground cache for the wgs84 position pt_*.
44     // That is take all vertices in the ball with radius rad around the
45     // position given by the pt_* and store them in a local scene graph.
46     bool prepare_ground_cache(double ref_time, const SGVec3d& pt,
47                               double rad);
48
49     // Returns true if the cache is valid.
50     // Also the reference time, point and radius values where the cache
51     // is valid for are returned.
52     bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
53
54     // Return the nearest catapult to the given point
55     // pt in wgs84 coordinates.
56     double get_cat(double t, const SGVec3d& pt,
57                    SGVec3d end[2], SGVec3d vel[2]);
58   
59
60     // Return the altitude above ground below the wgs84 point pt
61     // Search for highest triangle not higher than pt + max_altoff.
62     // Return ground properties like the ground type, the maximum load
63     // this kind kind of ground can carry, the friction factor between
64     // 0 and 1 which can be used to model lower friction with wet runways
65     // and finally the altitude above ground.
66     bool get_agl(double t, const SGVec3d& pt, double max_altoff,
67                  SGVec3d& contact, SGVec3d& normal, SGVec3d& vel,
68                  int *type, const SGMaterial** material, double *agl);
69
70     // Return 1 if the hook intersects with a wire.
71     // That test is done by checking if the quad spanned by the points pt*
72     // intersects with the line representing the wire.
73     // If the wire is caught, the cache will trace this wires endpoints until
74     // the FDM calls release_wire().
75     bool caught_wire(double t, const SGVec3d pt[4]);
76   
77     // Return the location and speed of the wire endpoints.
78     bool get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2]);
79
80     // Tell the cache code that it does no longer need to care for
81     // the wire end position.
82     void release_wire(void);
83
84 private:
85     friend class GroundCacheFillVisitor;
86
87     struct Triangle {
88       Triangle() : material(0) {}
89       // The triangle we represent
90       SGTriangled triangle;
91       SGSphered sphere;
92       // The linear and angular velocity.
93       SGVec3d velocity;
94       SGVec3d rotation;
95       SGVec3d rotation_pivot;
96       // Ground type
97       int type;
98       // the simgear material reference, contains friction coeficients ...
99       const SGMaterial* material;
100     };
101     struct Catapult {
102       SGVec3d start;
103       SGVec3d end;
104       SGVec3d velocity;
105       SGVec3d rotation;
106       SGVec3d rotation_pivot;
107     };
108     struct Wire {
109       SGVec3d ends[2];
110       SGVec3d velocity;
111       SGVec3d rotation;
112       SGVec3d rotation_pivot;
113       int wire_id;
114     };
115
116
117     // Approximate ground radius.
118     // In case the aircraft is too high above ground.
119     double ground_radius;
120     // Ground type
121     int _type;
122     // the simgear material reference, contains friction coeficients ...
123     const SGMaterial* _material;
124     // The time reference for later call to intersection test routines.
125     // Is required since we will have moving triangles in carriers.
126     double cache_ref_time;
127     // The wire identifier to track.
128     int wire_id;
129
130     // Containers which hold all the essential information about this cache.
131     std::vector<Triangle> triangles;
132     std::vector<Catapult> catapults;
133     std::vector<Wire> wires;
134
135     // The point and radius where the cache is built around.
136     // That are the arguments that were given to prepare_ground_cache.
137     SGVec3d reference_wgs84_point;
138     double reference_vehicle_radius;
139     SGVec3d down;
140     bool found_ground;
141
142
143     // Helper class to hold some properties of the ground triangle.
144     struct GroundProperty {
145       GroundProperty() : type(0), material(0) {}
146       int type;
147       int wire_id;
148       SGVec3d vel;
149       SGVec3d rot;
150       SGVec3d pivot;
151       const SGMaterial* material;
152     };
153
154     static void velocityTransformTriangle(double dt, SGTriangled& dst,
155                                           SGSphered& sdst, const Triangle& src);
156 };
157
158 #endif