Changeset 8999

Show
Ignore:
Timestamp:
10/07/08 16:19:28 (6 years ago)
Author:
robert
Message:

Replaced IntersectVisitor? usage with IntersectionVisitor?

Location:
OpenSceneGraph/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgGA/UFOManipulator

    r7730 r8999  
    2121#include <osg/Matrix> 
    2222 
    23     /** 
    24       \class osgGA::UFOManipulator 
    25       \brief A UFO manipulator driven with keybindings. 
     23/** 
     24  \class osgGA::UFOManipulator 
     25  \brief A UFO manipulator driven with keybindings. 
    2626 
    27       The UFOManipulator is better suited for applications that employ  
    28       architectural walk-throughs, or situations where the eyepoint motion 
    29       model must move slowly, deliberately and well controlled.   
     27  The UFOManipulator is better suited for applications that employ  
     28  architectural walk-throughs, or situations where the eyepoint motion 
     29  model must move slowly, deliberately and well controlled.   
    3030 
    31       The UFO Manipulator allows the following movements with the listed 
    32       Key combinations: 
    33         \param UpArrow          Acceleration forward. 
    34         \param DownArrow        Acceleration backward (or deceleration forward). 
    35         \param LeftArrow        Rotate view and direction of travel to the left. 
    36         \param RightArrow       Rotate view and direction of travel to the right. 
    37         \param SpaceBar         Brake.  Gradually decelerates linear and rotational movement. 
    38         \param Shift/UpArrow    Accelerate up. 
    39         \param Shift/DownArrow  Accelerate down. 
    40         \param Shift/LeftArrow  Accelerate (linearly) left. 
    41         \param Shift/RightArrow Accelerate (linearly) right. 
    42         \param Shift/SpaceBar   Instant brake.  Immediately stop all linear and rotational movement. 
     31  The UFO Manipulator allows the following movements with the listed 
     32  Key combinations: 
     33    \param UpArrow          Acceleration forward. 
     34    \param DownArrow        Acceleration backward (or deceleration forward). 
     35    \param LeftArrow        Rotate view and direction of travel to the left. 
     36    \param RightArrow       Rotate view and direction of travel to the right. 
     37    \param SpaceBar         Brake.  Gradually decelerates linear and rotational movement. 
     38    \param Shift/UpArrow    Accelerate up. 
     39    \param Shift/DownArrow  Accelerate down. 
     40    \param Shift/LeftArrow  Accelerate (linearly) left. 
     41    \param Shift/RightArrow Accelerate (linearly) right. 
     42    \param Shift/SpaceBar   Instant brake.  Immediately stop all linear and rotational movement. 
    4343 
    44     When the Shift key is released, up, down, linear left and/or linear right movement is decelerated. 
     44When the Shift key is released, up, down, linear left and/or linear right movement is decelerated. 
    4545 
    46         \param Ctrl/UpArrow     Rotate view (but not direction of travel) up. 
    47         \param Ctrl/DownArrow   Rotate view (but not direction of travel) down. 
    48         \param Ctrl/LeftArrow   Rotate view (but not direction of travel) left. 
    49         \param Ctrl/RightArrow  Rotate view (but not direction of travel) right. 
    50         \param Ctrl/Return      Straightens out the view offset. 
     46    \param Ctrl/UpArrow     Rotate view (but not direction of travel) up. 
     47    \param Ctrl/DownArrow   Rotate view (but not direction of travel) down. 
     48    \param Ctrl/LeftArrow   Rotate view (but not direction of travel) left. 
     49    \param Ctrl/RightArrow  Rotate view (but not direction of travel) right. 
     50    \param Ctrl/Return      Straightens out the view offset. 
    5151 
    52     */ 
     52*/ 
    5353 
    5454namespace osgGA { 
     
    130130 
    131131    protected: 
     132 
     133        virtual ~UFOManipulator(); 
     134 
     135        bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const; 
     136 
    132137        osg::ref_ptr<osg::Node> _node; 
    133138        float       _viewAngle; 
  • OpenSceneGraph/trunk/src/osgGA/NodeTrackerManipulator.cpp

    r8038 r8999  
    1616#include <osg/Notify> 
    1717#include <osg/Transform> 
    18 #include <osgUtil/IntersectVisitor> 
    1918 
    2019using namespace osg; 
  • OpenSceneGraph/trunk/src/osgGA/TerrainManipulator.cpp

    r8710 r8999  
    1616#include <osg/Notify> 
    1717#include <osg/io_utils> 
    18 #include <osgUtil/IntersectVisitor> 
    1918#include <osgUtil/LineSegmentIntersector> 
    2019 
  • OpenSceneGraph/trunk/src/osgGA/UFOManipulator.cpp

    r7730 r8999  
     1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
     2 * 
     3 * This library is open source and may be redistributed and/or modified under 
     4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
     5 * (at your option) any later version.  The full license is in LICENSE file 
     6 * included with this distribution, and on the openscenegraph.org website. 
     7 * 
     8 * This library is distributed in the hope that it will be useful, 
     9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     11 * OpenSceneGraph Public License for more details. 
     12*/ 
     13 
     14/* Written by Don Burns */ 
     15 
    116#include <osgGA/UFOManipulator> 
    2 #include <osgUtil/IntersectVisitor> 
     17#include <osgUtil/LineSegmentIntersector> 
    318 
    419#include <osg/io_utils> 
     
    4358} 
    4459 
     60UFOManipulator::~UFOManipulator() 
     61{ 
     62} 
     63 
     64bool UFOManipulator::intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const 
     65{ 
     66    osg::ref_ptr<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(start,end); 
     67 
     68    osgUtil::IntersectionVisitor iv(lsi.get()); 
     69    iv.setTraversalMask(_intersectTraversalMask); 
     70     
     71    _node->accept(iv); 
     72     
     73    if (lsi->containsIntersections()) 
     74    { 
     75        intersection = lsi->getIntersections().begin()->getWorldIntersectPoint(); 
     76        return true; 
     77    } 
     78    return false; 
     79} 
     80 
    4581void UFOManipulator::setNode( osg::Node *node ) 
    4682{ 
     
    116152       * from a line segment extending from above to below the database at its  
    117153       * horizontal center, that intersects the database closest to zero. */ 
    118     osgUtil::IntersectVisitor iv; 
    119     iv.setTraversalMask(_intersectTraversalMask); 
    120154 
    121155    osg::CoordinateFrame cf( getCoordinateFrame(bs.center()) ); // not sure what position to use here 
    122156    osg::Vec3d upVec( getUpVector(cf) ); 
    123     osg::ref_ptr<osg::LineSegment> seg = new osg::LineSegment; 
     157 
    124158    osg::Vec3 A = bs.center() + (upVec*(bs.radius()*2)); 
    125159    osg::Vec3 B = bs.center() + (-upVec*(bs.radius()*2)); 
     
    130164    } 
    131165 
    132     /* 
    133     seg->set( bs.center() + (upVec*(bs.radius()*2)),  
    134               bs.center() + (-upVec*(bs.radius()*2)) ); 
    135               */ 
    136     seg->set( A, B ); 
    137  
    138     iv.addLineSegment( seg.get() ); 
    139     _node->accept(iv); 
    140  
    141166    // start with it high 
    142167    double ground = bs.radius() * 3; 
    143168 
    144     if (iv.hits()) 
    145     { 
    146         osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(seg.get()); 
    147         osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); 
     169    osg::Vec3d ip; 
     170    if (intersect(A, B, ip)) 
     171    { 
    148172        double d = ip.length(); 
    149173        if( d < ground ) 
     
    511535        return; 
    512536 
    513     osgUtil::IntersectVisitor iv; 
    514     iv.setTraversalMask(_intersectTraversalMask); 
    515  
    516537    // Forward line segment at 3 times our intersect distance 
    517     osg::ref_ptr<osg::LineSegment> segForward = new osg::LineSegment; 
    518     segForward->set(_position, _position + (_direction * (_minDistanceInFront * 3.0)) ); 
    519     iv.addLineSegment( segForward.get() ); 
    520  
    521  
    522     // Down line segment at 3 times our intersect distance 
     538 
     539 
     540    typedef std::vector<osg::Vec3d> Intersections; 
     541    Intersections intersections; 
     542 
     543    // Check intersects infront. 
     544    osg::Vec3d ip; 
     545    if (intersect(_position,  
     546                  _position + (_direction * (_minDistanceInFront * 3.0)), 
     547                  ip )) 
     548    { 
     549        double d = (ip - _position).length(); 
     550 
     551        if( d < _minDistanceInFront ) 
     552        { 
     553            _position = ip + (_direction * -_minDistanceInFront); 
     554            _stop(); 
     555        } 
     556    } 
     557     
     558    // Check intersects below. 
    523559    osg::CoordinateFrame cf( getCoordinateFrame(_position) ); 
    524560    osg::Vec3d upVec( getUpVector(cf) ); 
    525     osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment; 
    526     segDown->set(   _position,  
    527                     _position - upVec*_minHeightAboveGround*3); 
    528     iv.addLineSegment( segDown.get() ); 
    529  
    530     _node->accept(iv); 
    531  
    532     if (iv.hits()) 
    533     { 
    534         // Check intersects infront. 
    535         { 
    536             osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segForward.get()); 
    537             if (!hitList.empty()) 
    538             { 
    539                 osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); 
    540  
    541                 double d = (ip - _position).length(); 
    542              
    543                 if( d < _minDistanceInFront ) 
    544                 { 
    545                     _position = ip + (_direction * -_minDistanceInFront); 
    546                     _stop(); 
    547                 } 
    548             } 
    549         } 
    550  
    551         // Check intersects below. 
    552         { 
    553             osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); 
    554             if (!hitList.empty()) 
    555             { 
    556                 osg::Vec3d ip = hitList.front().getWorldIntersectPoint(); 
    557                 double d = (ip - _position).length(); 
    558              
    559                 if( d < _minHeightAboveGround ) 
    560                   _position = ip + (upVec * _minHeightAboveGround); 
    561             } 
    562         } 
    563  
     561 
     562    if (intersect(_position,  
     563                  _position - upVec*_minHeightAboveGround*3,  
     564                  ip )) 
     565    { 
     566        double d = (ip - _position).length(); 
     567 
     568        if( d < _minHeightAboveGround ) 
     569          _position = ip + (upVec * _minHeightAboveGround); 
    564570    } 
    565571}