1 // groundcache.hxx -- carries a small subset of the scenegraph near the vehicle
3 // Written by Mathias Froehlich, started Nov 2004.
5 // Copyright (C) 2004 Mathias Froehlich - Mathias.Froehlich@web.de
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.
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.
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.
23 #ifndef _GROUNDCACHE_HXX
24 #define _GROUNDCACHE_HXX
26 #include <simgear/compiler.h>
27 #include <simgear/constants.h>
28 #include <simgear/math/SGMath.hxx>
31 class GroundCacheFillVisitor;
38 //////////////////////////////////////////////////////////////////////////
39 // Ground handling routines
40 //////////////////////////////////////////////////////////////////////////
42 // Prepare the ground cache for the wgs84 position pt_*.
43 // That is take all vertices in the ball with radius rad around the
44 // position given by the pt_* and store them in a local scene graph.
45 bool prepare_ground_cache(double ref_time, const SGVec3d& pt,
48 // Returns true if the cache is valid.
49 // Also the reference time, point and radius values where the cache
50 // is valid for are returned.
51 bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
53 // Return the nearest catapult to the given point
54 // pt in wgs84 coordinates.
55 double get_cat(double t, const SGVec3d& pt,
56 SGVec3d end[2], SGVec3d vel[2]);
59 // Return the altitude above ground below the wgs84 point pt
60 // Search for highest triangle not higher than pt + max_altoff.
61 // Return ground properties like the ground type, the maximum load
62 // this kind kind of ground can carry, the friction factor between
63 // 0 and 1 which can be used to model lower friction with wet runways
64 // and finally the altitude above ground.
65 bool get_agl(double t, const SGVec3d& pt, double max_altoff,
66 SGVec3d& contact, SGVec3d& normal, SGVec3d& vel,
67 int *type, const SGMaterial** material, double *agl);
69 // Return 1 if the hook intersects with a wire.
70 // That test is done by checking if the quad spanned by the points pt*
71 // intersects with the line representing the wire.
72 // If the wire is caught, the cache will trace this wires endpoints until
73 // the FDM calls release_wire().
74 bool caught_wire(double t, const SGVec3d pt[4]);
76 // Return the location and speed of the wire endpoints.
77 bool get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2]);
79 // Tell the cache code that it does no longer need to care for
80 // the wire end position.
81 void release_wire(void);
84 friend class GroundCacheFillVisitor;
87 Triangle() : material(0) {}
90 // The surface normal.
92 // The bounding shpere.
95 // The linear and angular velocity.
98 SGVec3d rotation_pivot;
101 // the simgear material reference, contains friction coeficients ...
102 const SGMaterial* material;
109 SGVec3d rotation_pivot;
115 SGVec3d rotation_pivot;
120 // The center of the cache.
121 SGVec3d cache_center;
122 // Approximate ground radius.
123 // In case the aircraft is too high above ground.
124 double ground_radius;
127 // the simgear material reference, contains friction coeficients ...
128 const SGMaterial* _material;
129 // The time reference for later call to intersection test routines.
130 // Is required since we will have moving triangles in carriers.
131 double cache_ref_time;
132 // The wire identifier to track.
135 // Containers which hold all the essential information about this cache.
136 std::vector<Triangle> triangles;
137 std::vector<Catapult> catapults;
138 std::vector<Wire> wires;
140 // The point and radius where the cache is built around.
141 // That are the arguments that were given to prepare_ground_cache.
142 SGVec3d reference_wgs84_point;
143 double reference_vehicle_radius;
148 // Helper class to hold some properties of the ground triangle.
149 struct GroundProperty {
150 GroundProperty() : type(0), material(0) {}
156 const SGMaterial* material;
159 static void velocityTransformTriangle(double dt, Triangle& dst,
160 const Triangle& src);