Beispiel #1
0
    // Used to check for movement keys
    bool frameStarted(const Ogre::FrameEvent &evt)
    {
        // Tell OIS to handle all input events
        input.capture();

        // Disable movement in Gui mode
        if(windows.isGuiMode()) return true;

        float speed = 300 * evt.timeSinceLastFrame;
        float moveX = 0, moveY = 0, moveZ = 0;

        if(poller.isDown(A_MoveLeft)) moveX -= speed;
        if(poller.isDown(A_MoveRight)) moveX += speed;
        if(poller.isDown(A_MoveForward)) moveZ -= speed;
        if(poller.isDown(A_MoveBackward)) moveZ += speed;

        // TODO: These should be enabled for floating modes (like
        // swimming and levitation) and disabled for everything else.
        if(poller.isDown(A_MoveUp)) moveY += speed;
        if(poller.isDown(A_MoveDown)) moveY -= speed;

        if(moveX != 0 || moveY != 0 || moveZ != 0)
            player.moveRel(moveX, moveY, moveZ);

        return true;
    }
Beispiel #2
0
    // Used to check for movement keys
    bool frameStarted(const Ogre::FrameEvent &evt)
    {
      // Tell OIS to handle all input events
      input.capture();

      // Update windows/gui as a result of input events
      // For instance this could mean opening a new window/dialog,
      // by doing this after the input events are handled we
      // ensure that window/gui changes appear quickly while
      // avoiding that window/gui changes does not happen in
      // event callbacks (which may crash)
      windows.update();

      // Disable movement in Gui mode
      if(windows.isGuiMode()) return true;

      float speed = 300 * evt.timeSinceLastFrame;
      float moveX = 0, moveY = 0, moveZ = 0;

      if(poller.isDown(A_MoveLeft)) moveX -= speed;
      if(poller.isDown(A_MoveRight)) moveX += speed;
      if(poller.isDown(A_MoveForward)) moveZ -= speed;
      if(poller.isDown(A_MoveBackward)) moveZ += speed;

      // TODO: These should be enabled for floating modes (like
      // swimming and levitation) and disabled for everything else.
      if(poller.isDown(A_MoveUp)) moveY += speed;
      if(poller.isDown(A_MoveDown)) moveY -= speed;

      if(moveX != 0 || moveY != 0 || moveZ != 0)
        player.moveRel(moveX, moveY, moveZ);


      return true;
    }
Beispiel #3
0
    //NOTE: Used to check for movement keys
    void update ()
    {
        // Tell OIS to handle all input events
        input.capture();

        // Update windows/gui as a result of input events
        // For instance this could mean opening a new window/dialog,
        // by doing this after the input events are handled we
        // ensure that window/gui changes appear quickly while
        // avoiding that window/gui changes does not happen in
        // event callbacks (which may crash)
        windows.update();

        // Disable movement in Gui mode

        if (windows.isGuiMode()) return;

        // Configure player movement according to keyboard input. Actual movement will
        // be done in the physics system.
        if (poller.isDown(A_MoveLeft))
        {
            player.setAutoMove (false);
            player.setLeftRight (1);
        }
        else if (poller.isDown(A_MoveRight))
        {
            player.setAutoMove (false);
            player.setLeftRight (-1);
        }
        else
            player.setLeftRight (0);

        if (poller.isDown(A_MoveForward))
        {
            player.setAutoMove (false);
            player.setForwardBackward (1);
        }
        else if (poller.isDown(A_MoveBackward))
        {
            player.setAutoMove (false);
            player.setForwardBackward (-1);
        }
        else
            player.setForwardBackward (0);

        if (poller.isDown(A_Jump))
            player.setUpDown (1);
        else if (poller.isDown(A_Crouch))
            player.setUpDown (-1);
        else
            player.setUpDown (0);
    }
Beispiel #4
0
    InputImpl(OEngine::Render::OgreRenderer &_ogre,
              MWRender::PlayerPos &_player,
              MWGui::WindowManager &_windows,
              bool debug)
        : ogre(_ogre),
          exit(ogre.getWindow()),
          input(ogre.getWindow(), !debug),
          poller(input),
          player(_player),
          windows(_windows),
          shotCount(0)
    {
        using namespace OEngine::Input;
        using namespace OEngine::Render;
        using namespace OEngine::GUI;
        using namespace Mangle::Input;
        using namespace OIS;

        disp = DispatcherPtr(new Dispatcher(A_LAST));

        // Bind MW-specific functions
        disp->funcs.bind(A_Quit, boost::bind(&InputImpl::exitNow, this),
                         "Quit program");
        disp->funcs.bind(A_Screenshot, boost::bind(&InputImpl::screenshot, this),
                         "Screenshot");
        disp->funcs.bind(A_Inventory, boost::bind(&InputImpl::toggleInventory, this),
                         "Toggle inventory screen");
        disp->funcs.bind(A_Console, boost::bind(&InputImpl::toggleConsole, this),
                         "Toggle console");


        // Add the exit listener
        ogre.getRoot()->addFrameListener(&exit);
        // Add ourselves as a frame listener to catch movement keys
        ogre.getRoot()->addFrameListener(this);

        // Set up the mouse handler and tell it about the player camera
        mouse = MouseLookEventPtr(new MouseLookEvent(player.getCamera()));

        // This event handler pumps events into MyGUI
        guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));

        // Hook 'mouse' and 'disp' up as event handlers into 'input'
        // (the OIS driver and event source.) We do this through an
        // EventList which dispatches the event to multiple handlers for
        // us.
        {
            EventList *lst = new EventList;
            input.setEvent(EventPtr(lst));
            lst->add(mouse,Event::EV_MouseMove);
            lst->add(disp,Event::EV_KeyDown);
            lst->add(guiEvents,Event::EV_ALL);
        }

        // Start out in game mode
        setGuiMode(MWGui::GM_Game);

        /**********************************
          Key binding section

          The rest of this function has hard coded key bindings, and is
          intended to be replaced by user defined bindings later.
         **********************************/

        // Key bindings for keypress events

        disp->bind(A_Quit, KC_Q);
        disp->bind(A_Quit, KC_ESCAPE);
        disp->bind(A_Screenshot, KC_SYSRQ);
        disp->bind(A_Inventory, KC_I);
        disp->bind(A_Console, KC_F1);

        // Key bindings for polled keys

        // Arrow keys
        poller.bind(A_MoveLeft, KC_LEFT);
        poller.bind(A_MoveRight, KC_RIGHT);
        poller.bind(A_MoveForward, KC_UP);
        poller.bind(A_MoveBackward, KC_DOWN);

        // WASD keys
        poller.bind(A_MoveLeft, KC_A);
        poller.bind(A_MoveRight, KC_D);
        poller.bind(A_MoveForward, KC_W);
        poller.bind(A_MoveBackward, KC_S);

        // Use shift and ctrl for up and down
        poller.bind(A_MoveUp, KC_LSHIFT);
        poller.bind(A_MoveDown, KC_LCONTROL);
    }
Beispiel #5
0
    InputImpl(OEngine::Render::OgreRenderer &_ogre,
              MWWorld::Player &_player,
              MWGui::WindowManager &_windows,
              bool debug,
              OMW::Engine& engine)
        : ogre(_ogre),
          exit(ogre.getWindow()),
          input(ogre.getWindow(), !debug),
          poller(input),
          player(_player),
          windows(_windows),
          mEngine (engine),
          shotCount(0)
    {
        using namespace OEngine::Input;
        using namespace OEngine::Render;
        using namespace OEngine::GUI;
        using namespace Mangle::Input;
        using namespace OIS;

        disp = DispatcherPtr(new Dispatcher(A_LAST));

        // Bind MW-specific functions
        disp->funcs.bind(A_Quit, boost::bind(&InputImpl::exitNow, this),
                         "Quit program");
        disp->funcs.bind(A_Screenshot, boost::bind(&InputImpl::screenshot, this),
                         "Screenshot");
        disp->funcs.bind(A_Inventory, boost::bind(&InputImpl::toggleInventory, this),
                         "Toggle inventory screen");
        disp->funcs.bind(A_Console, boost::bind(&InputImpl::toggleConsole, this),
                         "Toggle console");
        disp->funcs.bind(A_Activate, boost::bind(&InputImpl::activate, this),
                         "Activate");
        disp->funcs.bind(A_AutoMove, boost::bind(&InputImpl::toggleAutoMove, this),
                         "Auto Move");
        disp->funcs.bind(A_ToggleWalk, boost::bind(&InputImpl::toggleWalking, this),
                         "Toggle Walk/Run");

        // Add the exit listener
        ogre.getRoot()->addFrameListener(&exit);
        // Add ourselves as a frame listener to catch movement keys
        ogre.getRoot()->addFrameListener(this);

        // Set up the mouse handler and tell it about the player camera
        mouse = MouseLookEventPtr(new MouseLookEvent(player.getRenderer()->getCamera()));

        // This event handler pumps events into MyGUI
        guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));

        // Hook 'mouse' and 'disp' up as event handlers into 'input'
        // (the OIS driver and event source.) We do this through an
        // EventList which dispatches the event to multiple handlers for
        // us.
        {
            EventList *lst = new EventList;
            input.setEvent(EventPtr(lst));
            lst->add(mouse,Event::EV_MouseMove);
            lst->add(disp,Event::EV_KeyDown);
            lst->add(guiEvents,Event::EV_ALL);
        }

        // Start out in game mode
        setGuiMode(MWGui::GM_Game);

        /**********************************
          Key binding section

          The rest of this function has hard coded key bindings, and is
          intended to be replaced by user defined bindings later.
         **********************************/

        // Key bindings for keypress events
        // NOTE: These keys do not require constant polling - use in conjuction with variables in loops.

        disp->bind(A_Quit, KC_Q);
        disp->bind(A_Quit, KC_ESCAPE);
        disp->bind(A_Screenshot, KC_SYSRQ);
        disp->bind(A_Inventory, KC_I);
        disp->bind(A_Console, KC_F1);
        disp->bind(A_Activate, KC_SPACE);
        disp->bind(A_AutoMove, KC_Z);
        disp->bind(A_ToggleSneak, KC_X);
        disp->bind(A_ToggleWalk, KC_C);

        // Key bindings for polled keys
        // NOTE: These keys are constantly being polled. Only add keys that must be checked each frame.

        // Arrow keys
        poller.bind(A_MoveLeft, KC_LEFT);
        poller.bind(A_MoveRight, KC_RIGHT);
        poller.bind(A_MoveForward, KC_UP);
        poller.bind(A_MoveBackward, KC_DOWN);

        // WASD keys
        poller.bind(A_MoveLeft, KC_A);
        poller.bind(A_MoveRight, KC_D);
        poller.bind(A_MoveForward, KC_W);
        poller.bind(A_MoveBackward, KC_S);
    }
Beispiel #6
0
 void adjustMouseRegion(int width, int height)
 {
     input.adjustMouseClippingSize(width, height);
 }
Beispiel #7
0
    //NOTE: Used to check for movement keys
    void update (float duration)
    {
        // Tell OIS to handle all input events
        input.capture();

        // Update windows/gui as a result of input events
        // For instance this could mean opening a new window/dialog,
        // by doing this after the input events are handled we
        // ensure that window/gui changes appear quickly while
        // avoiding that window/gui changes does not happen in
        // event callbacks (which may crash)
        windows.update();

        // Disable movement in Gui mode

        if (windows.isGuiMode()) return;

        // Configure player movement according to keyboard input. Actual movement will
        // be done in the physics system.
        if (mControlSwitch["playercontrols"]) {
            if (poller.isDown(A_MoveLeft))
            {
                player.setAutoMove (false);
                player.setLeftRight (1);
            }
            else if (poller.isDown(A_MoveRight))
            {
                player.setAutoMove (false);
                player.setLeftRight (-1);
            }
            else
                player.setLeftRight (0);

            if (poller.isDown(A_MoveForward))
            {
                player.setAutoMove (false);
                player.setForwardBackward (1);
            }
            else if (poller.isDown(A_MoveBackward))
            {
                player.setAutoMove (false);
                player.setForwardBackward (-1);
            }
            else
                player.setForwardBackward (0);

            if (poller.isDown(A_Jump) && mControlSwitch["playerjumping"])
                player.setUpDown (1);
            else if (poller.isDown(A_Crouch))
                player.setUpDown (-1);
            else
                player.setUpDown (0);

            if (mControlSwitch["playerviewswitch"]) {
                if (poller.isDown(A_TogglePOV)) {
                    if (mPreviewPOVDelay <= 0.5 &&
                        (mPreviewPOVDelay += duration) > 0.5)
                    {
                        mPreviewPOVDelay = 1.f;
                        MWBase::Environment::get().getWorld()->togglePreviewMode(true);
                    }
                } else {
                    if (mPreviewPOVDelay > 0.5) {
                        //disable preview mode
                        MWBase::Environment::get().getWorld()->togglePreviewMode(false);
                    } else if (mPreviewPOVDelay > 0.f) {
                        togglePOV();
                    }
                    mPreviewPOVDelay = 0.f;
                }
            }
        }
        // Idle time update despite of control switches
        if (poller.isDown(A_MoveLeft) ||
            poller.isDown(A_MoveRight) ||
            poller.isDown(A_MoveForward) ||
            poller.isDown(A_MoveBackward) ||
            poller.isDown(A_Jump) ||
            poller.isDown(A_Crouch) ||
            poller.isDown(A_TogglePOV))
        {
            resetIdleTime();
        } else {
            updateIdleTime(duration);
        }
    }
Beispiel #8
0
    InputImpl(OEngine::Render::OgreRenderer &_ogre,
                   MWWorld::Player &_player,
                   MWBase::WindowManager &_windows,
                   bool debug,
                   OMW::Engine& engine)
      : ogre(_ogre),
        input(ogre.getWindow(), !debug),
        poller(input),
        player(_player),
        windows(_windows),
        mEngine (engine),
        mDragDrop(false),
        mPreviewPOVDelay(0.f),
        mTimeIdle(0.f)
    {
      using namespace OEngine::Input;
      using namespace OEngine::Render;
      using namespace OEngine::GUI;
      using namespace Mangle::Input;
      using namespace OIS;

      disp = DispatcherPtr(new Dispatcher(A_LAST));

      // Bind MW-specific functions
      disp->funcs.bind(A_Quit, boost::bind(&InputImpl::exitNow, this),
                      "Quit program");
      disp->funcs.bind(A_Screenshot, boost::bind(&InputImpl::screenshot, this),
                      "Screenshot");
      disp->funcs.bind(A_Inventory, boost::bind(&InputImpl::toggleInventory, this),
                       "Toggle inventory screen");
      disp->funcs.bind(A_Console, boost::bind(&InputImpl::toggleConsole, this),
                       "Toggle console");
      disp->funcs.bind(A_Journal, boost::bind(&InputImpl::toggleJournal, this),
                       "Toggle journal");
      disp->funcs.bind(A_Activate, boost::bind(&InputImpl::activate, this),
                       "Activate");
      disp->funcs.bind(A_AutoMove, boost::bind(&InputImpl::toggleAutoMove, this),
                      "Auto Move");
      disp->funcs.bind(A_ToggleWalk, boost::bind(&InputImpl::toggleWalking, this),
                      "Toggle Walk/Run");
      disp->funcs.bind(A_ToggleWeapon,boost::bind(&InputImpl::toggleWeapon,this),
                      "Draw Weapon");
      disp->funcs.bind(A_ToggleSpell,boost::bind(&InputImpl::toggleSpell,this),
                      "Ready hands");
      disp->funcs.bind(A_GameMenu, boost::bind(&InputImpl::toggleMainMenu, this),
                      "Toggle main menu");

      mouse = MouseLookEventPtr(new MouseLookEvent());

      // This event handler pumps events into MyGUI
      guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));

      // Hook 'mouse' and 'disp' up as event handlers into 'input'
      // (the OIS driver and event source.) We do this through an
      // EventList which dispatches the event to multiple handlers for
      // us.
      {
        EventList *lst = new EventList;
        input.setEvent(EventPtr(lst));
        lst->add(mouse,Event::EV_MouseMove);
        lst->add(disp,Event::EV_KeyDown);
        lst->add(guiEvents,Event::EV_ALL);
      }

      mControlSwitch["playercontrols"]      = true;
      mControlSwitch["playerfighting"]      = true;
      mControlSwitch["playerjumping"]       = true;
      mControlSwitch["playerlooking"]       = true;
      mControlSwitch["playermagic"]         = true;
      mControlSwitch["playerviewswitch"]    = true;
      mControlSwitch["vanitymode"]          = true;

      changeInputMode(false);

      /**********************************
        Key binding section

        The rest of this function has hard coded key bindings, and is
        intended to be replaced by user defined bindings later.
       **********************************/

      // Key bindings for keypress events
      // NOTE: These keys do not require constant polling - use in conjuction with variables in loops.

      disp->bind(A_Quit, KC_Q);
      disp->bind(A_GameMenu, KC_ESCAPE);
      disp->bind(A_Screenshot, KC_SYSRQ);
      disp->bind(A_Inventory, KC_I);
      disp->bind(A_Console, KC_F1);
      disp->bind(A_Journal, KC_J);
      disp->bind(A_Activate, KC_SPACE);
      disp->bind(A_AutoMove, KC_Z);
      disp->bind(A_ToggleSneak, KC_X);
      disp->bind(A_ToggleWalk, KC_C);
      disp->bind(A_ToggleWeapon,KC_F);
      disp->bind(A_ToggleSpell,KC_R);

      // Key bindings for polled keys
      // NOTE: These keys are constantly being polled. Only add keys that must be checked each frame.

      // Arrow keys
      poller.bind(A_MoveLeft, KC_LEFT);
      poller.bind(A_MoveRight, KC_RIGHT);
      poller.bind(A_MoveForward, KC_UP);
      poller.bind(A_MoveBackward, KC_DOWN);

      // WASD keys
      poller.bind(A_MoveLeft, KC_A);
      poller.bind(A_MoveRight, KC_D);
      poller.bind(A_MoveForward, KC_W);
      poller.bind(A_MoveBackward, KC_S);

      poller.bind(A_Jump, KC_E);
      poller.bind(A_Crouch, KC_LCONTROL);

      poller.bind(A_TogglePOV, KC_TAB);
    }