+class FGGroundCache::CatapultFinder : public BVHVisitor {
+public:
+ CatapultFinder(const SGSphered& sphere, const double& t) :
+ _haveLineSegment(false),
+ _sphere(sphere),
+ _time(t)
+ { }
+
+ virtual void apply(BVHGroup& leaf)
+ {
+ if (!intersects(_sphere, leaf.getBoundingSphere()))
+ return;
+ leaf.traverse(*this);
+ }
+ virtual void apply(BVHPageNode& leaf)
+ {
+ if (!intersects(_sphere, leaf.getBoundingSphere()))
+ return;
+ leaf.traverse(*this);
+ }
+ virtual void apply(BVHTransform& transform)
+ {
+ if (!intersects(_sphere, transform.getBoundingSphere()))
+ return;
+
+ SGSphered sphere = _sphere;
+ _sphere = transform.sphereToLocal(sphere);
+ bool haveLineSegment = _haveLineSegment;
+ _haveLineSegment = false;
+
+ transform.traverse(*this);
+
+ if (_haveLineSegment) {
+ _lineSegment = transform.lineSegmentToWorld(_lineSegment);
+ _linearVelocity = transform.vecToWorld(_linearVelocity);
+ _angularVelocity = transform.vecToWorld(_angularVelocity);
+ }
+ _haveLineSegment |= haveLineSegment;
+ _sphere.setCenter(sphere.getCenter());
+ }
+ virtual void apply(BVHMotionTransform& transform)
+ {
+ if (!intersects(_sphere, transform.getBoundingSphere()))
+ return;
+
+ SGSphered sphere = _sphere;
+ _sphere = transform.sphereToLocal(sphere, _time);
+ bool haveLineSegment = _haveLineSegment;
+ _haveLineSegment = false;
+
+ transform.traverse(*this);
+
+ if (_haveLineSegment) {
+ SGMatrixd toWorld = transform.getToWorldTransform(_time);
+ _linearVelocity
+ += transform.getLinearVelocityAt(_lineSegment.getStart());
+ _angularVelocity += transform.getAngularVelocity();
+ _linearVelocity = toWorld.xformVec(_linearVelocity);
+ _angularVelocity = toWorld.xformVec(_angularVelocity);
+ _lineSegment = _lineSegment.transform(toWorld);
+ }
+ _haveLineSegment |= haveLineSegment;
+ _sphere.setCenter(sphere.getCenter());
+ }
+ virtual void apply(BVHLineGeometry& node)
+ {
+ if (node.getType() != BVHLineGeometry::CarrierCatapult)
+ return;
+
+ SGLineSegmentd lineSegment(node.getLineSegment());
+ if (!intersects(_sphere, lineSegment))
+ return;
+
+ _lineSegment = lineSegment;
+ double dist = distSqr(lineSegment, getSphere().getCenter());
+ _sphere.setRadius(sqrt(dist));
+ _linearVelocity = SGVec3d::zeros();
+ _angularVelocity = SGVec3d::zeros();
+ _haveLineSegment = true;
+ }
+ virtual void apply(BVHStaticGeometry& node)
+ { }
+
+ virtual void apply(const BVHStaticBinary&, const BVHStaticData&) { }
+ virtual void apply(const BVHStaticTriangle&, const BVHStaticData&) { }
+
+ void setSphere(const SGSphered& sphere)
+ { _sphere = sphere; }
+ const SGSphered& getSphere() const
+ { return _sphere; }
+
+ const SGLineSegmentd& getLineSegment() const
+ { return _lineSegment; }
+ const SGVec3d& getLinearVelocity() const
+ { return _linearVelocity; }
+ const SGVec3d& getAngularVelocity() const
+ { return _angularVelocity; }
+
+ bool getHaveLineSegment() const
+ { return _haveLineSegment; }
+
+protected:
+ SGLineSegmentd _lineSegment;
+ SGVec3d _linearVelocity;
+ SGVec3d _angularVelocity;
+
+ bool _haveLineSegment;
+
+ SGSphered _sphere;
+ double _time;
+};
+
+double
+FGGroundCache::get_cat(double t, const SGVec3d& pt,
+ SGVec3d end[2], SGVec3d vel[2])