コード例 #1
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if ( ea.getEventType() == osgGA::GUIEventAdapter::RESIZE || _first )
        {
            osg::Camera* cam = aa.asView()->getCamera();
            if ( cam && cam->getViewport() )
            {
                const osg::Viewport* vp = cam->getViewport();
                if ( _first || vp->width() != _width || vp->height() != _height )
                {
                    _cs->setProjectionMatrix(osg::Matrix::ortho2D( 0, vp->width()-1, 0, vp->height()-1 ) );

                    ControlContext cx;
                    cx._vp = new osg::Viewport( 0, 0, vp->width(), vp->height() );
                    cx._viewContextID = aa.asView()->getCamera()->getGraphicsContext()->getState()->getContextID();
                    _cs->setControlContext( cx );

                    _width = vp->width();
                    _height = vp->height();
                }
                if ( vp->width() != 0 && vp->height() != 0 )
                {
                    _first = false;
                }
            }
        }
        return false;
    }
コード例 #2
0
ファイル: CameraManipulator.cpp プロジェクト: Cecko/3dsoftviz
/*!
 * 
 * \param ea
 * Adapter udalosti.
 * 
 * Metoda spomali pohyb na zaklade zdroja prijatej udalosti. 
 * 
 */
bool Vwr::CameraManipulator::handleKeyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter & us)
{
	switch( ea.getKey() )
	{
	case osgGA::GUIEventAdapter::KEY_Space:
	{
		flushMouseEventStack();
		_thrown = false;
		_distance = 1.0f;
		home(ea,us);
		us.requestRedraw();
		us.requestContinuousUpdate(false);

		stop();
		break;
	}
	case osgGA::GUIEventAdapter::KEY_Up:
	case osgGA::GUIEventAdapter::KEY_Down:
		decelerateForwardRate = true;
		break;

	case osgGA::GUIEventAdapter::KEY_Right:
	case osgGA::GUIEventAdapter::KEY_Left:
		decelerateSideRate = true;
		break;

	case osgGA::GUIEventAdapter::KEY_Page_Up:
	case osgGA::GUIEventAdapter::KEY_Page_Down:
		decelerateVerticalRate = true;
		break;
	}

	return true;
}
コード例 #3
0
ファイル: GISManipulator.cpp プロジェクト: hjanetzek/SFCGAL
bool GISManipulator::handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
    osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();

    osg::Vec3d eye, center, up;
    getTransformation( eye, center, up );
    double altitude = eye[2];

    if ( sm == osgGA::GUIEventAdapter::SCROLL_UP ) {
        altitude /= 1.41;
    }
    else if ( sm == osgGA::GUIEventAdapter::SCROLL_DOWN ) {
        altitude *= 1.41;
    }
    else {
        return false;
    }

    eye[2] = altitude;
    center[2] = eye[2] - 1.0;
    setTransformation( eye, center, up );

    us.requestRedraw();
    us.requestContinuousUpdate( isAnimating() );
    return true;
}
コード例 #4
0
ファイル: RTTPicker.cpp プロジェクト: Karamaz0V1/osgearth
bool
RTTPicker::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    if ( ea.getEventType() == ea.FRAME )
    {
        osg::FrameStamp* fs = aa.asView() ? aa.asView()->getFrameStamp() : 0L;
        if ( fs )
        {
            runPicks( fs->getFrameNumber() );           
        }

        // if there are picks in the queue, need to continuing rendering:
        if ( !_picks.empty() )
        {
            aa.requestRedraw();
        }
    }

    else if ( _defaultCallback.valid() && _defaultCallback->accept(ea, aa) )
    {        
        pick( aa.asView(), ea.getX(), ea.getY(), _defaultCallback.get() );
        aa.requestRedraw();
    }

    return false;
}
コード例 #5
0
ファイル: CameraManipulator.cpp プロジェクト: Cecko/3dsoftviz
bool Vwr::CameraManipulator::handlePush(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
	if (ea.getButtonMask() == GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
	{
		if (_distance != 0)
		{
			lastDistance = _distance;

			osg::Vec3d eye, cameraCenter, up;

			osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &us );
			viewer->getCamera()->getViewMatrixAsLookAt(eye, cameraCenter, up);

			_center = eye;
			_distance = 0;
		}
		else
		{
			_distance = lastDistance;
		}

		return true;
	}
	else
	{
		flushMouseEventStack();
		addMouseEvent(ea);
		if (calcMovement()) us.requestRedraw();
		us.requestContinuousUpdate(false);
		_thrown = false;
		return true;
	}
}
コード例 #6
0
bool OrbitCameraManipulator::handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();

	// TODO: increase scroll factor when eye is far away from model bounding sphere
	double scroll_distance_factor = ( m_eye - m_rotate_center ).length()*0.1;

	switch( sm )
	{
		// mouse scroll up event
	case osgGA::GUIEventAdapter::SCROLL_UP:
		{
			// perform zoom
			zoomCamera( m_wheel_zoom_factor*scroll_distance_factor );
			aa.requestRedraw();
			aa.requestContinuousUpdate( isAnimating() || _thrown );
			return true;
		}

		// mouse scroll down event
	case osgGA::GUIEventAdapter::SCROLL_DOWN:
		{
			// perform zoom
			zoomCamera( -m_wheel_zoom_factor*scroll_distance_factor );
			aa.requestRedraw();
			aa.requestContinuousUpdate( isAnimating() || _thrown );
			return true;
		}

		// unhandled mouse scrolling motion
	default:
		return false;
	}
}
コード例 #7
0
ファイル: UFOManipulator.cpp プロジェクト: aalex/osg
void UFOManipulator::home(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us) 
{
    home(ea.getTime());
    us.requestRedraw();
    us.requestContinuousUpdate(false);

}
コード例 #8
0
bool TerrainZoomManipulator::handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
    // no zooming by intersection is choosed
    if (! (_flags & 0x08))
    {
        setCenterByMousePointer(ea, us);
    }

    switch( ea.getScrollingMotion() )
    {
        // mouse scroll up event
        case osgGA::GUIEventAdapter::SCROLL_UP:
        {
            // perform zoom
            zoomModel( _wheelZoomFactor, true );
            us.requestRedraw();
            us.requestContinuousUpdate( isAnimating() || _thrown );
            return true;
        }

        // mouse scroll down event
        case osgGA::GUIEventAdapter::SCROLL_DOWN:

            zoomModel( -_wheelZoomFactor, true );
            us.requestRedraw();
            us.requestContinuousUpdate( false );
            return true;

        // unhandled mouse scrolling motion
        default:
            return false;
   }
   
}
コード例 #9
0
bool QueryCoordinatesHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
  if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
  {
    osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
    osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false );
    mGlobe->showCurrentCoordinates( coords.x(), coords.y() );
  }
  if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH
       && ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
  {
    osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
    osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false );

    OE_NOTICE << "SelectedCoordinates set to:\nLon: " << coords.x() << " Lat: " << coords.y()
    << " Ele: " << coords.z() << std::endl;

    mGlobe->setSelectedCoordinates( coords );

    if ( ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL )
      //ctrl + rightclick pops up a QMessageBox
    {
      mGlobe->showSelectedCoordinates();
    }
  }

  return false;
}
コード例 #10
0
ファイル: CameraManipulator.cpp プロジェクト: Cecko/3dsoftviz
bool Vwr::CameraManipulator::handleScroll(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
	addMouseEvent(ea);
	if (calcMovement()) us.requestRedraw();
	us.requestContinuousUpdate(false);
	_thrown = false;
	return true;
}
コード例 #11
0
bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    if (ea.getHandled()) return false;

    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
    if (!view) return false;

    if (ea.getEventType() == osgGA::GUIEventAdapter::PUSH)
    {
        Picker picker( view, this );
        Picker::Hits hits;

        if ( picker.pick( ea.getX(), ea.getY(), hits ) )
        {
            _dragging = true;
            aa.requestRedraw();
            return true;
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    {
        _dragging = false;
        aa.requestRedraw();
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
    {
        if (_dragging)
        {
            osg::Vec3d world;
            if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse(view, ea.getX(), ea.getY(), world) )
            {
                GeoPoint mapPoint;
                _mapNode->getMap()->worldPointToMapPoint(world, mapPoint);
                setPosition( mapPoint );
                aa.requestRedraw();
                return true;
            }
        }
    }   
    else if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
    {
        Picker picker( view, this );
        Picker::Hits hits;

        if ( picker.pick( ea.getX(), ea.getY(), hits ) )
        {
            setHover( true );
        }
        else
        {
            setHover( false );
        }        
        aa.requestRedraw();
    }
    return false;
}
コード例 #12
0
bool OrbitCameraManipulator::handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
	if( !view )	return false;

	if( ea.getButtonMask() == 0 )
	{
		double timeSinceLastRecordEvent = _ga_t0.valid() ? (ea.getTime() - _ga_t0->getTime()) : DBL_MAX;
		if( timeSinceLastRecordEvent > 0.02 )
		{
			flushMouseEventStack();
		}

		if( isMouseMoving() )
		{
			if( performMovement( ea, aa ) && _allowThrow )
			{
				aa.requestRedraw();
				aa.requestContinuousUpdate( true );
				_thrown = true;
				// TODO: fade out throw animation
			}

			return true;
		}
	}
	
	if( !m_pointer_push_drag )
	{
		// select object
		bool intersection_geometry_found = intersectSceneSelect( ea, view );

		if( !intersection_geometry_found )
		{
			// click to background -> unselect all
			if( m_system != nullptr )
			{
				m_system->clearSelection();
			}
			
		}
	}
	m_pointer_push_drag = false;

	flushMouseEventStack();
	addMouseEvent( ea );
	if( performMovement( ea, aa ) )
	{
		aa.requestRedraw();
	}
	aa.requestContinuousUpdate( false );
	_thrown = false;

	return true;
}
コード例 #13
0
ファイル: WeaponHUD.cpp プロジェクト: goost/BrainTrain
    bool WeaponHUD::WeaponSwitchHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
        switch (ea.getEventType()) {
        case osgGA::GUIEventAdapter::SCROLL:
        {
	  /*
	   * catches multiple activations of the weapon switching
	   * per frame because linux triggers keys twice
	   */
            if (_frameNumber == aa.asView()->getFrameStamp()->getFrameNumber()) {
                return false;
            }
            _frameNumber = aa.asView()->getFrameStamp()->getFrameNumber();
	    //Debug message
            OSG_ALWAYS << "SCROLL: " << aa.asView()->getFrameStamp()->getFrameNumber() << std::endl;
            osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();
            switch (sm) {
            /*
	     * switches backwards through weapon list when
	     * the mouse wheel is scrolled down
	     */
            case osgGA::GUIEventAdapter::SCROLL_DOWN:
	    //Debug message
	      OSG_ALWAYS << "SCROLL DOWN" << std::endl;
		_switch->setValue(_curWeapon, false);
                _curWeapon--;
                /*
		 * if the first weapon is selected and another
		 * scroll backwards is triggered, the last weapon
		 * gets selected
		 */
		if (_curWeapon < 0)
                    _curWeapon = _switch->getNumChildren() - 1;
                _curWeapon = _curWeapon % _switch->getNumChildren();
                _switch->setValue(_curWeapon, true);
                return true;
	    /*
	     * switches forward through weapon list when
	     * the mouse wheel is scrolled up
	     */
	    case osgGA::GUIEventAdapter::SCROLL_UP:
	      //Debug message
                OSG_ALWAYS << "SCROLL UP" << std::endl;
                _switch->setValue(_curWeapon, false);
                _curWeapon++;
                _curWeapon = _curWeapon % _switch->getNumChildren();
                _switch->setValue(_curWeapon, true);
                return true;
            default:
                return false;
            }
        }
        default:
            return false;
        }
    }
コード例 #14
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&
            aa.asView()->getFrameStamp()->getFrameNumber() % 10 == 0)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
        }

        return false;
    }
コード例 #15
0
bool OrbitCameraManipulator::handleMouseDrag( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	addMouseEvent( ea );

	m_pointer_push_drag = true;
	if( performMovement( ea, aa ) )
	{
		aa.requestRedraw();
	}

	aa.requestContinuousUpdate( false );
	_thrown = false;

	return true;
}
コード例 #16
0
bool Start::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	m_control->clearDrawing();

	if ((ea.getEventType() == ea.PUSH) && (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON))
	{
		m_control->clearDrawing();
		osgUtil::LineSegmentIntersector::Intersections results;
		osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
		if (view->computeIntersections(ea.getX(), ea.getY(), results, 0x01))
		{
			// find the first hit under the mouse:
			osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
			osg::Vec3d point = first.getWorldIntersectPoint();

			// transform it to map coordinates:
			osg::Vec3d newPoint;
			m_control->getMapNode()->getMap()->worldPointToMapPoint(point, newPoint);
			m_control->setFirstPoint(newPoint);
			m_control->currentState() = new  FirstSelected(m_control);

			return (true);
		}
	}
	return (false);
}
コード例 #17
0
bool WaitingForSecondSelection::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	bool handled = false;

	osgUtil::LineSegmentIntersector::Intersections results;
	osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
	if ((ea.getEventType() == ea.DRAG) && view->computeIntersections(ea.getX(), ea.getY(), results, 0x01))
	{
		// find the first hit under the mouse:
		osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
		osg::Vec3d point = first.getWorldIntersectPoint();

		// transform it to map coordinates:
		osg::Vec3d newPoint;
		m_control->getMapNode()->getMap()->worldPointToMapPoint(point, newPoint);
		m_control->setSecondPoint(newPoint);
		m_control->drawRectangle();
	}
	else if ((ea.getEventType() == ea.DOUBLECLICK) && (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON))
	{
		m_control->currentState() = new Complete(m_control);
		handled = true;
	}

	return (handled);
}
コード例 #18
0
ファイル: stats.cpp プロジェクト: Thoronador/openmw
bool StatsHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{
    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::KEYDOWN):
        {
            if (ea.getKey()== _key)
            {
                osgViewer::View* myview = dynamic_cast<osgViewer::View*>(&aa);
                if (!myview) return false;

                osgViewer::ViewerBase* viewer = myview->getViewerBase();

                toggle(viewer);

                aa.requestRedraw();
                return true;
            }
            break;
        }
        case osgGA::GUIEventAdapter::RESIZE:
        {
            setWindowSize(ea.getWindowWidth(), ea.getWindowHeight());
            break;
        }
        default:
            break;
    }
    return false;
}
コード例 #19
0
      bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
      {
          if (ea.getEventType() == ea.PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
          {
              osg::Vec3d world;
              if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse( aa.asView(), ea.getX(), ea.getY(), world ))
              {
                  GeoPoint mapPoint;
                  _mapNode->getMap()->worldPointToMapPoint( world, mapPoint );

                  if (!_startValid)
                  {
                      _startValid = true;
                      _start = mapPoint.vec3d();
                      if (_featureNode.valid())
                      {
                          _root->removeChild( _featureNode.get() );
                          _featureNode = 0;
                      }
                  }
                  else
                  {
                      _end = mapPoint.vec3d();
                      compute();
                      _startValid = false;                    
                  }
              }        
          }
          return false;
      }
コード例 #20
0
bool
AddPointHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
    if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH )
    {
        if (ea.getButton() == _mouseButton)
        {
            _mouseDown = true;
            _firstMove = true;
            return addPoint( ea.getX(), ea.getY(), view );
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    {
        if (ea.getButton() == _mouseButton)
        {
            _mouseDown = false;
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE || ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
    {
        if (_mouseDown)
        {
            if (!_firstMove)
            {
                return addPoint( ea.getX(), ea.getY(), view );
            }
            _firstMove = false;
        }
        return true;
    }

    return false;
}
コード例 #21
0
void InputEventHandler::MouseMove(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	int x0 = ea.getXmin();
	int y0 = ea.getYmin();
	int x1 = ea.getXmax();
	int y1 = ea.getYmax();

	int centerX = (x0 + x1) / 2;
	int centerY = (y0 + y1) / 2;

	if (!m_cursorOn) {
		if (!((ea.getX() == centerX) && (ea.getY() == centerY))) {
			m_mouseX0 = centerX;
			m_mouseY0 = centerY;
			m_mouseX1 = ea.getX();
			m_mouseY1 = ea.getY();
			aa.requestWarpPointer (centerX, centerY);
		}
	} else {
		if (m_mouseMoveCount > (m_frameCount - 64)) {
			// track mouse inside frame window
			m_mouseX0 = m_mouseX1;
			m_mouseY0 = m_mouseY1;
			m_mouseX1 = ea.getX();
			m_mouseY1 = ea.getY();
		}
	}
	m_mouseMoveCount = m_frameCount;
}
コード例 #22
0
bool OrbitCameraManipulator::performAnimationMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	double f = (ea.getTime() - m_animation_data->_startTime) / m_animation_data->_animationTime;
    if( f >= 1. )
    {
        f = 1.;
        m_animation_data->_isAnimating = false;
        if( !_thrown )
            aa.requestContinuousUpdate( false );
    }

    applyAnimationStep( f, m_animation_data->_phase );

    m_animation_data->_phase = f;
    aa.requestRedraw();

    return m_animation_data->_isAnimating;
}
コード例 #23
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
        }

        return false;
    }
コード例 #24
0
void
AutoClipPlaneHandler::frame( osgGA::GUIActionAdapter& aa )
{
    osg::Camera* cam = aa.asView()->getCamera();

    if ( _rp < 0 )
    {
        osg::ref_ptr<MapNode> tempNode = osgEarth::findTopMostNodeOfType<MapNode>( cam );
        if ( tempNode.valid() && tempNode->getMap()->getProfile() )
        {
            _geocentric = tempNode->getMap()->isGeocentric();
            if ( _geocentric )
                _rp = tempNode->getMap()->getProfile()->getSRS()->getEllipsoid()->getRadiusPolar();
            else
                OE_INFO << "[AutoClipPlaneHandler] disabled for non-geocentric map" << std::endl;

            //_mapNode = tempNode.get();
        }
    }

    if ( _rp > 0 && _geocentric ) // _mapNode.valid() && _geocentric )
    {
        cam->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

        osg::Vec3d eye, center, up;
        cam->getViewMatrixAsLookAt( eye, center, up );

        double d = eye.length();

        if ( d < _rp )
            d = _rp;

        if ( d > _rp )
        {
            double fovy, ar, znear, zfar, finalZfar;
            cam->getProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar );

            // far clip at the horizon:
            zfar = sqrt( d*d - _rp*_rp );

            if (_autoFarPlaneClipping)
            {
                finalZfar = zfar;
            }

            double nfr = _nfrAtRadius + _nfrAtDoubleRadius * ((d-_rp)/d);
            znear = osg::clampAbove( zfar * nfr, 1.0 );

            cam->setProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar );

            //OE_NOTICE << fixed
            //    << "near=" << znear << ", far=" << zfar << std::endl;
        }
    }
}
コード例 #25
0
ファイル: MouseCoordsTool.cpp プロジェクト: ldelgass/osgearth
bool
MouseCoordsTool::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
    {
        osg::Vec3d world;
        if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world) )
        {
            GeoPoint map;
            map.fromWorld( _mapNode->getMapSRS(), world );

            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->set( map, aa.asView(), _mapNode );
        }
        else
        {
            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->reset( aa.asView(), _mapNode );
        }

#if 1 // testing AGL, Dist to Point
        osg::Vec3d eye, center, up;
        aa.asView()->getCamera()->getViewMatrixAsLookAt(eye, center, up);
        DPLineSegmentIntersector* lsi = new DPLineSegmentIntersector(eye, osg::Vec3d(0,0,0));
        osgUtil::IntersectionVisitor iv(lsi);
        lsi->setIntersectionLimit(lsi->LIMIT_NEAREST);
        //iv.setUserData( new Map() );
        _mapNode->accept(iv);

        if ( !lsi->getIntersections().empty() )
        {            
            double agl = (eye - lsi->getFirstIntersection().getWorldIntersectPoint()).length();
            double dtp = (eye - world).length();
            //OE_NOTICE << "AGL = " << agl << "m; DPT = " << dtp << "m" << std::endl;
            Registry::instance()->startActivity("AGL", Stringify() << agl << " m");
            Registry::instance()->startActivity("Range", Stringify() << dtp << " m");
        }
#endif
    }

    return false;
}
コード例 #26
0
bool CameraManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::FRAME):
        {
			return handleFrame(ea, us);
        }
        default:
            break;
    }

    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::PUSH):
        {
			return handlePush(ea, us);
        }
        case(osgGA::GUIEventAdapter::RELEASE):
        {
            return handleRelease(ea, us);
        }
        case(osgGA::GUIEventAdapter::DRAG):
        case(osgGA::GUIEventAdapter::SCROLL):
        {
			return handleScroll(ea, us);
        }
        case(osgGA::GUIEventAdapter::MOVE):
        {
            return false;
        }
		case(osgGA::GUIEventAdapter::KEYDOWN):
		{
			return handleKeyDown(ea, us);
		}
		case(osgGA::GUIEventAdapter::KEYUP):
		{
			return handleKeyUp( ea, us );
		}
        case(osgGA::GUIEventAdapter::FRAME):
		{
            if (_thrown)
            {
                if (calcMovement()) us.requestRedraw();
            }

            return false;
		}
        default:
            return false;
    }
}
コード例 #27
0
bool Vwr::CameraManipulator::handleRelease(const osgGA::GUIEventAdapter& ea,
		osgGA::GUIActionAdapter& us) {
	if (ea.getButtonMask() == 0) {

		double timeSinceLastRecordEvent = _ga_t0.valid() ? (ea.getTime()
				- _ga_t0->getTime()) : DBL_MAX;
		if (timeSinceLastRecordEvent > 0.02)
			flushMouseEventStack();

		if (isMouseMoving()) {
			if (calcMovement()) {
				us.requestRedraw();
				us.requestContinuousUpdate(true);
				_thrown = _allowThrow;
			}
		} else {
			flushMouseEventStack();
			addMouseEvent(ea);
			if (calcMovement())
				us.requestRedraw();
			us.requestContinuousUpdate(false);
			_thrown = false;
		}

	} else {
		flushMouseEventStack();
		addMouseEvent(ea);
		if (calcMovement())
			us.requestRedraw();
		us.requestContinuousUpdate(false);
		_thrown = false;
	}
	return true;
}
コード例 #28
0
bool ThirdPersonCameraManipulator::handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{

	/// At the moment, OSG doesn't have support for extra mouse buttons, but I plan to add that later, at which point you'll be able to zoom with the forwards and backwards buttons (if you have them)
	switch(ea.getButton())
	{
#ifdef SUPPORTS_EXTRA_MOUSE_BUTTONS
	case osgGA::GUIEventAdapter::FORWARD_MOUSE_BUTTON :
		zoom(_zoomFactor);
		aa.requestRedraw();
		return true;
	case osgGA::GUIEventAdapter::BACKWARD_MOUSE_BUTTON :
		zoom(-_zoomFactor);
		aa.requestRedraw();
		return true;
#endif
	default:
		return false;
	}

	return false;
}
コード例 #29
0
ファイル: ViewerEventHandlers.cpp プロジェクト: yueying/osg
bool LODScaleHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
    osg::Camera* camera = view ? view->getCamera() : 0;
    if (!camera) return false;

    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::KEYUP):
        {
            if (ea.getKey() == _keyEventIncreaseLODScale)
            {
                camera->setLODScale(camera->getLODScale()*1.1);
                OSG_NOTICE<<"LODScale = "<<camera->getLODScale()<<std::endl;

                aa.requestRedraw();
                return true;
            }

            else if (ea.getKey() == _keyEventDecreaseLODScale)
            {
                camera->setLODScale(camera->getLODScale()/1.1);
                OSG_NOTICE<<"LODScale = "<<camera->getLODScale()<<std::endl;

                aa.requestRedraw();
                return true;
            }

            break;
        }
    default:
        break;
    }

    return false;
}
コード例 #30
0
// mouse button has been pushed down
bool OrbitCameraManipulator::handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
	if( !view )
	{
		return false;
	}

	m_pointer_push_drag = false;
	flushMouseEventStack();
	addMouseEvent( ea );
	m_ga_pointer_push = &ea;

	intersectSceneRotateCenter( ea, view );

	int buttonMask = ea.getButtonMask();
	if( buttonMask == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON || buttonMask == (osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON | osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) )
	{
		m_pan_point.set( m_pointer_intersection );
	}
	
	if( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
	{
		osg::Vec3d distance_intersect_eye( m_pointer_intersection - m_eye );
		//double distance_eye_intersection = distance_intersect_eye.length();

		// rotate the intersection cone into mouse ray direction
		if( m_intersect_hit_geometry )
		{

		}
	}
	aa.requestRedraw();
	aa.requestContinuousUpdate( false );
	_thrown = false;

	return false;
}