bool TechniqueEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) { _ops_index++; if (_ops_index>=_ops_nb) _ops_index=0; _logicOp->setOpcode(_operations[_ops_index]); std::cout<<"Operation name = "<<_ops_name[_ops_index]<<std::endl; return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) { _ops_index--; if (_ops_index<0) _ops_index=_ops_nb-1; _logicOp->setOpcode(_operations[_ops_index]); std::cout<<"Operation name = "<<_ops_name[_ops_index]<<std::endl; return true; } return false; } default: return false; } }
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='n') { osg::StateSet* stateset = new osg::StateSet; osg::PolygonOffset* polyoffset = new osg::PolygonOffset; polyoffset->setFactor(-1.0f); polyoffset->setUnits(-1.0f); osg::PolygonMode* polymode = new osg::PolygonMode; polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); osg::Material* material = new osg::Material; stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); _mapNode->setStateSet(stateset); return true; } if (ea.getKey()=='p') { _mapNode->setStateSet(new osg::StateSet()); return true; } break; } default: break; } return false; }
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { if (ea.getHandled()) return false; switch (ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYUP) : { if (ea.getKey() == 'o') { osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); osg::Node* node = view ? view->getSceneData() : 0; if (node) { osgDB::writeNodeFile(*node, "hud.osgt"); osgDB::writeNodeFile(*node, "hud.osgb"); } return true; } if (ea.getKey() == _key) { osg::notify(osg::NOTICE) << "event handler" << std::endl; _snapImage->_snapImage = true; return true; } break; } default: break; } return false; }
bool ShowEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* /*nv*/) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYUP): { osg::notify(osg::INFO)<<"ShowEventHandler KEYUP "<<(int)ea.getKey()<<std::endl; if (ea.getKey()>=osgGA::GUIEventAdapter::KEY_F1 && ea.getKey()<=osgGA::GUIEventAdapter::KEY_F8) { unsigned int child = ea.getKey()-osgGA::GUIEventAdapter::KEY_F1; osg::notify(osg::INFO)<<" Select "<<child<<std::endl; osg::Switch* showSwitch = dynamic_cast<osg::Switch*>(object); if (showSwitch) { if (child<showSwitch->getNumChildren()) { osg::notify(osg::INFO)<<" Switched "<<child<<std::endl; showSwitch->setSingleChildOn(child); return true; } } } break; } default: break; } return false; }
bool HumanController::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): osg::Vec3 delta = _left^_up; delta.normalize(); delta *= _velocity; if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up) { _eye += delta; } if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down) { _eye -= delta; } if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left) { _eye += _left*_velocity; } if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right) { _eye -= _left*_velocity; } return true; } return false; }
bool TechniqueEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&, osg::Object*, osg::NodeVisitor*) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='n' || ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) { _ForestTechniqueManager->advanceToNextTechnique(1); return true; } else if (ea.getKey()=='p' || ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) { _ForestTechniqueManager->advanceToNextTechnique(-1); return true; } return false; } default: return false; } }
bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F1) { m_spring_node->setEnable(!m_spring_node->getEnable()); std::string str = m_spring_node->getEnable() ? "Enabled" : "Disabled"; osg::notify(osg::WARN) << str << " rendering of spring" << std::endl; return true; } if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F2) { osgHaptics::SpringForceOperator *spring = m_spring_node->getForceOperator(); if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT) spring->setStiffness(spring->getStiffness()*0.9); else spring->setStiffness(spring->getStiffness()*1.1); osg::notify(osg::WARN) << "Stiffness : " << spring->getStiffness() << std::endl; return true; } return false; } default: return false; } return false; }
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *o, osg::NodeVisitor *) { osgGA::GUIEventAdapter::EventType etype = ea.getEventType(); CeguiDrawable* myDrawable = static_cast<CeguiDrawable*>(o); if (etype & (osgGA::GUIEventAdapter::RELEASE | osgGA::GUIEventAdapter::PUSH | osgGA::GUIEventAdapter::MOVE | osgGA::GUIEventAdapter::DRAG | osgGA::GUIEventAdapter::KEYDOWN | osgGA::GUIEventAdapter::KEYUP)) { if (etype == osgGA::GUIEventAdapter::KEYDOWN && ea.getKey() == osgGA::GUIEventAdapter::KEY_F7) { myDrawable->addEvent(ea); return true; } if (!m_guiHandlesEvents && etype == osgGA::GUIEventAdapter::KEYDOWN && ea.getKey() == osgGA::GUIEventAdapter::KEY_Tab) { using namespace CEGUI; m_guiHandlesEvents = true; GUIContext & gui = System::getSingleton().getDefaultGUIContext(); gui.getMouseCursor().show(); m_guiApp->hudGotFocus(); return true; } if (!m_guiHandlesEvents) return false; // HACK: don't send events directly to CEGUI, instead wait until the required OpenGL context is active // as CEGUI will probably try to change OpenGL objects/state, which will SILENTLY fail in case of the // wrong or no active OpenGL context(thanks to gDEBugger I've actually seen this happen). // which means, that we should do the injection in draw phase... myDrawable->addEvent(ea); return true; } return false; }
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { static float scale = 1.0f; if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN || ( ea.getKey() != '=' && ea.getKey() != '-' ) ) return false; osg::MatrixTransform* matrix = getMatrix(aa); if(!matrix) return false; osg::StateSet* state = matrix->getStateSet(); osg::Uniform* aMin = state->getUniform("AlphaMin"); osg::Uniform* aMax = state->getUniform("AlphaMax"); if(ea.getKey() == '=') scale += SCALE_STEP; else if(ea.getKey() == '-') scale -= SCALE_STEP; // OSG_NOTICE << "New Scale: " << scale << std::endl; aMin->set(std::max(0.0f, 0.5f - 0.07f / (scale / 2.0f))); aMax->set(std::min(0.5f + 0.07f / (scale / 2.0f), 1.0f)); matrix->setMatrix(osg::Matrix::scale(scale, scale, 1.0f)); // OSG_NOTICE << "AlphaMin: " << std::max(0.0f, 0.5f - 0.07f / scale) << std::endl; // OSG_NOTICE << "AlphaMax: " << std::min(0.5f + 0.07f / scale, 1.0f) << std::endl; return true; }
/** Handle keyboard event. */ virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) { global_date += (1.0 / 24) / 4; force_update_of_sky_dome = true; return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) { global_date -= (1.0 / 24) / 4; force_update_of_sky_dome = true; return true; } return false; } default: return false; } }
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/) { if (!_layer) return false; float scale = 1.2; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey() == 'q') { _layer->transform(0.0, scale); return true; } else if (ea.getKey() == 'a') { _layer->transform(0.0, 1.0f/scale); return true; } break; } default: break; } return false; }
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::notify(osg::NOTICE)<<"LODScale = "<<camera->getLODScale()<<std::endl; return true; } else if (ea.getKey() == _keyEventDecreaseLODScale) { camera->setLODScale(camera->getLODScale()/1.1); osg::notify(osg::NOTICE)<<"LODScale = "<<camera->getLODScale()<<std::endl; return true; } break; } default: break; } return false; }
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { int x = ea.getX(), y = ea.getY(), width = ea.getWindowWidth(), height = ea.getWindowHeight(); if ( ea.getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS ) y = ea.getWindowHeight() - y; if ( !CEGUI::System::getSingletonPtr() ) return false; CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext(); switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::KEYDOWN: context.injectKeyDown(key_conv(ea.getKey())); context.injectChar(char_conv(ea.getKey())); // return key_conv(ea.getKey()) != CEGUI::Key::Unknown; break; case osgGA::GUIEventAdapter::KEYUP: context.injectKeyUp(key_conv(ea.getKey())); // return key_conv(ea.getKey()) != CEGUI::Key::Unknown; break; case osgGA::GUIEventAdapter::PUSH: context.injectMousePosition( x, y ); context.injectMouseButtonDown(convertMouseButton(ea.getButton())); break; case osgGA::GUIEventAdapter::RELEASE: context.injectMousePosition(x, y); context.injectMouseButtonUp(convertMouseButton(ea.getButton())); break; case osgGA::GUIEventAdapter::SCROLL: if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_DOWN ) context.injectMouseWheelChange(-1); else if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_UP ) context.injectMouseWheelChange(+1); break; case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::MOVE: context.injectMousePosition(x, y); break; case osgGA::GUIEventAdapter::RESIZE: if ( _camera.valid() ) { _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) ); _camera->setViewport( 0.0, 0.0, width, height ); } break; default: return false; } CEGUI::Window* rootWindow = context.getRootWindow(); if ( rootWindow ) { CEGUI::Window* anyWindow = rootWindow->getChildAtPosition( CEGUI::Vector2f(x, y) ); if ( anyWindow ) return true; } return false; }
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { if ( ea.getEventType() == ea.KEYDOWN && ea.getKey() >= '1' && ea.getKey() <= '5' ) { _manip->setViewpoint( VPs[ea.getKey()-'1'], 4.0 ); } return false; }
bool QOsgEventHandler::handle( const osgGA::GUIEventAdapter &ea , osgGA::GUIActionAdapter &) { if(ea.getEventType() == osgGA::GUIEventAdapter::FRAME || ea.getEventType() == osgGA::GUIEventAdapter::MOVE) return false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if(ea.getKey() == '-' || ea.getKey() == '+') { const float f = 1.00f + (ea.getKey() == '+' ? +0.004f : -0.004f); if(m_fov * f >= 1.f && m_fov * f <= 179.f) m_fov *= f; emit fovChanged(m_fov); } } break; case(osgGA::GUIEventAdapter::SCROLL): { const float f = 1.00f + (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_DOWN ? -0.08f : +0.08f); if(m_fov * f >= 1.f && m_fov * f <= 179.f) m_fov *= f; emit fovChanged(m_fov); return true; } break; case(osgGA::GUIEventAdapter::RELEASE): if(ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON && (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL) != 0) { m_fov = m_fovBackup; emit fovChanged(m_fov); return true; } break; default: break; }; return false; }
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::FRAME: if ( view->getDatabasePager() ) { // Wait until all paged nodes are processed if ( view->getDatabasePager()->getRequestsInProgress() ) break; } if ( _printer.valid() ) { _printer->frame( view->getFrameStamp(), view->getSceneData() ); if ( _started && _printer->done() ) { osg::Switch* root = dynamic_cast<osg::Switch*>( view->getSceneData() ); if ( root ) { // Assume child 0 is the loaded model and 1 is the poster camera // Switch them in time to prevent dual traversals of subgraph root->setValue( 0, true ); root->setValue( 1, false ); } _started = false; } } break; case osgGA::GUIEventAdapter::KEYDOWN: if ( ea.getKey()=='p' || ea.getKey()=='P' ) { if ( _printer.valid() ) { osg::Switch* root = dynamic_cast<osg::Switch*>( view->getSceneData() ); if ( root ) { // Assume child 0 is the loaded model and 1 is the poster camera root->setValue( 0, false ); root->setValue( 1, true ); } _printer->init( view->getCamera() ); _started = true; } return true; } break; default: break; } return false; }
bool myKeyBoardEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { int pressedKeyId = ea.getKey(); if( pressedKeyId > 0 ) { if( ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN ) cout << "get button : " << ea.getKey() << endl; } return true; }
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/, Object*, NodeVisitor* /*nv*/) { if (ea.getHandled()) return false; ref_ptr<Depth> depth; if (!_depth.lock(depth)) return false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey() == 'i') { _appState->invertRange = !_appState->invertRange; if (!_appState->invertRange) { _appState->camera->setClearDepth(1.0f); depth->setFunction(Depth::LESS); depth->setRange(0.0f, 1.0f); _appState->textInverted->setNodeMask(0u); } else { _appState->camera->setClearDepth(0.0f); depth->setFunction(Depth::GEQUAL); depth->setRange(1.0f, 0.0f); _appState->textInverted->setNodeMask(~0u); } return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up) { _appState->zNear *= 2.0; _appState->updateNear(); return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Down) { _appState->zNear *= .5; _appState->updateNear(); return true; } break; } default: break; } return false; }
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) { switch( ea.getEventType() ) { case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey()==osgGA::GUIEventAdapter::KEY_F6) { // F6 -- Toggle osgOQ testing. _enable = !_enable; EnableQueryVisitor eqv( _enable ); _node.accept( eqv ); return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_F7) { // F7 -- Toggle display of OQ test bounding volumes _debug = !_debug; DebugDisplayVisitor ddv( _debug ); _node.accept( ddv ); return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_F8) { // F8 -- Gether stats and display StatisticsVisitor sv; _node.accept( sv ); std::cout << "osgOQ: Stats: numOQNs " << sv.getNumOQNs() << ", numPased " << sv.getNumPassed() << std::endl; return true; } else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_F9) { // F9 -- Remove all OcclusionQueryNodes RemoveOcclusionQueryVisitor roqv; _node.accept( roqv ); return true; } else if (ea.getKey()=='o') { if (osgDB::writeNodeFile( _node, "saved_model.osg" )) osg::notify( osg::ALWAYS ) << "osgOQ: Wrote scene graph to \"saved_model.osg\"" << std::endl; else osg::notify( osg::ALWAYS ) << "osgOQ: Wrote failed for \"saved_model.osg\"" << std::endl; return true; } return false; } default: break; } return false; }
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { #if 1 // osg::notify(osg::NOTICE)<<"Mouse "<<ea.getButtonMask()<<std::endl; #define PRINT(mask) osg::notify(osg::NOTICE)<<#mask<<" ="<<(ea.getModKeyMask() & mask)<<std::endl; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): case(osgGA::GUIEventAdapter::KEYUP): { osg::notify(osg::NOTICE)<<std::endl; PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_SHIFT); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_SHIFT); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_ALT); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_ALT); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_META); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_META); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_SUPER); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_SUPER); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_HYPER); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_HYPER); PRINT(osgGA::GUIEventAdapter::MODKEY_NUM_LOCK); PRINT(osgGA::GUIEventAdapter::MODKEY_CAPS_LOCK); break; } default: break; } #endif switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { _keyboardModel->keyChange(ea.getKey(), ea.getUnmodifiedKey(),1); return true; } case(osgGA::GUIEventAdapter::KEYUP): { _keyboardModel->keyChange(ea.getKey(), ea.getUnmodifiedKey(),0); return true; } default: return false; } }
bool PickHandler::handleKeyDown( const osgGA::GUIEventAdapter& ea, GUIActionAdapter& aa) { if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L) { isCtrlPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_R) { isShiftPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_R) { isAltPressed = true; } else if(ea.getKey() == 'q') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::randomElementSelector(currentGraph->getNodes(), currentGraph->getEdges(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } else if(ea.getKey() == 'w') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } return false; }
bool CSulManipulatorCamera::handle( const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa ) { switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::KEYDOWN: { if ( ea.getKey()=='w' ) m_bForward = true; if ( ea.getKey()=='s' ) m_bReverse = true; if ( ea.getKey()=='a' ) m_bStrafeLeft = true; if ( ea.getKey()=='d' ) m_bStrafeRight = true; } return true; case osgGA::GUIEventAdapter::KEYUP: { if ( ea.getKey()=='w' ) m_bForward = false; if ( ea.getKey()=='s' ) m_bReverse = false; if ( ea.getKey()=='a' ) m_bStrafeLeft = false; if ( ea.getKey()=='d' ) m_bStrafeRight = false; } return true; case( osgGA::GUIEventAdapter::FRAME ): { double t = ea.getTime(); // check for first time initialization if ( m_timeLast==0.0 ) { m_timeLast = ea.getTime(); m_timeDelta = 0.0; } else { m_timeDelta = t - m_timeLast; m_timeLast = t; } // do movement if ( m_bForward ) m_c.y() += m_timeDelta*m_fSpeed; if ( m_bReverse ) m_c.y() -= m_timeDelta*m_fSpeed; if ( m_bStrafeRight ) m_c.x() += m_timeDelta*m_fSpeed; if ( m_bStrafeLeft ) m_c.x() -= m_timeDelta*m_fSpeed; } return true; } return false; }
bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='a') { _autoSteppingActive = !_autoSteppingActive; _previousTime = ea.getTime(); return true; } else if (ea.getKey()=='n') { _album->nextPage(ea.getTime()+1.0f); return true; } else if (ea.getKey()=='p') { _album->previousPage(ea.getTime()+1.0f); return true; } return false; } case(osgGA::GUIEventAdapter::FRAME): { if (_autoSteppingActive) { if (_firstTraversal) { _firstTraversal = false; _previousTime = ea.getTime(); } else if (ea.getTime()-_previousTime>_timePerSlide) { _previousTime = ea.getTime(); _album->nextPage(ea.getTime()+1.0f); } } _album->setVisibility(); } default: return false; } }
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& gaa){ if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN){ switch (ea.getKey()){ case osgGA::GUIEventAdapter::KEY_Up: tessOuter++; tessOuterU->set(tessOuter); return true; case osgGA::GUIEventAdapter::KEY_Down: tessOuter--; tessOuter=std::max(1.0f,tessOuter); tessOuterU->set(tessOuter); return true; case osgGA::GUIEventAdapter::KEY_Left: tessInner--; tessInner=std::max(1.0f,tessInner); tessInnerU->set(tessInner); return true; case osgGA::GUIEventAdapter::KEY_Right: tessInner++; tessInnerU->set(tessInner); return true; } } return osgGA::GUIEventHandler::handle(ea,gaa); }
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); }
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 ModelController::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) { if ( !_model ) return false; osg::Matrix matrix = _model->getMatrix(); switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::KEYDOWN: switch ( ea.getKey() ) { case 'a': case 'A': matrix *= osg::Matrix::rotate( -0.1f, osg::Z_AXIS ); break; case 'd': case 'D': matrix *= osg::Matrix::rotate( 0.1f, osg::Z_AXIS ); break; case 'w': case 'W': matrix *= osg::Matrix::rotate( -0.1f, osg::X_AXIS ); break; case 's': case 'S': matrix *= osg::Matrix::rotate( 0.1f, osg::X_AXIS ); break; default: break; } _model->setMatrix( matrix ); break; default: break; } return false; }
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* /*nv*/) { osg::Switch* sw = dynamic_cast<osg::Switch*>(object); if (!sw) return false; if (ea.getHandled()) return false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='n') { ++_childNum; if (_childNum >= sw->getNumChildren()) _childNum = 0; sw->setSingleChildOn(_childNum); return true; } break; } default: break; } return false; }
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { osgViewer::View* view = static_cast<osgViewer::View*>( &aa ); if ( !view || !_root ) return false; switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::KEYUP: if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Return ) { osg::Vec3 eye, center, up, dir; view->getCamera()->getViewMatrixAsLookAt( eye, center, up ); dir = center - eye; dir.normalize(); addPhysicsSphere( new osg::Sphere(osg::Vec3(), 0.5f), eye, dir * 60.0f, 2.0 ); } break; case osgGA::GUIEventAdapter::FRAME: BulletInterface::instance()->simulate( 0.02 ); for ( NodeMap::iterator itr=_physicsNodes.begin(); itr!=_physicsNodes.end(); ++itr ) { osg::Matrix matrix = BulletInterface::instance()->getMatrix(itr->first); itr->second->setMatrix( matrix ); } break; default: break; } return false; }
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { if ( ea.getEventType()==osgGA::GUIEventAdapter::KEYUP ) { SilverLining::Atmosphere* atmosphere = _silverLining->atmosphere(); switch ( ea.getKey() ) { case '0': // clear atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::NONE, 0 ); break; case '1': // rain atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::RAIN, 10 ); break; case '2': // wet snow atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::WET_SNOW, 10 ); break; case '3': // dry snow atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::DRY_SNOW, 10 ); break; case '4': // sleet atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::SLEET, 10 ); break; default: break; } } return false; }