bool LibRocketInputProcessor::onSdlEvent(SDL_Event& event) { bool consumed = false; updateKeyModState(); switch(event.type) { case SDL_KEYUP: case SDL_KEYDOWN: consumed = processKeyInput(event); break; case SDL_TEXTINPUT: consumed = processTextInput(event); break; case SDL_MOUSEWHEEL: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: consumed = processMouseInput(event); break; case SDL_MOUSEMOTION: consumed = processMouseMotion(event); break; default: break; } return consumed; }
bool CEGuiInputProcessor::onSdlEvent(SDL_Event& event) { bool consumed = false; switch(event.type) { case SDL_KEYUP: case SDL_KEYDOWN: consumed = processKeyInput(event); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: consumed = processMouseInput(event); break; case SDL_MOUSEMOTION: consumed = processMouseMotion(event); break; default: ; } return consumed; }
//! [10] void Base3DView::mouseMoveEvent(QMouseEvent *event) { if(event->modifiers() == Qt::AltModifier) processCamera(event); else processMouseInput(event); m_lastPos = event->pos(); }
bool BaseFrameListener::frameEnded(const FrameEvent &evt) { // grab the keyboard & mouse state app->getKeyboard()->capture(); app->getMouse()->capture(); processKeyboardInput(evt); processMouseInput(evt); if(! keepRendering) { //OGRE_APP.shutdown(); } return keepRendering; }
void PlayerCharacter::update(Ogre::Real elapsedTime, OIS::Keyboard *input) { processKeyboardInput(elapsedTime); processMouseInput(elapsedTime); //Get the position of the ground below the player Ogre::TerrainGroup* terrain = RenderManager::getSingletonPtr()->getTerrainManager()->getTerrainGroup(); //Store the position to increase it, to guarantuee a hit on the terrain Ogre::Vector3 main_position = mMainNode_->getPosition(); Ogre::Vector3 ray_cast_position = main_position; ray_cast_position.y += 1000.0f; // Setup the query ray Ogre::Ray queryRay(ray_cast_position, Ogre::Vector3::NEGATIVE_UNIT_Y); // Perform the scene query Ogre::TerrainGroup::RayResult result = terrain->rayIntersects(queryRay); if(result.hit) { mCurrentGroundPosition = result.position.y; } //Process jumping if(isJumping_) { // if we're jumping, add a vertical offset too, and apply gravity mMainNode_->translate(0, mCurrentDropVelocity * elapsedTime, 0, Ogre::Node::TS_LOCAL); mCurrentDropVelocity -= mDropVelocityIncrement * elapsedTime; Ogre::Vector3 pos = mMainNode_->getPosition(); if (pos.y <= mCurrentGroundPosition) { // if we've hit the ground, change to landing state pos.y = mCurrentGroundPosition; mMainNode_->setPosition(pos); isJumping_ = false; mCurrentDropVelocity = 0.0f; } } //Upate the player height to the world if not jumping if(!isJumping_) { if(main_position.y <= mCurrentGroundPosition) { main_position.y = mCurrentGroundPosition; mMainNode_->setPosition(main_position); mCurrentDropVelocity = 0.0f; } else { mCurrentDropVelocity += mDropVelocityIncrement * elapsedTime; main_position.y = main_position.y - mCurrentDropVelocity; //Check if we are already below the ground if(main_position.y < mCurrentGroundPosition) main_position.y = mCurrentGroundPosition; mMainNode_->setPosition(main_position); } } if (isRunning_ && mBaseAnimID == ANIM_IDLE_BASE) { // start running if not already moving and the player wants to move setBaseAnimation(ANIM_WALK, true); } if(!isRunning_ && mBaseAnimID == ANIM_WALK) { setBaseAnimation(ANIM_IDLE_BASE); } updateAnimations(elapsedTime); }
void mainLoop() { static Uint32 lastEvent = 0; SDL_Event evt; while( SDL_PollEvent(&evt) ) { lastEvent = SDL_GetTicks(); if(evt.type == SDL_KEYUP || evt.type == SDL_KEYDOWN) { if(evt.key.keysym.sym == SDLK_UNDO) exit(0); processKeyInput(evt.key.keysym.sym, evt.key.state == SDL_PRESSED); //printf("Got key %d %d", evt.key.keysym.sym, evt.key.state == SDL_PRESSED); } // PC mouse events if(evt.type == SDL_MOUSEBUTTONUP || evt.type == SDL_MOUSEBUTTONDOWN) { // TODO: implement PC input touchPointers[evt.jbutton.button].pressed = (evt.button.state == SDL_PRESSED); } if(evt.type == SDL_MOUSEMOTION) { // TODO: implement PC input touchPointers[evt.jbutton.button].x = evt.motion.x; touchPointers[evt.jbutton.button].y = evt.motion.y; } // Android-specific events - accelerometer, multitoush, and on-screen joystick if( evt.type == SDL_JOYAXISMOTION ) { if(evt.jaxis.which == 0) // Multitouch and on-screen joysticks { if(evt.jaxis.axis >= 4) touchPointers[evt.jaxis.axis - 4].pressure = evt.jaxis.value; } } if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP ) { if(evt.jbutton.which == 0) // Multitouch and on-screen joystick touchPointers[evt.jbutton.button].pressed = (evt.jbutton.state == SDL_PRESSED); //printf("Touch press %d: %d", evt.jbutton.button, evt.jbutton.state); } if( evt.type == SDL_JOYBALLMOTION ) { if(evt.jball.which == 0) // Multitouch and on-screen joystick { touchPointers[evt.jball.ball].x = evt.jball.xrel; touchPointers[evt.jball.ball].y = evt.jball.yrel; //printf("Touch %d: %d %d", evt.jball.ball, evt.jball.xrel, evt.jball.yrel); } } } processGui(); processMouseInput(); SDL_Flip(SDL_GetVideoSurface()); SDL_FillRect(SDL_GetVideoSurface(), NULL, 0); if( lastEvent + 1000 < SDL_GetTicks() ) SDL_Delay(150); }
void mainLoop(bool noHid) { static Uint32 lastEvent = 0; SDL_Event evt; for( int i = 0; i < MAX_POINTERS; i++) { if( touchPointers[i].delayRelease ) touchPointers[i].pressed = false; touchPointers[i].delayRelease = false; } while( SDL_PollEvent(&evt) ) { lastEvent = SDL_GetTicks(); if( evt.type == SDL_KEYUP || evt.type == SDL_KEYDOWN ) { #ifndef __ANDROID__ if( (evt.key.keysym.unicode & 0xFF80) == 0 ) evt.key.keysym.unicode = 0; // That's how Android sends keypresses #endif if( evt.key.keysym.sym == SDLK_UNDO ) { if( evt.type == SDL_KEYDOWN ) { if( sInsideSettings ) // TODO: dialog stack? settingsCloseGui(); else exit(0); } } else { if( sInsideSettings ) // TODO: dialog stack? settingsProcessKeyInput(evt.key.keysym.sym, evt.key.keysym.unicode, evt.key.state == SDL_PRESSED); else { if( !processKeyInput(evt.key.keysym.sym, evt.key.keysym.unicode, evt.key.state == SDL_PRESSED) ) { settingsShowGui(); settingsDefineKeycode(evt.key.keysym.sym, evt.key.keysym.unicode); } else if( evt.key.keysym.unicode != 0 && evt.key.state == SDL_PRESSED ) processKeyInput(evt.key.keysym.sym, evt.key.keysym.unicode, false); // Keyboards do not send key-up for international keys } //printf("Got key %d %d", evt.key.keysym.sym, evt.key.state == SDL_PRESSED); } } // PC mouse events if( evt.type == SDL_MOUSEBUTTONUP || evt.type == SDL_MOUSEBUTTONDOWN ) { if( evt.type == SDL_MOUSEBUTTONUP ) touchPointers[evt.jbutton.button - SDL_BUTTON_LEFT].delayRelease = true; // Unpress the button after one extra loop, so we won't lose quick keypresses else touchPointers[evt.jbutton.button - SDL_BUTTON_LEFT].pressed = true; } if( evt.type == SDL_MOUSEMOTION ) { // TODO: implement PC input touchPointers[0].x = evt.motion.x; touchPointers[0].y = evt.motion.y; } // Android-specific events - accelerometer, multitoush, and on-screen joystick if( evt.type == SDL_JOYAXISMOTION ) { if(evt.jaxis.which == 0) // Multitouch and on-screen joysticks { if(evt.jaxis.axis >= 4) touchPointers[evt.jaxis.axis - 4].pressure = evt.jaxis.value; } } if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP ) { if(evt.jbutton.which == 0) // Multitouch and on-screen joystick touchPointers[evt.jbutton.button].pressed = (evt.jbutton.state == SDL_PRESSED); //printf("Touch press %d: %d", evt.jbutton.button, evt.jbutton.state); } if( evt.type == SDL_JOYBALLMOTION ) { if(evt.jball.which == 0) // Multitouch and on-screen joystick { touchPointers[evt.jball.ball].x = evt.jball.xrel; touchPointers[evt.jball.ball].y = evt.jball.yrel; //printf("Touch %d: %d %d", evt.jball.ball, evt.jball.xrel, evt.jball.yrel); } } if( evt.type == SDL_QUIT ) { exit(0); } } SDL_SemTryWait(screenRedrawSemaphore); // Drain the semaphore SDL_FillRect(SDL_GetVideoSurface(), NULL, 0); processGui(); if( !noHid ) { processTouchpad(TOUCHPAD_X0, TOUCHPAD_Y0, TOUCHPAD_X1, TOUCHPAD_Y1); processMouseInput(); } SDL_Flip(SDL_GetVideoSurface()); SDL_SemPost(screenRedrawSemaphore); if( lastEvent + 1000 < SDL_GetTicks() ) SDL_Delay(150); }