1 // groundcache.cxx -- carries a small subset of the scenegraph near the vehicle
3 // Written by Mathias Froehlich, started Nov 2004.
5 // Copyright (C) 2004, 2009 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.
29 #include <osg/Drawable>
31 #include <osg/Geometry>
33 #include <osg/Transform>
34 #include <osg/MatrixTransform>
35 #include <osg/PositionAttitudeTransform>
36 #include <osg/CameraView>
38 #include <simgear/sg_inlines.h>
39 #include <simgear/constants.h>
40 #include <simgear/debug/logstream.hxx>
41 #include <simgear/math/sg_geodesy.hxx>
42 #include <simgear/scene/util/SGNodeMasks.hxx>
43 #include <simgear/scene/util/SGSceneUserData.hxx>
45 #include <simgear/scene/bvh/BVHNode.hxx>
46 #include <simgear/scene/bvh/BVHGroup.hxx>
47 #include <simgear/scene/bvh/BVHTransform.hxx>
48 #include <simgear/scene/bvh/BVHMotionTransform.hxx>
49 #include <simgear/scene/bvh/BVHLineGeometry.hxx>
50 #include <simgear/scene/bvh/BVHStaticGeometry.hxx>
51 #include <simgear/scene/bvh/BVHStaticData.hxx>
52 #include <simgear/scene/bvh/BVHStaticNode.hxx>
53 #include <simgear/scene/bvh/BVHStaticTriangle.hxx>
54 #include <simgear/scene/bvh/BVHStaticBinary.hxx>
55 #include <simgear/scene/bvh/BVHSubTreeCollector.hxx>
56 #include <simgear/scene/bvh/BVHLineSegmentVisitor.hxx>
57 #include <simgear/scene/bvh/BVHNearestPointVisitor.hxx>
59 #include <Main/globals.hxx>
60 #include <Scenery/scenery.hxx>
61 #include <Scenery/tilemgr.hxx>
64 #include "groundcache.hxx"
66 using namespace simgear;
68 class FGGroundCache::CacheFill : public osg::NodeVisitor {
70 CacheFill(const SGVec3d& center, const double& radius,
71 const double& startTime, const double& endTime) :
72 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN),
75 _startTime(startTime),
78 setTraversalMask(SG_NODEMASK_TERRAIN_BIT);
80 virtual void apply(osg::Node& node)
82 if (!testBoundingSphere(node.getBound()))
85 addBoundingVolume(node);
88 virtual void apply(osg::Group& group)
90 if (!testBoundingSphere(group.getBound()))
93 simgear::BVHSubTreeCollector::NodeList parentNodeList;
94 mSubTreeCollector.pushNodeList(parentNodeList);
97 addBoundingVolume(group);
99 mSubTreeCollector.popNodeList(parentNodeList);
102 virtual void apply(osg::Transform& transform)
103 { handleTransform(transform); }
104 virtual void apply(osg::Camera& camera)
106 if (camera.getRenderOrder() != osg::Camera::NESTED_RENDER)
108 handleTransform(camera);
110 virtual void apply(osg::CameraView& transform)
111 { handleTransform(transform); }
112 virtual void apply(osg::MatrixTransform& transform)
113 { handleTransform(transform); }
114 virtual void apply(osg::PositionAttitudeTransform& transform)
115 { handleTransform(transform); }
117 void handleTransform(osg::Transform& transform)
119 // Hmm, may be this needs to be refined somehow ...
120 if (transform.getReferenceFrame() != osg::Transform::RELATIVE_RF)
123 if (!testBoundingSphere(transform.getBound()))
126 osg::Matrix inverseMatrix;
127 if (!transform.computeWorldToLocalMatrix(inverseMatrix, this))
130 if (!transform.computeLocalToWorldMatrix(matrix, this))
133 // Look for a velocity note
134 const SGSceneUserData::Velocity* velocity = getVelocity(transform);
136 SGVec3d center = _center;
137 _center = SGVec3d(inverseMatrix.preMult(_center.osg()));
138 double radius = _radius;
140 _radius += (_endTime - _startTime)*norm(velocity->linear);
142 simgear::BVHSubTreeCollector::NodeList parentNodeList;
143 mSubTreeCollector.pushNodeList(parentNodeList);
145 addBoundingVolume(transform);
148 if (mSubTreeCollector.haveChildren()) {
150 simgear::BVHMotionTransform* bvhTransform;
151 bvhTransform = new simgear::BVHMotionTransform;
152 bvhTransform->setToWorldTransform(SGMatrixd(matrix.ptr()));
153 bvhTransform->setLinearVelocity(velocity->linear);
154 bvhTransform->setAngularVelocity(velocity->angular);
155 bvhTransform->setReferenceTime(_startTime);
156 bvhTransform->setEndTime(_endTime);
157 bvhTransform->setId(velocity->id);
159 mSubTreeCollector.popNodeList(parentNodeList, bvhTransform);
161 simgear::BVHTransform* bvhTransform;
162 bvhTransform = new simgear::BVHTransform;
163 bvhTransform->setToWorldTransform(SGMatrixd(matrix.ptr()));
165 mSubTreeCollector.popNodeList(parentNodeList, bvhTransform);
168 mSubTreeCollector.popNodeList(parentNodeList);
174 const SGSceneUserData::Velocity* getVelocity(osg::Node& node)
176 SGSceneUserData* userData = SGSceneUserData::getSceneUserData(&node);
179 return userData->getVelocity();
181 simgear::BVHNode* getNodeBoundingVolume(osg::Node& node)
183 SGSceneUserData* userData = SGSceneUserData::getSceneUserData(&node);
186 return userData->getBVHNode();
188 void addBoundingVolume(osg::Node& node)
190 simgear::BVHNode* bvNode = getNodeBoundingVolume(node);
194 // Get that part of the local bv tree that intersects our sphere
196 mSubTreeCollector.setSphere(SGSphered(_center, _radius));
197 bvNode->accept(mSubTreeCollector);
200 bool testBoundingSphere(const osg::BoundingSphere& bound) const
205 double maxDist = bound._radius + _radius;
206 return distSqr(SGVec3d(bound._center), _center) <= maxDist*maxDist;
209 SGSharedPtr<simgear::BVHNode> getBVHNode() const
210 { return mSubTreeCollector.getNode(); }
219 simgear::BVHSubTreeCollector mSubTreeCollector;
222 FGGroundCache::FGGroundCache() :
227 reference_wgs84_point(SGVec3d(0, 0, 0)),
228 reference_vehicle_radius(0),
234 FGGroundCache::~FGGroundCache()
239 FGGroundCache::prepare_ground_cache(double ref_time, const SGVec3d& pt,
243 found_ground = false;
245 SGGeod geodPt = SGGeod::fromCart(pt);
246 // Don't blow away the cache ground_radius and stuff if there's no
248 if (!globals->get_tile_mgr()->scenery_available(geodPt.getLatitudeDeg(),
249 geodPt.getLongitudeDeg(),
254 // If we have an active wire, get some more area into the groundcache
256 rad = SGMiscd::max(200, rad);
258 // Store the parameters we used to build up that cache.
259 reference_wgs84_point = pt;
260 reference_vehicle_radius = rad;
261 // Store the time reference used to compute movements of moving triangles.
262 cache_ref_time = ref_time;
264 // Get a normalized down vector valid for the whole cache
265 SGQuatd hlToEc = SGQuatd::fromLonLat(geodPt);
266 down = hlToEc.rotate(SGVec3d(0, 0, 1));
268 // Get the ground cache, that is a local collision tree of the environment
269 double endTime = cache_ref_time + 1; //FIXME??
270 CacheFill subtreeCollector(pt, rad, cache_ref_time, endTime);
271 globals->get_scenery()->get_scene_graph()->accept(subtreeCollector);
272 _localBvhTree = subtreeCollector.getBVHNode();
274 // Try to get a croase altitude value for the ground cache
275 SGLineSegmentd line(pt, pt + 2*reference_vehicle_radius*down);
276 simgear::BVHLineSegmentVisitor lineSegmentVisitor(line, ref_time);
278 _localBvhTree->accept(lineSegmentVisitor);
280 // If this is successful, store this altitude for croase altitude values
281 if (!lineSegmentVisitor.empty()) {
282 SGGeod geodPt = SGGeod::fromCart(lineSegmentVisitor.getPoint());
283 _altitude = geodPt.getElevationM();
284 _material = lineSegmentVisitor.getMaterial();
287 // Else do a crude scene query for the current point
288 found_ground = globals->get_scenery()->
289 get_cart_elevation_m(pt, rad, _altitude, &_material);
292 // Still not sucessful??
294 SG_LOG(SG_FLIGHT, SG_WARN, "prepare_ground_cache(): trying to build "
295 "cache without any scenery below the aircraft");
301 FGGroundCache::is_valid(double& ref_time, SGVec3d& pt, double& rad)
303 pt = reference_wgs84_point;
304 rad = reference_vehicle_radius;
305 ref_time = cache_ref_time;
309 class FGGroundCache::BodyFinder : public BVHVisitor {
311 BodyFinder(BVHNode::Id id, const double& t) :
313 _bodyToWorld(SGMatrixd::unit()),
314 _linearVelocity(0, 0, 0),
315 _angularVelocity(0, 0, 0),
319 virtual void apply(BVHGroup& leaf)
323 leaf.traverse(*this);
325 virtual void apply(BVHTransform& transform)
330 transform.traverse(*this);
333 _linearVelocity = transform.vecToWorld(_linearVelocity);
334 _angularVelocity = transform.vecToWorld(_angularVelocity);
335 _bodyToWorld = transform.getToWorldTransform()*_bodyToWorld;
338 virtual void apply(BVHMotionTransform& transform)
343 if (_id == transform.getId()) {
348 transform.traverse(*this);
351 SGMatrixd toWorld = transform.getToWorldTransform(_time);
352 SGVec3d referencePoint = _bodyToWorld.xformPt(SGVec3d::zeros());
353 _linearVelocity += transform.getLinearVelocityAt(referencePoint);
354 _angularVelocity += transform.getAngularVelocity();
355 _linearVelocity = toWorld.xformVec(_linearVelocity);
356 _angularVelocity = toWorld.xformVec(_angularVelocity);
357 _bodyToWorld = toWorld*_bodyToWorld;
360 virtual void apply(BVHLineGeometry& node) { }
361 virtual void apply(BVHStaticGeometry& node) { }
363 virtual void apply(const BVHStaticBinary&, const BVHStaticData&) { }
364 virtual void apply(const BVHStaticTriangle&, const BVHStaticData&) { }
366 const SGMatrixd& getBodyToWorld() const
367 { return _bodyToWorld; }
368 const SGVec3d& getLinearVelocity() const
369 { return _linearVelocity; }
370 const SGVec3d& getAngularVelocity() const
371 { return _angularVelocity; }
374 { return !_foundId; }
377 simgear::BVHNode::Id _id;
379 SGMatrixd _bodyToWorld;
381 SGVec3d _linearVelocity;
382 SGVec3d _angularVelocity;
390 FGGroundCache::get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel,
391 SGVec3d& angularVel, simgear::BVHNode::Id id)
393 // Get the transform matrix and velocities of a moving body with id at t.
396 BodyFinder bodyFinder(id, t);
397 _localBvhTree->accept(bodyFinder);
398 if (bodyFinder.empty())
401 bodyToWorld = bodyFinder.getBodyToWorld();
402 linearVel = bodyFinder.getLinearVelocity();
403 angularVel = bodyFinder.getAngularVelocity();
408 class FGGroundCache::CatapultFinder : public BVHVisitor {
410 CatapultFinder(const SGSphered& sphere, const double& t) :
413 _haveLineSegment(false)
416 virtual void apply(BVHGroup& leaf)
418 if (!intersects(_sphere, leaf.getBoundingSphere()))
420 leaf.traverse(*this);
422 virtual void apply(BVHTransform& transform)
424 if (!intersects(_sphere, transform.getBoundingSphere()))
427 SGSphered sphere = _sphere;
428 _sphere = transform.sphereToLocal(sphere);
429 bool haveLineSegment = _haveLineSegment;
430 _haveLineSegment = false;
432 transform.traverse(*this);
434 if (_haveLineSegment) {
435 _lineSegment = transform.lineSegmentToWorld(_lineSegment);
436 _linearVelocity = transform.vecToWorld(_linearVelocity);
437 _angularVelocity = transform.vecToWorld(_angularVelocity);
439 _haveLineSegment |= haveLineSegment;
440 _sphere.setCenter(sphere.getCenter());
442 virtual void apply(BVHMotionTransform& transform)
444 if (!intersects(_sphere, transform.getBoundingSphere()))
447 SGSphered sphere = _sphere;
448 _sphere = transform.sphereToLocal(sphere, _time);
449 bool haveLineSegment = _haveLineSegment;
450 _haveLineSegment = false;
452 transform.traverse(*this);
454 if (_haveLineSegment) {
455 SGMatrixd toWorld = transform.getToWorldTransform(_time);
457 += transform.getLinearVelocityAt(_lineSegment.getStart());
458 _angularVelocity += transform.getAngularVelocity();
459 _linearVelocity = toWorld.xformVec(_linearVelocity);
460 _angularVelocity = toWorld.xformVec(_angularVelocity);
461 _lineSegment = _lineSegment.transform(toWorld);
463 _haveLineSegment |= haveLineSegment;
464 _sphere.setCenter(sphere.getCenter());
466 virtual void apply(BVHLineGeometry& node)
468 if (node.getType() != BVHLineGeometry::CarrierCatapult)
471 SGLineSegmentd lineSegment(node.getLineSegment());
472 if (!intersects(_sphere, lineSegment))
475 _lineSegment = lineSegment;
476 double dist = distSqr(lineSegment, getSphere().getCenter());
477 _sphere.setRadius(sqrt(dist));
478 _linearVelocity = SGVec3d::zeros();
479 _angularVelocity = SGVec3d::zeros();
480 _haveLineSegment = true;
482 virtual void apply(BVHStaticGeometry& node)
485 virtual void apply(const BVHStaticBinary&, const BVHStaticData&) { }
486 virtual void apply(const BVHStaticTriangle&, const BVHStaticData&) { }
488 void setSphere(const SGSphered& sphere)
489 { _sphere = sphere; }
490 const SGSphered& getSphere() const
493 const SGLineSegmentd& getLineSegment() const
494 { return _lineSegment; }
495 const SGVec3d& getLinearVelocity() const
496 { return _linearVelocity; }
497 const SGVec3d& getAngularVelocity() const
498 { return _angularVelocity; }
500 bool getHaveLineSegment() const
501 { return _haveLineSegment; }
504 SGLineSegmentd _lineSegment;
505 SGVec3d _linearVelocity;
506 SGVec3d _angularVelocity;
508 bool _haveLineSegment;
515 FGGroundCache::get_cat(double t, const SGVec3d& pt,
516 SGVec3d end[2], SGVec3d vel[2])
518 double maxDistance = 1000;
520 // Get the wire in question
521 CatapultFinder catapultFinder(SGSphered(pt, maxDistance), t);
523 _localBvhTree->accept(catapultFinder);
525 if (!catapultFinder.getHaveLineSegment())
528 // prepare the returns
529 end[0] = catapultFinder.getLineSegment().getStart();
530 end[1] = catapultFinder.getLineSegment().getEnd();
532 // The linear velocity is the one at the start of the line segment ...
533 vel[0] = catapultFinder.getLinearVelocity();
534 // ... so the end point has the additional cross product.
535 vel[1] = catapultFinder.getLinearVelocity();
536 vel[1] += cross(catapultFinder.getAngularVelocity(),
537 catapultFinder.getLineSegment().getDirection());
539 // Return the distance to the cat
540 return sqrt(distSqr(catapultFinder.getLineSegment(), pt));
544 FGGroundCache::get_agl(double t, const SGVec3d& pt, SGVec3d& contact,
545 SGVec3d& normal, SGVec3d& linearVel, SGVec3d& angularVel,
546 simgear::BVHNode::Id& id, const SGMaterial*& material)
548 // Just set up a ground intersection query for the given point
549 SGLineSegmentd line(pt, pt + 10*reference_vehicle_radius*down);
550 simgear::BVHLineSegmentVisitor lineSegmentVisitor(line, t);
552 _localBvhTree->accept(lineSegmentVisitor);
554 if (!lineSegmentVisitor.empty()) {
555 // Have an intersection
556 contact = lineSegmentVisitor.getPoint();
557 normal = lineSegmentVisitor.getNormal();
558 if (0 < dot(normal, down))
560 linearVel = lineSegmentVisitor.getLinearVelocity();
561 angularVel = lineSegmentVisitor.getAngularVelocity();
562 material = lineSegmentVisitor.getMaterial();
563 id = lineSegmentVisitor.getId();
567 // Whenever we did not have a ground triangle for the requested point,
568 // take the ground level we found during the current cache build.
569 // This is as good as what we had before for agl.
570 SGGeod geodPt = SGGeod::fromCart(pt);
571 geodPt.setElevationM(_altitude);
572 contact = SGVec3d::fromGeod(geodPt);
574 linearVel = SGVec3d(0, 0, 0);
575 angularVel = SGVec3d(0, 0, 0);
576 material = _material;
585 FGGroundCache::get_nearest(double t, const SGVec3d& pt, double maxDist,
586 SGVec3d& contact, SGVec3d& linearVel,
587 SGVec3d& angularVel, simgear::BVHNode::Id& id,
588 const SGMaterial*& material)
593 // Just set up a ground intersection query for the given point
594 SGSphered sphere(pt, maxDist);
595 simgear::BVHNearestPointVisitor nearestPointVisitor(sphere, t);
596 _localBvhTree->accept(nearestPointVisitor);
598 if (nearestPointVisitor.empty())
601 // Have geometry in the range of maxDist
602 contact = nearestPointVisitor.getPoint();
603 linearVel = nearestPointVisitor.getLinearVelocity();
604 angularVel = nearestPointVisitor.getAngularVelocity();
605 material = nearestPointVisitor.getMaterial();
606 id = nearestPointVisitor.getId();
612 class FGGroundCache::WireIntersector : public BVHVisitor {
614 WireIntersector(const SGVec3d pt[4], const double& t) :
615 _linearVelocity(SGVec3d::zeros()),
616 _angularVelocity(SGVec3d::zeros()),
620 // Build the two triangles spanning the area where the hook has moved
621 // during the past step.
622 _triangles[0].set(pt[0], pt[1], pt[2]);
623 _triangles[1].set(pt[0], pt[2], pt[3]);
626 virtual void apply(BVHGroup& leaf)
628 if (!_intersects(leaf.getBoundingSphere()))
631 leaf.traverse(*this);
633 virtual void apply(BVHTransform& transform)
635 if (!_intersects(transform.getBoundingSphere()))
638 SGTriangled triangles[2] = { _triangles[0], _triangles[1] };
639 _triangles[0] = triangles[0].transform(transform.getToLocalTransform());
640 _triangles[1] = triangles[1].transform(transform.getToLocalTransform());
642 transform.traverse(*this);
645 _lineSegment = transform.lineSegmentToWorld(_lineSegment);
646 _linearVelocity = transform.vecToWorld(_linearVelocity);
647 _angularVelocity = transform.vecToWorld(_angularVelocity);
649 _triangles[0] = triangles[0];
650 _triangles[1] = triangles[1];
652 virtual void apply(BVHMotionTransform& transform)
654 if (!_intersects(transform.getBoundingSphere()))
657 SGMatrixd toLocal = transform.getToLocalTransform(_time);
659 SGTriangled triangles[2] = { _triangles[0], _triangles[1] };
660 _triangles[0] = triangles[0].transform(toLocal);
661 _triangles[1] = triangles[1].transform(toLocal);
663 transform.traverse(*this);
666 SGMatrixd toWorld = transform.getToWorldTransform(_time);
668 += transform.getLinearVelocityAt(_lineSegment.getStart());
669 _angularVelocity += transform.getAngularVelocity();
670 _linearVelocity = toWorld.xformVec(_linearVelocity);
671 _angularVelocity = toWorld.xformVec(_angularVelocity);
672 _lineSegment = _lineSegment.transform(toWorld);
674 _triangles[0] = triangles[0];
675 _triangles[1] = triangles[1];
677 virtual void apply(BVHLineGeometry& node)
679 if (node.getType() != BVHLineGeometry::CarrierWire)
681 SGLineSegmentd lineSegment(node.getLineSegment());
682 if (!_intersects(lineSegment))
685 _lineSegment = lineSegment;
686 _linearVelocity = SGVec3d::zeros();
687 _angularVelocity = SGVec3d::zeros();
690 virtual void apply(BVHStaticGeometry& node)
693 virtual void apply(const BVHStaticBinary&, const BVHStaticData&) { }
694 virtual void apply(const BVHStaticTriangle&, const BVHStaticData&) { }
696 bool _intersects(const SGSphered& sphere) const
700 if (intersects(_triangles[0], sphere))
702 if (intersects(_triangles[1], sphere))
706 bool _intersects(const SGLineSegmentd& lineSegment) const
710 if (intersects(_triangles[0], lineSegment))
712 if (intersects(_triangles[1], lineSegment))
717 const SGLineSegmentd& getLineSegment() const
718 { return _lineSegment; }
719 const SGVec3d& getLinearVelocity() const
720 { return _linearVelocity; }
721 const SGVec3d& getAngularVelocity() const
722 { return _angularVelocity; }
724 const BVHLineGeometry* getWire() const
728 SGLineSegmentd _lineSegment;
729 SGVec3d _linearVelocity;
730 SGVec3d _angularVelocity;
731 const BVHLineGeometry* _wire;
733 SGTriangled _triangles[2];
737 bool FGGroundCache::caught_wire(double t, const SGVec3d pt[4])
739 // Get the wire in question
740 WireIntersector wireIntersector(pt, t);
742 _localBvhTree->accept(wireIntersector);
744 _wire = wireIntersector.getWire();
748 class FGGroundCache::WireFinder : public BVHVisitor {
750 WireFinder(const BVHLineGeometry* wire, const double& t) :
753 _lineSegment(SGVec3d::zeros(), SGVec3d::zeros()),
754 _linearVelocity(SGVec3d::zeros()),
755 _angularVelocity(SGVec3d::zeros()),
756 _haveLineSegment(false)
759 virtual void apply(BVHGroup& leaf)
761 if (_haveLineSegment)
763 leaf.traverse(*this);
765 virtual void apply(BVHTransform& transform)
767 if (_haveLineSegment)
770 transform.traverse(*this);
772 if (_haveLineSegment) {
773 _linearVelocity = transform.vecToWorld(_linearVelocity);
774 _angularVelocity = transform.vecToWorld(_angularVelocity);
775 _lineSegment = transform.lineSegmentToWorld(_lineSegment);
778 virtual void apply(BVHMotionTransform& transform)
780 if (_haveLineSegment)
783 transform.traverse(*this);
785 if (_haveLineSegment) {
786 SGMatrixd toWorld = transform.getToWorldTransform(_time);
788 += transform.getLinearVelocityAt(_lineSegment.getStart());
789 _angularVelocity += transform.getAngularVelocity();
790 _linearVelocity = toWorld.xformVec(_linearVelocity);
791 _angularVelocity = toWorld.xformVec(_angularVelocity);
792 _lineSegment = _lineSegment.transform(toWorld);
795 virtual void apply(BVHLineGeometry& node)
797 if (_haveLineSegment)
801 if (node.getType() != BVHLineGeometry::CarrierWire)
803 _lineSegment = SGLineSegmentd(node.getLineSegment());
804 _linearVelocity = SGVec3d::zeros();
805 _angularVelocity = SGVec3d::zeros();
806 _haveLineSegment = true;
808 virtual void apply(BVHStaticGeometry&) { }
810 virtual void apply(const BVHStaticBinary&, const BVHStaticData&) { }
811 virtual void apply(const BVHStaticTriangle&, const BVHStaticData&) { }
813 const SGLineSegmentd& getLineSegment() const
814 { return _lineSegment; }
816 bool getHaveLineSegment() const
817 { return _haveLineSegment; }
819 const SGVec3d& getLinearVelocity() const
820 { return _linearVelocity; }
821 const SGVec3d& getAngularVelocity() const
822 { return _angularVelocity; }
825 const BVHLineGeometry* _wire;
828 SGLineSegmentd _lineSegment;
829 SGVec3d _linearVelocity;
830 SGVec3d _angularVelocity;
832 bool _haveLineSegment;
835 bool FGGroundCache::get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2])
837 // Fast return if we do not have an active wire.
841 // Get the wire in question
842 WireFinder wireFinder(_wire, t);
844 _localBvhTree->accept(wireFinder);
846 if (!wireFinder.getHaveLineSegment())
849 // prepare the returns
850 end[0] = wireFinder.getLineSegment().getStart();
851 end[1] = wireFinder.getLineSegment().getEnd();
853 // The linear velocity is the one at the start of the line segment ...
854 vel[0] = wireFinder.getLinearVelocity();
855 // ... so the end point has the additional cross product.
856 vel[1] = wireFinder.getLinearVelocity();
857 vel[1] += cross(wireFinder.getAngularVelocity(),
858 wireFinder.getLineSegment().getDirection());
863 void FGGroundCache::release_wire(void)