bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*)
 {
     if (ea.getEventType() == ea.KEYDOWN && ea.getKey() == _c)
     {
         osg::Vec3d world;
         _mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world);
         GeoPoint coords;
         coords.fromWorld(s_activeMap->getSRS(), world);
         osg::ref_ptr<ElevationEnvelope> env = s_activeMap->getElevationPool()->createEnvelope(s_activeMap->getSRS(), 23u);
         float ep_elev = env->getElevation(coords.x(), coords.y());
         OE_NOTICE << "Elevations under mouse. EP=" << ep_elev << "\n";
     }
     return false;
 }
Example #2
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;
}
Example #3
0
bool KeyboardHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    if(ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
    {
        if(ea.getKey() == 'w')
        {
            std::cout << "W pressed" << std::endl;

            return false;
        }
    }

    return false;
}
bool MYGUIManager::handleEvent(const osgGA::GUIEventAdapter& ea, bool async) const {
	if (async || !_platform || !_initialized) {
		const_cast<MYGUIManager*>(this)->pushEvent(&ea);
		return false;
	}

	int x = ea.getX(), y = ea.getY(), key = ea.getKey();
	static int z = 0;
	if (ea.getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS)
		y = ea.getWindowHeight() - y;

	x = int(floor(float(x) / _uiScale + 0.5f));
	y = int(floor(float(y) / _uiScale + 0.5f));

	switch (ea.getEventType())
	{
	case osgGA::GUIEventAdapter::PUSH:
		return MyGUI::InputManager::getInstance().injectMousePress(x, y, convertMouseButton(ea.getButton()));
		break;
	case osgGA::GUIEventAdapter::RELEASE:
		return MyGUI::InputManager::getInstance().injectMouseRelease(x, y, convertMouseButton(ea.getButton()));
		break;
	case osgGA::GUIEventAdapter::SCROLL:
		switch (ea.getScrollingMotion()) {
		case osgGA::GUIEventAdapter::SCROLL_UP:
			z++; break;
		case osgGA::GUIEventAdapter::SCROLL_DOWN:
			z--; break;
		}
		// fall through
	case osgGA::GUIEventAdapter::DRAG:
	case osgGA::GUIEventAdapter::MOVE:
		return MyGUI::InputManager::getInstance().injectMouseMove(x, y, z);
		break;
	case osgGA::GUIEventAdapter::KEYDOWN:
		if (key<127)
			return MyGUI::InputManager::getInstance().injectKeyPress(convertKeyCode(key), (char)key);
		else
			return MyGUI::InputManager::getInstance().injectKeyPress(convertKeyCode(key));
		break;
	case osgGA::GUIEventAdapter::KEYUP:
		return MyGUI::InputManager::getInstance().injectKeyRelease(convertKeyCode(key));
		break;
	case osgGA::GUIEventAdapter::RESIZE:
		_platform->getRenderManagerPtr()->setViewSize(
			int(floor(float(ea.getWindowWidth()) / _uiScale + 0.5f)),
			int(floor(float(ea.getWindowHeight()) / _uiScale + 0.5f)));
		break;
	default:
		break;
	}

	return false;
}
Example #5
0
 bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
 {
   if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
   {
     osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
     osgUtil::LineSegmentIntersector::Intersections hits;
     if ( view->computeIntersections( ea.getX(), ea.getY(), hits ) )
     {
       osgEarth::GeoPoint isectPoint;
       isectPoint.fromWorld( mGlobe->mapNode()->getMapSRS()->getGeodeticSRS(), hits.begin()->getWorldIntersectPoint() );
       mGlobe->showCurrentCoordinates( isectPoint );
     }
   }
   return false;
 }
    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/)
    {
        if (!_gt) return false;

        switch(ea.getEventType())
        {
        case(osgGA::GUIEventAdapter::KEYDOWN):
            {
                if (ea.getKey() == 'g')
                {
                    osg::notify(osg::NOTICE)<<"Gaussian"<<std::endl;
                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::GAUSSIAN);
                    return true;
                }
                else if (ea.getKey() == 's')
                {
                    osg::notify(osg::NOTICE)<<"Smooth"<<std::endl;
                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SMOOTH);
                    return true;
                }
                else if (ea.getKey() == 'S')
                {
                    osg::notify(osg::NOTICE)<<"Sharpen"<<std::endl;
                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SHARPEN);
                    return true;
                }
                else if (ea.getKey() == '+')
                {
                    _gt->setFilterWidth(_gt->getFilterWidth()*1.1);
                    osg::notify(osg::NOTICE)<<"Filter width = "<<_gt->getFilterWidth()<<std::endl;
                    return true;
                }
                else if (ea.getKey() == '-')
                {
                    _gt->setFilterWidth(_gt->getFilterWidth()/1.1);
                    osg::notify(osg::NOTICE)<<"Filter width = "<<_gt->getFilterWidth()<<std::endl;
                    return true;
                }
                else if (ea.getKey() == '>')
                {
                    _gt->setFilterBias(_gt->getFilterBias()+0.1);
                    osg::notify(osg::NOTICE)<<"Filter bias = "<<_gt->getFilterBias()<<std::endl;
                    return true;
                }
                else if (ea.getKey() == '<')
                {
                    _gt->setFilterBias(_gt->getFilterBias()-0.1);
                    osg::notify(osg::NOTICE)<<"Filter bias = "<<_gt->getFilterBias()<<std::endl;
                    return true;
                }
                break;
            }
        default:
            break;
        }
        return false;

    }
Example #7
0
bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
   switch(ea.getEventType())
   {
      case(osgGA::GUIEventAdapter::KEYDOWN):
      {
          switch(ea.getKey())
          {
             case '1':
                placeStreams(GRID_LAYOUT);
                return false;
                break;
             case '2':
                placeStreams(ROW_LAYOUT);
                return false;
                break;
             case '3':
                colorStreams(MEMORY_COLORING);
                return false;
                break;
             case '4':
                colorStreams(EXECUTION_FREQ_COLORING);
                return false;
                break;
             case 'h':
                hideByImage(HIDE);
                return false;
                break;
             case 'u':
                hideByImage(HIDE_ALL_ELSE);
                return false;
                break;
             case 'n':
                updateTimeline(1);
                return false;
                break;
             case 'p':
                updateTimeline(-1);
                return false;
                break;
             default:
                return false;
          }
      }
      default:
         return false;
   }
}
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;
	}
}
Example #9
0
bool WeaponHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{
 /*   osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
    if (!view) return false;
    
    osgViewer::ViewerBase* viewer = view->getViewerBase();
*/

 //   if (ea.getHandled()) return false;
	

    switch(ea.getEventType())
    {
	case(osgGA::GUIEventAdapter::RELEASE):
	//case(osgGA::GUIEventAdapter::DOUBLECLICK):
        {
           //shoot
		//	if(ea.getButtonMask() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
			{
				//if(osgGA::GUIEventAdapter::RELEASE == ea.getEventType())
				GameManager::instance()->getWeaponManager()->Tire();
			}	
            break;
        }

    default:
        break;

    }
    return false;
}
Example #10
0
void UFOManipulator::home(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us) 
{
    home(ea.getTime());
    us.requestRedraw();
    us.requestContinuousUpdate(false);

}
Example #11
0
bool CScreenCapture::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	osgViewer::ViewerBase* viewer = dynamic_cast<osgViewer::View*>(&aa)->getViewerBase();
	if (!viewer) return false;

	switch (ea.getEventType())
	{
	case (osgGA::GUIEventAdapter::FRAME) :
	{
		// Booleans aren't the best way of doing this, but I want to do
		// the actual adding here because I don't want to require
		// startCapture() take a viewer as argument, which could not be
		// the right one.
		if (_startCapture)
		{
			// Start capturing with the currently set number of frames.
			// If set to -1 it will capture continuously, if set to >0
			// it will capture that number of frames.
			_startCapture = false;
			addCallbackToViewer(*viewer);
		}
		else if (_stopCapture)
		{
			_stopCapture = false;
			removeCallbackFromViewer(*viewer);
		}
		break;
	}

	default:
		break;
	}
	return false;
}
Example #12
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;
    }
Example #13
0
        bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& )
        {
            if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN )
                return false;

            switch( ea.getKey() )
            {
                case 'x':
                    _gl2Scene->reloadShaderSource();
                    return true;
                case 'y':
                    _gl2Scene->toggleShaderEnable();
                    return true;
            }
            return false;
        }
bool OSGCameraManipulator::keyUp(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &aa)	{
	int bRes = true;

	int nResKey = ea.getKey();
	if ((nResKey ==	osgGA::GUIEventAdapter::KEY_Control_L) ||
		(nResKey ==	osgGA::GUIEventAdapter::KEY_Control_R))	{
			m_bCtrl = false;
	}

	if ((nResKey ==	osgGA::GUIEventAdapter::KEY_Shift_L) ||
		(nResKey ==	osgGA::GUIEventAdapter::KEY_Shift_R))	{
		m_bShift = false;
		m_dbDefaultMoveSpeed = 1;
	}

	if ((nResKey == osgGA::GUIEventAdapter::KEY_Up) ||
		(nResKey == osgGA::GUIEventAdapter::KEY_Down))	{
		m_dbForwardFactor = 0.0;
		m_dbLateralRotationRate = 0.0;
		m_dbDefaultMoveSpeed = 1;
	}

	if ((nResKey == osgGA::GUIEventAdapter::KEY_Left) ||
		(nResKey == osgGA::GUIEventAdapter::KEY_Right))	{
		m_dbDirectionRotationRate = 0.0;
		m_dbPitchOffsetRate = 0.0;
		m_dbDefaultMoveSpeed = 1;
	}

	return(bRes);
}
Example #15
0
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;
}
Example #16
0
void PickHandler::pick_measure(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea)
{

  
  
  osgUtil::LineSegmentIntersector::Intersections intersections;
  if (viewer->computeIntersections(ea.getX(), ea.getY(), intersections)){
    
    // use the nearest intersection                 
    const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin());
  
    (*measure_vertices)[1].set( intersection.getWorldIntersectPoint());
    // cout <<   (*measure_vertices)[1] <<endl;
}

}
void ViewerManipulator::handleKeypress(const osgGA::GUIEventAdapter& ea)
{
	if (ea.getKey()=='r')
	{
		sendEvent(user->s_name, "sfff", "setOrientation", 0.0, 0.0, 0.0, LO_ARGS_END);
	}
}
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;
   }
   
}
Example #19
0
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
    switch(ea.getEventType())
    { 

    case(osgGA::GUIEventAdapter::DOUBLECLICK):
    {
        if(measuring_tool_on){
            // if(ea.getButtonMask() ==GUIEventAdapter::MIDDLE_MOUSE_BUTTON){
            osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
            if (viewer) pick(viewer,ea);
            //      }
        }
        return false;
    }    
    case(osgGA::GUIEventAdapter::MOVE):
      {
	if(!measure_anchored)
	  return false;
      osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
	if (viewer ) pick_measure(viewer,ea);
	return false;
      }
 default:
      return false;
    }
}
Example #20
0
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;
	}
}
Example #21
0
/*!
 * 
 * \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;
}
bool MYGUIHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	// This only works under single-threaded mode
	switch (ea.getEventType()) {
	case osgGA::GUIEventAdapter::PUSH:
	case osgGA::GUIEventAdapter::RELEASE:
	case osgGA::GUIEventAdapter::SCROLL:
	case osgGA::GUIEventAdapter::DRAG:
	case osgGA::GUIEventAdapter::MOVE:
	case osgGA::GUIEventAdapter::KEYDOWN:
	case osgGA::GUIEventAdapter::KEYUP:
	{
		// check if there are any model window
		bool hasModal = false;
		if (_manager->_initialized) {
			hasModal = MyGUI::InputManager::getInstance().isModalAny();
		}
		return _manager->handleEvent(ea) || hasModal;
	}
	case osgGA::GUIEventAdapter::RESIZE:
		_manager->handleEvent(ea, true);
		return false;
	default:
		return false;
	}
}
Example #23
0
    virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
        {
            switch (ea.getKey())
            {
            case 65361:
                steerAngle += 0.1;
                break;
            case 65363:
                steerAngle -= 0.1;
                break;
            case 65362:
                gasPedal = 1.0;
                break;
            case 65364:
                brakePedal = 1.0;
                break;
            }
            return true;
        }
        else if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP)
        {
            switch (ea.getKey())
            {
            case 65362:
                gasPedal = 0.0;
                break;
            case 65364:
                brakePedal = 0.0;
                break;
            case 103:
                gear += 1;
                if (gear > 5)
                    gear = 5;
                break;
            case 102:
                gear -= 1;
                if (gear < -1)
                    gear = -1;
                break;
            }
            return true;
        }

        return false;
    }
Example #24
0
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
        {
            osg::Vec3 pos = osg::Vec3( lightPos[0], lightPos[1], lightPos[2] );
            osg::Matrixf view = osg::Matrixf::lookAt( pos, osg::Vec3( 0., 0., 0. ), osg::Vec3( 0., 0., 1. ) );
            osg::Matrixf proj = osg::Matrixf::perspective( 50., 1., 10., 80. );
            _shadowViewProj->set( view * proj );
            return( true );
        }

        else if( ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN )
        {
            switch( ea.getKey() )
            {
            case 'd':
            {
                bool v;
                _displayTC->get( v );
                _displayTC->set( !v );
                return( true );
            }
            case 'l':
            {
                lightPos[ 0 ] -= 1.;
                return( true );
            }
            case 'L':
            {
                lightPos[ 0 ] += 1.;
                return( true );
            }
            case 'k':
            {
                lightPos[ 1 ] -= 1.;
                return( true );
            }
            case 'K':
            {
                lightPos[ 1 ] += 1.;
                return( true );
            }
            }
        }

        return( false );
    }
	virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
		if (!level.valid()) return false;

		game::Polyhedron *poly = level->getSelectedPolyhedron();
		int dir = -1;

		switch (ea.getEventType()) {
		case osgGA::GUIEventAdapter::FRAME:
			level->update();
			return false;
		case osgGA::GUIEventAdapter::KEYDOWN:
			switch (ea.getKey()) {
			case osgGA::GUIEventAdapter::KEY_Up:
				dir = 0; break;
			case osgGA::GUIEventAdapter::KEY_Left:
				dir = 1; break;
			case osgGA::GUIEventAdapter::KEY_Down:
				dir = 2; break;
			case osgGA::GUIEventAdapter::KEY_Right:
				dir = 3; break;
			case osgGA::GUIEventAdapter::KEY_Space:
				if (!level->isAnimating()) level->switchToNextPolyhedron();
				break;
			default:
				return false;
			}
			if (dir >= 0) {
				osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
				osg::Camera* camera = viewer ? viewer->getCamera() : NULL;
				if (camera) {
					osg::Vec3 eye, center, up;
					camera->getViewMatrixAsLookAt(eye, center, up);
					eye = (eye - center) ^ up;
					if (eye.x() < eye.y()) {
						if (eye.x() + eye.y() > 0) dir += 3;
					} else if (eye.x() + eye.y() > 0) dir += 2;
					else dir += 1;
				}
				const game::MoveDirection dirs[4] = { MOVE_UP, MOVE_LEFT, MOVE_DOWN, MOVE_RIGHT };
				if (!level->isAnimating() && poly) poly->move(level.get(), dirs[dir & 3]);
			}
			break;
		default:
			return false;
		}
		return true;
	}
Example #26
0
bool OSGViewer::EventHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) {
    bool suppressDefault = false;
    osgGA::GUIEventAdapter::EventType t = ea.getEventType();
    // keypress handlers
    if (t == osgGA::GUIEventAdapter::KEYDOWN) {
      int key = ea.getKey();
      KeyCallbackMap::iterator it = key_cbs.find(key);
      if (it != key_cbs.end()) (it->second)(ea);
    }

    // general event handlers
    for (int i=0; i < event_cbs.size(); ++i) suppressDefault |= event_cbs[i](ea);


    if (suppressDefault) return false;
    else return osgGA::TrackballManipulator::handle(ea, aa);
}
Example #27
0
bool keyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
   bool newKeyDownEvent = false;
   bool newKeyUpEvent   = false;

   switch(ea.getEventType())
   {
   case(osgGA::GUIEventAdapter::KEYDOWN):
      {
         keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey());
         if (itr != keyFuncMap.end())
         {
            if ( (*itr).second.keyState == KEY_UP )
            {
               (*itr).second.keyState = KEY_DOWN;
               newKeyDownEvent = true;
            }
            if (newKeyDownEvent)
            {
               std::cout << ea.getKey() << "+";
               (*itr).second.keyFunction();
               newKeyDownEvent = false;
            }
            return true;
         }
         return false;
      }
   case(osgGA::GUIEventAdapter::KEYUP):
      {
         keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey());
         if (itr != keyFuncMap.end() )
         {
            (*itr).second.keyState = KEY_UP;
         }
         itr = keyUPFuncMap.find(ea.getKey());
         if (itr != keyUPFuncMap.end())
         {
            (*itr).second.keyFunction();
            return true;
         }
         return false; 
      }
   default:
      return false;
   }
}
bool OpenVREventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& ad)
{
	switch (ea.getEventType())
	{
		case osgGA::GUIEventAdapter::KEYUP:
		{
			switch (ea.getKey())
			{
				case osgGA::GUIEventAdapter::KEY_R:
					m_openvrDevice->resetSensorOrientation();
					break;
			}
		}
	}

	return osgGA::GUIEventHandler::handle(ea, ad);
}
Example #29
0
void OscSendingDevice::sendEvent(const osgGA::GUIEventAdapter &ea)
{
    static osc::int64 msg_id(0);
    bool msg_sent(false);
    unsigned int num_messages = _numMessagesPerEvent;
    
    if((ea.getEventType() == osgGA::GUIEventAdapter::DRAG) || (ea.getEventType() == osgGA::GUIEventAdapter::MOVE))
        num_messages = 1;
    
    for(unsigned int i = 0; i < num_messages; ++i) {
        msg_sent = sendEventImpl(ea, msg_id);
        if ((_delayBetweenSendsInMilliSecs > 0) && (i < num_messages-1))
            OpenThreads::Thread::microSleep(1000 * _delayBetweenSendsInMilliSecs);
    }
    if (msg_sent)
        msg_id++;
}
Example #30
0
    // handle keydown events
    virtual bool handle(const osgGA::GUIEventAdapter& ea,
                        osgGA::GUIActionAdapter&)
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN) {
            switch (ea.getKey()) {
            case 's':
                {
                    osg::Sequence::SequenceMode mode = _seq->getMode();
                    if (mode == osg::Sequence::STOP) {
                        mode = osg::Sequence::START;
                        std::cerr << "Start" << std::endl;
                    }
                    else if (mode == osg::Sequence::PAUSE) {
                        mode = osg::Sequence::RESUME;
                        std::cerr << "Resume" << std::endl;
                    }
                    else {
                        mode = osg::Sequence::PAUSE;
                        std::cerr << "Pause" << std::endl;
                    }
                    _seq->setMode(mode);
                }
                break;
            case 'l':
                {
                    osg::Sequence::LoopMode mode;
                    int begin, end;
                    _seq->getInterval(mode, begin, end);
                    if (mode == osg::Sequence::LOOP) {
                        mode = osg::Sequence::SWING;
                        std::cerr << "Swing" << std::endl;
                    }
                    else {
                        mode = osg::Sequence::LOOP;
                        std::cerr << "Loop" << std::endl;
                    }
                    _seq->setInterval(mode, begin, end);
                }
                break;
            default:
                break;
            }
        }

        return false;
    }