From c63f0e2fce333cc4e14c92708733570310eadd9b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 11 Jun 2004 20:57:36 +0000 Subject: [PATCH] Added checks against null to prevent crashes when the terrain manipulator is set up before a node has been attached. --- src/osgGA/TerrainManipulator.cpp | 117 +++++++++++++++++-------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/src/osgGA/TerrainManipulator.cpp b/src/osgGA/TerrainManipulator.cpp index efe1ef791..711c17b62 100644 --- a/src/osgGA/TerrainManipulator.cpp +++ b/src/osgGA/TerrainManipulator.cpp @@ -193,12 +193,22 @@ void TerrainManipulator::addMouseEvent(const GUIEventAdapter& ea) void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix) { + osg::Vec3 lookVector(- matrix(2,0),-matrix(2,1),-matrix(2,2)); osg::Vec3 eye(matrix(3,0),matrix(3,1),matrix(3,2)); osg::notify(INFO)<<"eye point "<getBound().radius()*0.1f; - osg::Vec3d start_segment = _center + getUpVector(coordinateFrame) * distance; - osg::Vec3d end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance); - - osg::notify(INFO)<<"start="< segLookVector = new osg::LineSegment; - segLookVector->set(start_segment,end_segment); - iv.addLineSegment(segLookVector.get()); - - _node->accept(iv); - - bool hitFound = false; - if (iv.hits()) + if (_node.valid()) { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segLookVector.get()); - if (!hitList.empty()) + + // now reorientate the coordinate frame to the frame coords. + CoordinateFrame coordinateFrame = getCoordinateFrame(_center); + + // need to reintersect with the terrain + osgUtil::IntersectVisitor iv; + + double distance = _node->getBound().radius()*0.1f; + osg::Vec3d start_segment = _center + getUpVector(coordinateFrame) * distance; + osg::Vec3d end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance); + + osg::notify(INFO)<<"start="< segLookVector = new osg::LineSegment; + segLookVector->set(start_segment,end_segment); + iv.addLineSegment(segLookVector.get()); + + _node->accept(iv); + + bool hitFound = false; + if (iv.hits()) { - notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); - _center = ip; + osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segLookVector.get()); + if (!hitList.empty()) + { + notify(INFO) << "Hit terrain ok"<< std::endl; + osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); + _center = ip; - hitFound = true; + hitFound = true; + } } - } - if (!hitFound) - { - // ?? - osg::notify(INFO)<<"TerrainManipulator unable to intersect with terrain."<