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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef _GROUNDCACHE_HXX
24 #define _GROUNDCACHE_HXX
28 #include <simgear/compiler.h>
29 #include <simgear/constants.h>
33 //////////////////////////////////////////////////////////////////////////
34 // Ground handling routines
35 //////////////////////////////////////////////////////////////////////////
37 // Prepare the ground cache for the wgs84 position pt_*.
38 // That is take all vertices in the ball with radius rad around the
39 // position given by the pt_* and store them in a local scene graph.
40 bool prepare_ground_cache(double ref_time, const double pt[3],
43 // Returns true if the cache is valid.
44 // Also the reference time, point and radius values where the cache
45 // is valid for are returned.
46 bool is_valid(double *ref_time, double pt[3], double *rad);
49 // Return the nearest catapult to the given point
50 // pt in wgs84 coordinates.
51 double get_cat(double t, const double pt[3],
52 double end[2][3], double vel[2][3]);
55 // Return the altitude above ground below the wgs84 point pt
56 // Search for the nearest triangle to pt.
57 // Return ground properties like the ground type, the maximum load
58 // this kind kind of ground can carry, the friction factor between
59 // 0 and 1 which can be used to model lower friction with wet runways
60 // and finally the altitude above ground.
61 bool get_agl(double t, const double pt[3],
62 double contact[3], double normal[3], double vel[3],
63 int *type, double *loadCapacity,
64 double *frictionFactor, double *agl);
67 // Return 1 if the hook intersects with a wire.
68 // That test is done by checking if the quad spanned by the points pt*
69 // intersects with the line representing the wire.
70 // If the wire is caught, the cache will trace this wires endpoints until
71 // the FDM calls release_wire().
72 bool caught_wire(double t, const double pt[4][3]);
74 // Return the location and speed of the wire endpoints.
75 bool get_wire_ends(double t, double end[2][3], double vel[2][3]);
77 // Tell the cache code that it does no longer need to care for
78 // the wire end position.
79 void release_wire(void);
82 // Holds the private ground triangle cache ...
83 // The surface cache itself.
85 // The center of the cache.
87 // Approximate ground radius.
88 // In case the aircraft is too high above ground.
90 // The time reference for later call to intersection test routines.
91 // Is required since we will have moving triangles in carriers.
92 double cache_ref_time;
93 // The wire identifier to track.
96 // The point and radius where the cache is built around.
97 // That are the arguments that were given to prepare_ground_cache.
98 sgdVec3 reference_wgs84_point;
99 double reference_vehicle_radius;
103 // Fills the environment cache with everything inside the sphere sp.
104 void cache_fill(ssgBranch *branch, sgMat4 xform,
105 sgSphere* sp, sgVec3 down, sgSphere* wsp);
107 // Helper class to hold some properties of the ground triangle.
111 GroundProperty() : type(0) {}
115 // not yet implemented ...
116 // double loadCapacity;
119 // compute the ground property of this leaf.
120 static GroundProperty *extractGroundProperty( ssgLeaf* leaf );
123 // compute the ground property of this leaf.
124 void putSurfaceLeafIntoCache(const sgSphere *sp, const sgMat4 xform,
125 bool sphIsec, sgVec3 down, ssgLeaf *l);
127 void putLineLeafIntoCache(const sgSphere *wsp, const sgMat4 xform,
130 void addAndFlattenLeaf(GLenum ty, ssgLeaf *l, ssgIndexArray *ia,
134 void extractCacheRelativeVertex(double t, ssgVtxArray *va,
136 short i, sgVec3 rel_pos,
139 void extractWgs84Vertex(double t, ssgVtxArray *va,
140 GroundProperty *gp, short i,
141 sgdVec3 wgs84_pos, sgdVec3 wgs84_vel);