Esempio n. 1
0
//事件处理函数
bool CPickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
	switch(ea.getEventType())
	{
		//每一帧
	case(osgGA::GUIEventAdapter::FRAME):
		{
			osg::ref_ptr<osgViewer::Viewer> viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
			//得到视图矩阵
			viewer ->getCamera() ->getViewMatrixAsLookAt(position, center, up) ;
			if (viewer)
			{	
				//执行PICK动作
				pick(viewer.get(),ea);
			}
			return false;
		}    
	default:
		return false;
	}

}
Esempio n. 2
0
		virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*)
		{
			osgViewer::Viewer* viewer=dynamic_cast<osgViewer::Viewer*>(&aa);
			if (!viewer)
			{
				return false;
			}
			switch(ea.getEventType())
			{
			case osgGA::GUIEventAdapter::KEYDOWN:
				/*if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Space)
				{
					int width=ea.getWindowWidth();
					int height=ea.getWindowHeight();
					viewer->requestWarpPointer(width*0.7,height*0.7);
				}else*/
				{
					osg::Switch* root = dynamic_cast<osg::Switch*>(viewer->getSceneData());
					if (!root)
					{
						return false;
					}
					if (ea.getKey()=='1')
					{
						root->setValue(0,true);
						root->setValue(1,false);
					}
					else if (ea.getKey()=='2')
					{
						root->setValue(0,false);
						root->setValue(1,true);
					}
				}
				break;
			default:
				break;
			}
			return false;
		}
    bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object*, osg::NodeVisitor* /*nv*/)
    {
        switch(ea.getEventType())
        {
            case(osgGA::GUIEventAdapter::KEYDOWN):
                {
                    if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Left)
                        loadSlide(_currentFile - 1);
                    else if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Right)
                        loadSlide(_currentFile + 1);
                    else
                        return false;

                    return true;
                }
                break;
            default:
                break;
        }

        return false;
    }
Esempio n. 4
0
    bool handle( const osgGA::GUIEventAdapter& ea,
            osgGA::GUIActionAdapter& aa )
    {
        osgViewer::Viewer* viewer =
                dynamic_cast<osgViewer::Viewer*>( &aa );
        if (!viewer)
            return false;

        switch( ea.getEventType() )
        {
            case osgGA::GUIEventAdapter::PUSH:
            case osgGA::GUIEventAdapter::MOVE:
            {
                // Record mouse location for the button press
                //   and move events.
                _mX = ea.getX();
                _mY = ea.getY();
                return false;
            }
            case osgGA::GUIEventAdapter::RELEASE:
            {
                // If the mouse hasn't moved since the last
                //   button press or move event, perform a
                //   pick. (Otherwise, the trackball
                //   manipulator will handle it.)
                if (_mX == ea.getX() && _mY == ea.getY())
                {
                    if (pick( ea.getXnormalized(),
                                ea.getYnormalized(), viewer ))
                        return true;
                }
                return false;
            }    

            default:
                return false;
        }
    }
Esempio n. 5
0
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;
}
bool OsgKeyboardHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
{
	bool result = false;

	switch (ea.getEventType())
	{
		case (osgGA::GUIEventAdapter::KEYDOWN) :
			{
				// Note that we are setting the modifier mask here instead of the modifier itself
				m_keyboardScaffold.lock()->updateDevice(ea.getUnmodifiedKey(), ea.getModKeyMask());
				result = true;
				break;
			}
		case (osgGA::GUIEventAdapter::KEYUP) :
			{
				m_keyboardScaffold.lock()->updateDevice(KeyCode::NONE, ModKeyMask::MODKEY_NONE);
				result = true;
				break;
			}
		default:
			result = false;
			break;
	}

	// We wan to to support some of the osg viewer keys, pass these through, we will still receive the event, but osg
	// will also react here
	int key = ea.getUnmodifiedKey();
	if (key == 's' || key == 't' || key == 'v' || key == 'w')
	{
		// s: Stats Display
		// t: texturing
		// v: vsync
		// w: wireframe
		result = false;
	}

	return result;
}
bool OSGCameraManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)	{
	bool bRes = true;

	int nResEvent = ea.getEventType();

	//Orbit manipulator
	if(nResEvent == GUIEventAdapter::EventType::DRAG ||
		GUIEventAdapter::EventType::MOVE ||
		GUIEventAdapter::EventType::PUSH ||
		GUIEventAdapter::EventType::RELEASE ||
		GUIEventAdapter::EventType::SCROLL) {

			bRes = OrbitManipulator::handle(ea,us);
	}

	if(nResEvent == GUIEventAdapter::KEYDOWN) {
		bRes = keyDown(ea, us);
	}
	else if(nResEvent == GUIEventAdapter::KEYUP)	{
		bRes = keyUp(ea, us);
	}
	return(bRes);
}
Esempio n. 8
0
    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
    {
        if (ea.getHandled()) return false;

        switch(ea.getEventType())
        {
            case(osgGA::GUIEventAdapter::KEYUP):
            {
                if (ea.getKey() == _key)
                {
                    osg::notify(osg::NOTICE)<<"event handler"<<std::endl;
                    _snapImage->_snapImage = true;
                    return true;
                }

                break;
            }
        default:
            break;
        }

        return false;
    }
bool TimerHandler::handle( const osgGA::GUIEventAdapter& ea,
		                       osgGA::GUIActionAdapter& aa )
{
	
	switch ( ea.getEventType())
	{
	case osgGA::GUIEventAdapter::FRAME:

		float x = ea.getX();
		float y = ea.getY();
		std::cout << "X:  " << x << std::endl;
		std::cout << "Y:  " << y << std::endl;
		gameRender->updateDirection(x, y);
		gameRender->updateGamePlay();
		_count++;
		break;
	}

	return false;



}
Esempio n. 10
0
bool EventHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) {
    bool suppressDefault = false;
    osgGA::GUIEventAdapter::EventType t = ea.getEventType();

    // keypress handlers (for convenience)
    if (t == osgGA::GUIEventAdapter::KEYDOWN) {
        pair<Scene::KeyCallbackMap::const_iterator, Scene::KeyCallbackMap::const_iterator> range =
            scene.keyCallbacks.equal_range(ea.getKey());
        for (Scene::KeyCallbackMap::const_iterator i = range.first; i != range.second; ++i)
            suppressDefault |= i->second(ea);
    }

    // general handlers
    pair<Scene::CallbackMap::const_iterator, Scene::CallbackMap::const_iterator> range =
        scene.callbacks.equal_range(t);
    for (Scene::CallbackMap::const_iterator i = range.first; i != range.second; ++i)
        suppressDefault |= i->second(ea);

    if (!suppressDefault)
        return osgGA::TrackballManipulator::handle(ea, aa);

    return false;
}
Esempio n. 11
0
	bool MouseEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
		if (ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
			ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
			!(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL))
				return false;
	
		osgViewer::Viewer* viewer= dynamic_cast<osgViewer::Viewer*>(&aa);
		if (viewer) {
			osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector=
			new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
			osgUtil::IntersectionVisitor iv(intersector.get());
			// Sólo recorrer aquellos nodos con nodeMask=0x1
			iv.setTraversalMask(~0x1);
			viewer->getCamera()->accept(iv);
			if (intersector->containsIntersections()) {
				//osgUtil::LineSegmentIntersector::Intersection& elegido= *(intersector->getIntersections().begin());
				//orbita= elegido.;
				//std::cout<<"ola k ase\n";
			// Hagamos lo que tengamos que hacer...
			}
		}
		return false;
	}
Esempio n. 12
0
//==============================================================================
void DefaultEventHandler::eventPick(const osgGA::GUIEventAdapter& ea)
{
    MouseButtonEvent mbe;
    switch(ea.getEventType())
    {
    case osgGA::GUIEventAdapter::PUSH:
        mbe = BUTTON_PUSH;
        break;
    case osgGA::GUIEventAdapter::DRAG:
        mbe = BUTTON_DRAG;
        break;
    case osgGA::GUIEventAdapter::RELEASE:
        mbe = BUTTON_RELEASE;
        break;
    default:
        return;
    }

    if(   ( (ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
            && !mSuppressButtonPicks[LEFT_MOUSE][mbe])
            || ( (ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
                 && !mSuppressButtonPicks[RIGHT_MOUSE][mbe])
            || ( (ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
                 && !mSuppressButtonPicks[MIDDLE_MOUSE][mbe]))
    {
        pick(mTempPicks, ea);

        if(ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
            mButtonPicks[LEFT_MOUSE][mbe] = mTempPicks;

        if(ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
            mButtonPicks[RIGHT_MOUSE][mbe] = mTempPicks;

        if(ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
            mButtonPicks[MIDDLE_MOUSE][mbe] = mTempPicks;
    }
}
Esempio n. 13
0
    bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
    {
        switch(ea.getEventType())
        {
            case(osgGA::GUIEventAdapter::KEYDOWN):
            {   
                if (ea.getKey()=='r')
                {
                    _terrain->setSampleRatio(_terrain->getSampleRatio()*0.5);
                    osg::notify(osg::NOTICE)<<"Sample ratio "<<_terrain->getSampleRatio()<<std::endl;
                    return true;
                }
                else if (ea.getKey()=='R')
                {
                    _terrain->setSampleRatio(_terrain->getSampleRatio()/0.5);
                    osg::notify(osg::NOTICE)<<"Sample ratio "<<_terrain->getSampleRatio()<<std::endl;
                    return true;
                }
                else if (ea.getKey()=='v')
                {
                    _terrain->setVerticalScale(_terrain->getVerticalScale()*1.25);
                    osg::notify(osg::NOTICE)<<"Vertical scale "<<_terrain->getVerticalScale()<<std::endl;
                    return true;
                }
                else if (ea.getKey()=='V')
                {
                    _terrain->setVerticalScale(_terrain->getVerticalScale()/1.25);
                    osg::notify(osg::NOTICE)<<"Vertical scale "<<_terrain->getVerticalScale()<<std::endl;
                    return true;
                }

                return false;
            }    
            default:
                return false;
        }
    }
Esempio n. 14
0
bool GameManagerKeyboardHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{

    std::string activeRenderingInstanceName = _gameManager->getActiveRenderingInstanceName();

    // check if key is pressed or released
    switch(ea.getEventType())
    {
    case osgGA::GUIEventAdapter::KEYDOWN:
        // find out which key was pressed

        switch(ea.getKey())
        {
        case K_EXIT:

            if(activeRenderingInstanceName == "game")
                _gameManager->selectRenderingInstance("road_select_menu");
            else if(activeRenderingInstanceName == "road_select_menu")
                _gameManager->selectRenderingInstance("main_menu");
            else if(activeRenderingInstanceName == "main_menu")
                exit(0);

            break;

        default:
            return false;
        }

        break;

    default:
        return false;
    }

    return false;
}
bool PointsEventHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter&)
{
    switch (ea.getEventType())
    {
    case (osgGA::GUIEventAdapter::KEYDOWN):
    {
        if (ea.getKey() == '+' || ea.getKey() == osgGA::GUIEventAdapter::KEY_KP_Add)
        {
            changePointSize(1.0f);
            return true;
        }
        else if (ea.getKey() == '-' || ea.getKey() == osgGA::GUIEventAdapter::KEY_KP_Subtract)
        {
            changePointSize(-1.0f);
            return true;
        }
        else if (ea.getKey() == '<')
        {
            changePointAttenuation(1.1f);
            return true;
        }
        else if (ea.getKey() == '>')
        {
            changePointAttenuation(1.0f / 1.1f);
            return true;
        }

        break;
    }

    default:
        break;
    }

    return false;
}
Esempio n. 16
0
 virtual bool handle(const osgGA::GUIEventAdapter& ea,
                     osgGA::GUIActionAdapter& aa,
                     Object*, NodeVisitor* /*nv*/)
 {
     if (ea.getHandled()) return false;
     osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
     if (!viewer) return false;
     switch(ea.getEventType())
     {
     case osgGA::GUIEventAdapter::KEYUP:
     {
         if (ea.getKey()=='d')
         {
             _appState->displayScene = !_appState->displayScene;
             _appState->updateDisplayedTexture();
             return true;
         }
         else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right ||
                  ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right)
         {
             _appState->advanceConfig(1);
             return true;
         }
         else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left ||
                  ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left)
         {
             _appState->advanceConfig(-1);
             return true;
         }
         break;
     }
     default:
         break;
     }
     return false;
 }
Esempio n. 17
0
bool ResizeHandler::handle(
    const osgGA::GUIEventAdapter& gea,
    osgGA::GUIActionAdapter&      /*gaa*/,
    osg::Object*                  /*obj*/,
    osg::NodeVisitor*             /*nv*/
) {
    osgGA::GUIEventAdapter::EventType ev = gea.getEventType();

    if(ev != osgGA::GUIEventAdapter::RESIZE) return false;

    osg::Matrix::value_type w = gea.getWindowWidth();
    osg::Matrix::value_type h = gea.getWindowHeight();

    if(_camera.valid()) {
        _camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0f, w, 0.0f, h));

        _wm->setSize(w, h);
    }

    _wm->setWindowSize(w, h);
    _wm->resizeAllWindows();

    return true;
}
Esempio n. 18
0
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
             ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
             !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) )
            return false;
        
        osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
        if ( viewer )
        {
            osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
                new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
            osgUtil::IntersectionVisitor iv( intersector.get() );
            iv.setTraversalMask( ~DO_NOT_PICK_NODE_MASK );
            viewer->getCamera()->accept( iv );
            
            if ( intersector->containsIntersections() )
            {
                const osgUtil::LineSegmentIntersector::Intersection& result =
                    *(intersector->getIntersections().begin());
                
                
#if OSG_MIN_VERSION_REQUIRED(3,3,2)
				osg::BoundingBox bb = result.drawable->getBoundingBox();
#else
				osg::BoundingBox bb = result.drawable->getBound();
#endif  

                osg::Vec3 worldCenter = bb.center() * osg::computeLocalToWorld(result.nodePath);
                _selectionBox->setMatrix(
                    osg::Matrix::scale(bb.xMax()-bb.xMin(), bb.yMax()-bb.yMin(), bb.zMax()-bb.zMin()) *
                    osg::Matrix::translate(worldCenter) );
            }
        }
        return false;
    }
Esempio n. 19
0
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
    switch(ea.getEventType())
    {
    case(osgGA::GUIEventAdapter::PUSH):
        {
            if (ea.getModKeyMask() == 0)
                return false;

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

            osgUtil::LineSegmentIntersector::Intersection intersection;
            osg::NodePath node_path;
            Renderable* renderable = NULL;
            if (ea.getButtonMask() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
                renderable = computeIntersection<Renderable>(view, ea, intersection, node_path);
            else if (ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
                renderable = computePointIntersection<Renderable>(view, ea, intersection, node_path);
            else 
                return false;

            if (renderable == NULL)
                return false;

            renderable->pickEvent(ea.getModKeyMask(), intersection.getWorldIntersectPoint());
            return true;
        }
        break;
    default:
        return false;
    }

    return false;
}
Esempio n. 20
0
bool
ActivityMonitorTool::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    if (ea.getEventType() == ea.FRAME)
    {
        osg::ref_ptr<VBox> vbox;
        if ( _vbox.lock(vbox) )
        {
            std::set<std::string> activity;
            Registry::instance()->getActivities(activity);
            if ( activity != _prev )
            {            
                _vbox->clearControls();
                for(std::set<std::string>::const_iterator i = activity.begin(); i != activity.end(); ++i)
                {
                    _vbox->addControl( new LabelControl(*i) );
                }
                _prev = activity;
            }
        }        
    }

    return false;
}
Esempio n. 21
0
bool GestionEvenements::handle( const osgGA::GUIEventAdapter& ea,
 osgGA::GUIActionAdapter& aa)
{
	switch(ea.getEventType()){
		case osgGA::GUIEventAdapter::KEYDOWN :
		
			switch(ea.getKey()){
				
				case 'a':
					viewer.setCameraManipulator(trackCone.get());
					break;
				case 'z':
					viewer.setCameraManipulator(trackBoite.get());
					break;
				case 'e':
					viewer.setCameraManipulator(trackSphere.get());
					break;
			}
			break;
		
		case osgGA::GUIEventAdapter::PUSH :{
			int x = ea.getX();
			int y = ea.getY();
			if( ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
				std::cout << "bouton gauche" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
				std::cout << "bouton milieu" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
				std::cout << "bouton droit" << std::endl;
			break;
 }
		case osgGA::GUIEventAdapter::DOUBLECLICK :
			break;
			}
 return false; // pour que l'événement soit traité par d'autres gestionnaires
}
Esempio n. 22
0
    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
    {
        osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
        if (!view) 
			return false;

        switch(ea.getEventType())
        {
			case(osgGA::GUIEventAdapter::KEYDOWN):
			{
				switch(ea.getKey())
				{
					case 'r': case 'R':
						{
							std::cout << "Resetting multi marker" << std::endl;
							multi_marker_init->Reset();
							multi_marker_init->MeasurementsReset();
							multi_marker_bundle->Reset();
							multi_marker_bundle->MeasurementsReset();
							optimize_done = false;
							visualize	  = true;
							curr_meas  = 0;
							every_20th = 0;
						}
						break;
					case 'q': case 'Q':
						{
							stop_running = true;
							std::cout << "Stopping..." << std::endl;
						} 
						break;
				}
			}
		}			
        return true;
	}
Esempio n. 23
0
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::PUSH):
        {
            osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
            if (view) pick(view,ea);
            return false;
        }

        case(osgGA::GUIEventAdapter::KEYUP):
        {
            if (ea.getKey() == 't')
            {
                osg::ref_ptr<osgGA::GUIEventAdapter> user_event = new osgGA::GUIEventAdapter();
                user_event->setEventType(osgGA::GUIEventAdapter::USER);
                user_event->setUserValue("vec2f", osg::Vec2f(1.0f,2.0f));
                user_event->setUserValue("vec3f", osg::Vec3f(1.0f,2.0f, 3.0f));
                user_event->setUserValue("vec4f", osg::Vec4f(1.0f,2.0f, 3.0f, 4.0f));

                user_event->setUserValue("vec2d", osg::Vec2d(1.0,2.0));
                user_event->setUserValue("vec3d", osg::Vec3d(1.0,2.0, 3.0));
                user_event->setUserValue("vec4d", osg::Vec4d(1.0,2.0, 3.0, 4.0));

                user_event->setName("osc_test_1");

                _device->sendEvent(*user_event);
            }

        }

        default:
            return false;
    }
}
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{
    osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer*>(&aa);

    if (!viewer)
        return false;

    if (ea.getHandled())
        return false;

    if (ea.getEventType() == GUIEventAdapter::KEYDOWN)
    {
        switch (ea.getKey())
        {
        case osgGA::GUIEventAdapter::KEY_Right:
            // Toggle next switch
            nextSwitch();
            return true;
            break;

        case osgGA::GUIEventAdapter::KEY_Up:
            // Increase animation speed
            multiplyAnimation(2);
            return true;
            break;

        case osgGA::GUIEventAdapter::KEY_Down:
            // Decrease animation speed
            multiplyAnimation(0.5);
            return true;
            break;
        }
    }

    return false;
}
Esempio n. 25
0
bool ResizeHandler::handle(
    const osgGA::GUIEventAdapter& gea,
    osgGA::GUIActionAdapter&      gaa,
    osg::Object*                  obj,
    osg::NodeVisitor*             nv
) {
    osgGA::GUIEventAdapter::EventType ev = gea.getEventType();

    if(ev != osgGA::GUIEventAdapter::RESIZE) return false;

    osg::Matrix::value_type w = gea.getWindowWidth();
    osg::Matrix::value_type h = gea.getWindowHeight();

    if(_wm->isInvertedY()) _camera->setProjectionMatrix(
        createInvertedYOrthoProjectionMatrix(w, h)
    );

    else _camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0f, w, 0.0f, h));
    
    _wm->setSize(w, h);
    _wm->resizeAllWindows();

    return true;
}
Esempio n. 26
0
bool ViewerManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    using namespace osgGA;

	if (ea.getEventType()==GUIEventAdapter::FRAME)
	{
		spinApp &spin = spinApp::Instance();
		
		// update from NodeTrackerManipulator:
		if (spin.userNode.valid())
		{
			// if the userNode's nodepath has changed, we must call setTrackNode
			// again to force NodeTrackerManipulator to store the proper nodePath
			if (spin.userNode->nodepathUpdate)
			{
				setTrackNode(spin.userNode->getAttachmentNode());
				spin.userNode->nodepathUpdate = false;
			}
			
			// update camera from NodeTrackerManipulator:
			if (_thrown) aa.requestRedraw();
		}
	}
	
	else if ((ea.getEventType()==GUIEventAdapter::MOVE)||
			(ea.getEventType()==GUIEventAdapter::DRAG)||
			(ea.getEventType()==GUIEventAdapter::PUSH)||
			(ea.getEventType()==GUIEventAdapter::RELEASE)||
			(ea.getEventType()==GUIEventAdapter::DOUBLECLICK)||
			(ea.getEventType()==GUIEventAdapter::SCROLL))
	{
		osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
		if (view) handleMouse(view,ea);
	}
	
	
	else if (ea.getEventType()==GUIEventAdapter::KEYUP)
	{
		handleKeypress(ea);
	}
	
	return false;
}
Esempio n. 27
0
bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::MOVE):
        case(osgGA::GUIEventAdapter::PUSH):
        case(osgGA::GUIEventAdapter::RELEASE):
        {
            if (_trackMouse)
            {
                osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
                osgUtil::LineSegmentIntersector::Intersections intersections;
                bool foundIntersection = view==0 ? false :
                    (nv==0 ? view->computeIntersections(ea, intersections) :
                             view->computeIntersections(ea, nv->getNodePath(), intersections));

                if (foundIntersection)
                {

                    // use the nearest intersection
                    const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin());
                    osg::Drawable* drawable = intersection.drawable.get();
                    osg::Geometry* geometry = drawable ? drawable->asGeometry() : 0;
                    osg::Vec3Array* vertices = geometry ? dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()) : 0;
                    if (vertices)
                    {
                        // get the vertex indices.
                        const osgUtil::LineSegmentIntersector::Intersection::IndexList& indices = intersection.indexList;
                        const osgUtil::LineSegmentIntersector::Intersection::RatioList& ratios = intersection.ratioList;

                        if (indices.size()==3 && ratios.size()==3)
                        {
                            unsigned int i1 = indices[0];
                            unsigned int i2 = indices[1];
                            unsigned int i3 = indices[2];

                            float r1 = ratios[0];
                            float r2 = ratios[1];
                            float r3 = ratios[2];

                            osg::Array* texcoords = (geometry->getNumTexCoordArrays()>0) ? geometry->getTexCoordArray(0) : 0;
                            osg::Vec2Array* texcoords_Vec2Array = dynamic_cast<osg::Vec2Array*>(texcoords);
                            if (texcoords_Vec2Array)
                            {
                                // we have tex coord array so now we can compute the final tex coord at the point of intersection.
                                osg::Vec2 tc1 = (*texcoords_Vec2Array)[i1];
                                osg::Vec2 tc2 = (*texcoords_Vec2Array)[i2];
                                osg::Vec2 tc3 = (*texcoords_Vec2Array)[i3];
                                osg::Vec2 tc = tc1*r1 + tc2*r2 + tc3*r3;

                                osg::notify(osg::NOTICE)<<"We hit tex coords "<<tc<<std::endl;

                            }
                        }
                        else
                        {
                            osg::notify(osg::NOTICE)<<"Intersection has insufficient indices to work with";
                        }

                    }
                }
                else
                {
                    osg::notify(osg::NOTICE)<<"No intersection"<<std::endl;
                }
            }
            break;
        }
        case(osgGA::GUIEventAdapter::KEYDOWN):
        {
            if (ea.getKey()=='p')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    osg::ImageStream::StreamStatus playToggle = (*itr)->getStatus();
                    if (playToggle != osg::ImageStream::PLAYING)
                    {
                        std::cout<< (*itr).get() << " Play"<<std::endl;
                        (*itr)->play();
                    }
                    else
                    {
                        // playing, so pause
                        std::cout<< (*itr).get() << " Pause"<<std::endl;
                        (*itr)->pause();
                    }
                }
                return true;
            }
            else if (ea.getKey()=='r')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    std::cout<< (*itr).get() << " Restart"<<std::endl;
                    (*itr)->rewind();
                    (*itr)->play();
                }
                return true;
            }
            else if (ea.getKey()=='>')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    std::cout<<"Seeking"<<std::endl;
                    if(_seekIncr > 3) _seekIncr = 0;
                    double length = (*itr)->getLength();
                    double t_pos = (length/4.0f)*_seekIncr;
                    //(*itr)->rewind();
                    (*itr)->seek(t_pos);
                    (*itr)->play();
                    _seekIncr++;
                }
                return true;
            }
            else if (ea.getKey()=='L')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    if ( (*itr)->getLoopingMode() == osg::ImageStream::LOOPING)
                    {
                        std::cout<< (*itr).get() << " Toggle Looping Off"<<std::endl;
                        (*itr)->setLoopingMode( osg::ImageStream::NO_LOOPING );
                    }
                    else
                    {
                        std::cout<< (*itr).get() << " Toggle Looping On"<<std::endl;
                        (*itr)->setLoopingMode( osg::ImageStream::LOOPING );
                    }
                }
                return true;
            }
            else if (ea.getKey()=='+')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    double tm = (*itr)->getTimeMultiplier();
                    tm += 0.1;
                    (*itr)->setTimeMultiplier(tm);
                    std::cout << (*itr).get() << " Increase speed rate "<< (*itr)->getTimeMultiplier() << std::endl;
                }
                return true;
            }
            else if (ea.getKey()=='-')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    double tm = (*itr)->getTimeMultiplier();
                    tm -= 0.1;
                    (*itr)->setTimeMultiplier(tm);
                    std::cout << (*itr).get() << " Decrease speed rate "<< (*itr)->getTimeMultiplier() << std::endl;
                }
                return true;
            }
            else if (ea.getKey()=='o')
            {
                for(ImageStreamList::iterator itr=_imageStreamList.begin();
                    itr!=_imageStreamList.end();
                    ++itr)
                {
                    std::cout<< (*itr).get() << " Frame rate  "<< (*itr)->getFrameRate() <<std::endl;
                }
                return true;
            }
            return false;
        }

        default:
            return false;
    }
    return false;
}
Esempio n. 28
0
        virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv)
        {
            osg::AutoTransform* transform = dynamic_cast<osg::AutoTransform*>(object);
            if (!transform) return false;

            osg::NotifySeverity level = osg::INFO;
            
            switch(ea.getEventType())
            {
                case(osgGA::GUIEventAdapter::PUSH):
                case(osgGA::GUIEventAdapter::RELEASE):
                case(osgGA::GUIEventAdapter::MOVE):
                case(osgGA::GUIEventAdapter::DRAG):

                    osg::notify(level)<<std::endl<<"ea.getGraphicsContext()="<<ea.getGraphicsContext()<<std::endl;
                    osg::notify(level)<<"ea.getWindowWidth()="<<ea.getWindowWidth()<<std::endl;
                    osg::notify(level)<<"ea.getWindowHeight()="<<ea.getWindowHeight()<<std::endl;
                    osg::notify(level)<<"ea.getX()="<<ea.getX()<<std::endl;
                    osg::notify(level)<<"ea.getXin()="<<ea.getXmin()<<std::endl;
                    osg::notify(level)<<"ea.getXmax()="<<ea.getXmax()<<std::endl;
                    osg::notify(level)<<"ea.getY()="<<ea.getY()<<std::endl;
                    osg::notify(level)<<"ea.getYin()="<<ea.getYmin()<<std::endl;
                    osg::notify(level)<<"ea.getYmax()="<<ea.getYmax()<<std::endl;

                    _mousePostition.set(ea.getXnormalized(), ea.getYnormalized());
                    break;

                case(osgGA::GUIEventAdapter::FRAME):
                {
                    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);


                    osg::Camera* camera = view->getCamera();
                    osg::Matrix VP =  camera->getViewMatrix() * camera->getProjectionMatrix();

                    osg::Matrix inverse_VP;
                    inverse_VP.invert(VP);

                    osg::Vec3d start_eye(_mousePostition.x(), _mousePostition.y(), 0.0);
                    osg::Vec3d end_eye(_mousePostition.x(), _mousePostition.y(), 1.0);

                    osg::Vec3d start_world = start_eye * inverse_VP;
                    osg::Vec3d end_world = start_eye * inverse_VP;

                    osg::notify(level)<<"start_world="<<start_world<<std::endl;
                    osg::notify(level)<<"end_world="<<end_world<<std::endl;

                    if (end_world.valid()) transform->setPosition(end_world);
                    else
                    {
                        OSG_NOTICE<<"Ignoring invalid end_world position"<<std::endl;
                    }

                    break;
                }
                case(osgGA::GUIEventAdapter::KEYDOWN):
                {
                    if (ea.getKey()=='c')
                    {
                        for(unsigned int i=0; i< transform->getNumChildren(); ++i)
                        {
                            osg::Node* node = transform->getChild(i);
                            node->setNodeMask(
                                node->getNodeMask()!=0 ?
                                0 :
                                0xffffff);
                        }
                    }
                    break;
                }
                default:
                    break;
            }
            return false;
        }
Esempio n. 29
0
bool PrintPosterHandler::handle(
    const osgGA::GUIEventAdapter& ea
,   osgGA::GUIActionAdapter& aa)
{
    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);

    if(!view) 
        return false;

    switch(ea.getEventType())
    {
        case osgGA::GUIEventAdapter::FRAME:
        {
            // Wait until all paged LOD are processed
            if(view->getDatabasePager() && view->getDatabasePager()->getRequestsInProgress())
                break;

            if(m_isFinished)
            {
                const osg::FrameStamp* fs = view->getFrameStamp();
                if((fs->getFrameNumber() % 2) == 0)
                {
                    aggregateAndFreeTiles(); // Record images and unref them to free memory
                    std::cout << "finished" << std::endl;

                    write();
                    m_isFinished = false;
                }
            }

            if(m_make)
                make(view);

            if(m_making)
            {

                // Every "copy-to-image" process seems to be finished in 2 frames.
                // So record them and dispatch cameras to next tiles.

                const osg::FrameStamp* fs = view->getFrameStamp();

                if((fs->getFrameNumber() % 2) == 0)
                {
                    // Record images and unref them to free memory
                    aggregateAndFreeTiles();

                    osg::Camera* camera = 0;

                    while((camera = getAvailableCamera()) != NULL)
                    {
                        std::cout << "Binding sub-camera " << m_currentRow << "_" << m_currentColumn
                                    << " to image..." << std::endl;

                        bindCameraToImage(camera, m_currentRow, m_currentColumn);

                        if (m_currentColumn < m_tileColumns - 1)
                            m_currentColumn++;
                        else
                        {
                            if(m_currentRow < m_tileRows - 1)
                            {
                                m_currentRow++;
                                m_currentColumn = 0;
                            }
                            else
                            {
                                m_making = false;
                                m_isFinished = true;
                                    
                                std::cout << "Sub-cameras dispatching finished." << std::endl;
                                break;
                            }
                        }
                    }
                    m_cameraIndex = m_cameraRoot->getNumChildren();
                }
            }
            break;
        }

        case osgGA::GUIEventAdapter::KEYDOWN:
        {
            if ( ea.getKey()=='p' || ea.getKey()=='P' )
            {
                print();
                return true;
            }
            break;
        }

        default:
            break;
    }

    return false;
}
// Keyboard Handler ////////////////////////////
bool KineBallRunSandboxKeyboardHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::KEYDOWN):
        {
            switch(ea.getKey())
            {
                case 'q':
                    appPtr->sendSelfTerminate();
                    break;
                // Camera Zoom
                case 'p':
                    cam_mult = 100;
                    break;
                case 'o':
                    cam_mult = 1;
                    break;

                case 'z':
                    dz1 = 0;
                    break;
                case 'x':
                    dz1 = 25;
                case 'c':
                    dz1 = 600;
                    break;
                case 'a':
                    theta1 += .025;
                    break;
                case 'd':
                    theta1 -= .025;
                    break;

                case 'b':
                    dz2 = 0;
                    break;
                case 'n':
                    dz2 = 25;
                case 'm':
                    dz2 = 600;
                    break;
                case 'h':
                    theta2 += .025;
                    break;
                case 'k':
                    theta2 -= .025;
                    break;
                case '4':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(-1000*cam_mult,0,0),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '6':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(1000*cam_mult,0,0),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '8':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(0,0,-1000*cam_mult),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '2':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(0,0,1000*cam_mult),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '1':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(0,1000*cam_mult,0),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '3':
                    appPtr->_camServo.translateCameraRel( appPtr->_camera1,osg::Vec3(0,-1000*cam_mult,0),
                                                                    cam1_eye,cam1_look,cam1_up);
                    break;
                case '7':
                    {   
                        theta1 += .03;
                        appPtr->_camServo.rotateCameraRel(appPtr->_camera1,cam1_eye,
                                                   cam1_look,cam1_up,cam1_start, cam1_off, theta1);
                        break;
                    } break;
                case '9':
                    {   
                        theta1 -= .03;
                        appPtr->_camServo.rotateCameraRel(appPtr->_camera1,cam1_eye,
                                                   cam1_look,cam1_up,cam1_start, cam1_off, theta1);
                        break;
                    } break;
                    break; 
            } 
        }
        default:
            return false;
    }
}