2004-11-22 10:10:33 +00:00
|
|
|
// groundcache.hxx -- carries a small subset of the scenegraph near the vehicle
|
|
|
|
//
|
|
|
|
// Written by Mathias Froehlich, started Nov 2004.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2004 Mathias Froehlich - Mathias.Froehlich@web.de
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-11-22 10:10:33 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifndef _GROUNDCACHE_HXX
|
|
|
|
#define _GROUNDCACHE_HXX
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
#include <simgear/constants.h>
|
2006-10-29 19:30:21 +00:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2007-01-30 20:13:32 +00:00
|
|
|
#include <simgear/math/SGGeometry.hxx>
|
2009-03-01 16:22:04 +00:00
|
|
|
#include <simgear/scene/bvh/BVHNode.hxx>
|
|
|
|
#include <simgear/structure/SGSharedPtr.hxx>
|
2004-11-22 10:10:33 +00:00
|
|
|
|
2009-03-16 09:47:59 +00:00
|
|
|
// #define GROUNDCACHE_DEBUG
|
|
|
|
#ifdef GROUNDCACHE_DEBUG
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <simgear/timing/timestamp.hxx>
|
|
|
|
#endif
|
|
|
|
|
2006-06-11 13:34:18 +00:00
|
|
|
class SGMaterial;
|
2009-03-01 16:22:04 +00:00
|
|
|
namespace simgear {
|
|
|
|
class BVHLineGeometry;
|
|
|
|
}
|
2006-06-11 13:34:18 +00:00
|
|
|
|
2004-11-22 10:10:33 +00:00
|
|
|
class FGGroundCache {
|
|
|
|
public:
|
2004-12-08 14:48:06 +00:00
|
|
|
FGGroundCache();
|
|
|
|
~FGGroundCache();
|
|
|
|
|
2004-11-22 10:10:33 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Ground handling routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Prepare the ground cache for the wgs84 position pt_*.
|
|
|
|
// That is take all vertices in the ball with radius rad around the
|
|
|
|
// position given by the pt_* and store them in a local scene graph.
|
2009-03-15 11:26:31 +00:00
|
|
|
bool prepare_ground_cache(double startSimTime, double endSimTime,
|
|
|
|
const SGVec3d& pt, double rad);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
|
|
|
// Returns true if the cache is valid.
|
|
|
|
// Also the reference time, point and radius values where the cache
|
|
|
|
// is valid for are returned.
|
2006-10-29 19:30:21 +00:00
|
|
|
bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
2009-03-06 16:37:12 +00:00
|
|
|
// Returns the unit down vector at the ground cache
|
|
|
|
const SGVec3d& get_down() const
|
|
|
|
{ return down; }
|
|
|
|
|
2009-03-16 09:47:59 +00:00
|
|
|
// The time offset that originates from a simtime different than zero
|
|
|
|
// at initialization time of the fdm.
|
2009-03-15 18:18:21 +00:00
|
|
|
double get_cache_time_offset() const
|
|
|
|
{ return cache_time_offset; }
|
|
|
|
void set_cache_time_offset(double time_offset)
|
|
|
|
{ cache_time_offset = time_offset; }
|
2009-03-06 16:37:12 +00:00
|
|
|
|
|
|
|
bool get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel,
|
|
|
|
SGVec3d& angularVel, simgear::BVHNode::Id id);
|
|
|
|
|
2004-11-22 10:10:33 +00:00
|
|
|
// Return the nearest catapult to the given point
|
|
|
|
// pt in wgs84 coordinates.
|
2006-10-29 19:30:21 +00:00
|
|
|
double get_cat(double t, const SGVec3d& pt,
|
|
|
|
SGVec3d end[2], SGVec3d vel[2]);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Return the altitude above ground below the wgs84 point pt
|
Mathias Fröhlich:
I have introduced the posibility to start directly on the carrier.
With that patch you will have a --carrrier=id argument where id can either be
the pennant number configured in the nimitz scenario or the carriers name
also configured in the carriers scenario.
Additionaly you can use --parkpos=id to select different positions on the
carrier. They are also configured in the scenario file.
That includes the switch of the whole FGInterface class to make use of the
groundcache.
That means that an aircraft no longer uses the current elevation value from
the scenery class. It rather has its own local cache of the aircrafts
environment which is setup in the common_init method of FGInterface and
updated either manually by calling
FGInterface::get_groundlevel_m(lat, lon, alt_m);
or implicitly by calling the above method in the
FGInterface::_updateGeo*Position(lat, lon, alt);
methods.
A call get_groundlevel_m rebuilds the groundcache if the request is outside
the range of the cache.
Note that for the real usage of the groundcache including the correct
information about the movement of objects and the velocity information, you
still need to set up the groundcache in the usual way like YASim and JSBSim
currently does.
If you use the native interface, you will get only static objects correctly.
But for FDM's only using one single ground level for a whole step this is IMO
sufficient.
The AIManager gets a way to return the location of a object which is placed
wrt an AI Object. At the moment it only honours AICarriers for that.
That method is a static one, which loads the scenario file for that reason and
throws it away afterwards. This looked like the aprioriate way, because the
AIManager is initialized much later in flightgears bootstrap, and I did not
find an easy way to reorder that for my needs. Since this additional load is
very small and does only happen if such a relative location is required, I
think that this is ok.
Note that moving on the carrier will only work correctly for JSBSim and YASim,
but you should now be able to start and move on every not itself moving
object with any FDM.
2005-07-03 09:39:14 +00:00
|
|
|
// Search for highest triangle not higher than pt + max_altoff.
|
2009-03-06 16:37:12 +00:00
|
|
|
// Return ground properties like the maximum load
|
2004-11-22 10:10:33 +00:00
|
|
|
// this kind kind of ground can carry, the friction factor between
|
2009-03-06 16:37:12 +00:00
|
|
|
// 0 and 1 which can be used to model lower friction with wet runways.
|
|
|
|
bool get_agl(double t, const SGVec3d& pt, SGVec3d& contact,
|
|
|
|
SGVec3d& normal, SGVec3d& linearVel, SGVec3d& angularVel,
|
|
|
|
simgear::BVHNode::Id& id, const SGMaterial*& material);
|
|
|
|
|
|
|
|
bool get_nearest(double t, const SGVec3d& pt, double maxDist,
|
|
|
|
SGVec3d& contact, SGVec3d& linearVel, SGVec3d& angularVel,
|
|
|
|
simgear::BVHNode::Id& id, const SGMaterial*& material);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
|
|
|
// Return 1 if the hook intersects with a wire.
|
|
|
|
// That test is done by checking if the quad spanned by the points pt*
|
|
|
|
// intersects with the line representing the wire.
|
|
|
|
// If the wire is caught, the cache will trace this wires endpoints until
|
|
|
|
// the FDM calls release_wire().
|
2006-10-29 19:30:21 +00:00
|
|
|
bool caught_wire(double t, const SGVec3d pt[4]);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
|
|
|
// Return the location and speed of the wire endpoints.
|
2006-10-29 19:30:21 +00:00
|
|
|
bool get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2]);
|
2004-11-22 10:10:33 +00:00
|
|
|
|
|
|
|
// Tell the cache code that it does no longer need to care for
|
|
|
|
// the wire end position.
|
|
|
|
void release_wire(void);
|
|
|
|
|
|
|
|
private:
|
2009-03-01 16:22:04 +00:00
|
|
|
class CacheFill;
|
2009-03-06 16:37:12 +00:00
|
|
|
class BodyFinder;
|
2009-03-01 16:22:04 +00:00
|
|
|
class CatapultFinder;
|
|
|
|
class WireIntersector;
|
|
|
|
class WireFinder;
|
2005-05-30 08:48:27 +00:00
|
|
|
|
2004-11-22 10:10:33 +00:00
|
|
|
// Approximate ground radius.
|
|
|
|
// In case the aircraft is too high above ground.
|
2009-03-01 16:22:04 +00:00
|
|
|
double _altitude;
|
2007-01-02 09:50:35 +00:00
|
|
|
// the simgear material reference, contains friction coeficients ...
|
|
|
|
const SGMaterial* _material;
|
2004-11-22 10:10:33 +00:00
|
|
|
// The time reference for later call to intersection test routines.
|
|
|
|
// Is required since we will have moving triangles in carriers.
|
|
|
|
double cache_ref_time;
|
2009-03-15 18:18:21 +00:00
|
|
|
// The time the cache was initialized.
|
|
|
|
double cache_time_offset;
|
2009-03-01 16:22:04 +00:00
|
|
|
// The wire to track.
|
|
|
|
const simgear::BVHLineGeometry* _wire;
|
2005-05-30 08:48:27 +00:00
|
|
|
|
2004-11-22 10:10:33 +00:00
|
|
|
// The point and radius where the cache is built around.
|
|
|
|
// That are the arguments that were given to prepare_ground_cache.
|
2006-10-29 19:30:21 +00:00
|
|
|
SGVec3d reference_wgs84_point;
|
2004-11-22 10:10:33 +00:00
|
|
|
double reference_vehicle_radius;
|
2006-10-29 19:30:21 +00:00
|
|
|
SGVec3d down;
|
2004-11-22 10:10:33 +00:00
|
|
|
bool found_ground;
|
|
|
|
|
2009-03-01 16:22:04 +00:00
|
|
|
SGSharedPtr<simgear::BVHNode> _localBvhTree;
|
2009-03-16 09:47:59 +00:00
|
|
|
|
|
|
|
#ifdef GROUNDCACHE_DEBUG
|
|
|
|
SGTimeStamp _lookupTime;
|
|
|
|
unsigned _lookupCount;
|
|
|
|
SGTimeStamp _buildTime;
|
|
|
|
unsigned _buildCount;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> _group;
|
|
|
|
#endif
|
2004-11-22 10:10:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|