X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2Fgroundcache.hxx;h=145561a9c571589b47f1075e8d7be5735de6de2b;hb=c44948041b9356c9d16acc2d888de109bf7866e7;hp=f00fb40c1e9904df3b910ae751f6ced7f1c473ca;hpb=93cb29608a9eaebc84dee6a9d39872308ff0651e;p=flightgear.git diff --git a/src/FDM/groundcache.hxx b/src/FDM/groundcache.hxx index f00fb40c1..145561a9c 100644 --- a/src/FDM/groundcache.hxx +++ b/src/FDM/groundcache.hxx @@ -26,9 +26,21 @@ #include #include #include +#include +#include +#include + +// #define GROUNDCACHE_DEBUG +#ifdef GROUNDCACHE_DEBUG +#include +#include +#include +#endif class SGMaterial; -class GroundCacheFillVisitor; +namespace simgear { +class BVHLineGeometry; +} class FGGroundCache { public: @@ -42,14 +54,28 @@ public: // 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. - bool prepare_ground_cache(double ref_time, const SGVec3d& pt, - double rad); + bool prepare_ground_cache(double startSimTime, double endSimTime, + const SGVec3d& pt, double rad); // Returns true if the cache is valid. // Also the reference time, point and radius values where the cache // is valid for are returned. bool is_valid(double& ref_time, SGVec3d& pt, double& rad); + // Returns the unit down vector at the ground cache + const SGVec3d& get_down() const + { return down; } + + // The time offset that originates from a simtime different than zero + // at initialization time of the fdm. + double get_cache_time_offset() const + { return cache_time_offset; } + void set_cache_time_offset(double time_offset) + { cache_time_offset = time_offset; } + + bool get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel, + SGVec3d& angularVel, simgear::BVHNode::Id id); + // Return the nearest catapult to the given point // pt in wgs84 coordinates. double get_cat(double t, const SGVec3d& pt, @@ -58,13 +84,16 @@ public: // Return the altitude above ground below the wgs84 point pt // Search for highest triangle not higher than pt + max_altoff. - // Return ground properties like the ground type, the maximum load + // Return ground properties like the maximum load // this kind kind of ground can carry, the friction factor between - // 0 and 1 which can be used to model lower friction with wet runways - // and finally the altitude above ground. - bool get_agl(double t, const SGVec3d& pt, double max_altoff, - SGVec3d& contact, SGVec3d& normal, SGVec3d& vel, - int *type, const SGMaterial** material, double *agl); + // 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); // Return 1 if the hook intersects with a wire. // That test is done by checking if the quad spanned by the points pt* @@ -81,61 +110,24 @@ public: void release_wire(void); private: - friend class GroundCacheFillVisitor; - - struct Triangle { - Triangle() : material(0) {} - // The edge vertices. - SGVec3d vertices[3]; - // The surface normal. - SGVec4d plane; - // The bounding shpere. - SGVec3d boundCenter; - double boundRadius; - // The linear and angular velocity. - SGVec3d velocity; - SGVec3d rotation; - SGVec3d rotation_pivot; - // Ground type - int type; - // the simgear material reference, contains friction coeficients ... - const SGMaterial* material; - }; - struct Catapult { - SGVec3d start; - SGVec3d end; - SGVec3d velocity; - SGVec3d rotation; - SGVec3d rotation_pivot; - }; - struct Wire { - SGVec3d ends[2]; - SGVec3d velocity; - SGVec3d rotation; - SGVec3d rotation_pivot; - int wire_id; - }; - - - // The center of the cache. - SGVec3d cache_center; + class CacheFill; + class BodyFinder; + class CatapultFinder; + class WireIntersector; + class WireFinder; + // Approximate ground radius. // In case the aircraft is too high above ground. - double ground_radius; - // Ground type - int _type; + double _altitude; // the simgear material reference, contains friction coeficients ... const SGMaterial* _material; // The time reference for later call to intersection test routines. // Is required since we will have moving triangles in carriers. double cache_ref_time; - // The wire identifier to track. - int wire_id; - - // Containers which hold all the essential information about this cache. - std::vector triangles; - std::vector catapults; - std::vector wires; + // The time the cache was initialized. + double cache_time_offset; + // The wire to track. + const simgear::BVHLineGeometry* _wire; // The point and radius where the cache is built around. // That are the arguments that were given to prepare_ground_cache. @@ -144,20 +136,16 @@ private: SGVec3d down; bool found_ground; + SGSharedPtr _localBvhTree; - // Helper class to hold some properties of the ground triangle. - struct GroundProperty { - GroundProperty() : type(0), material(0) {} - int type; - int wire_id; - SGVec3d vel; - SGVec3d rot; - SGVec3d pivot; - const SGMaterial* material; - }; +#ifdef GROUNDCACHE_DEBUG + SGTimeStamp _lookupTime; + unsigned _lookupCount; + SGTimeStamp _buildTime; + unsigned _buildCount; - static void velocityTransformTriangle(double dt, Triangle& dst, - const Triangle& src); + osg::ref_ptr _group; +#endif }; #endif