Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1444 for code/branches/network


Ignore:
Timestamp:
May 28, 2008, 12:01:16 AM (17 years ago)
Author:
rgrieder
Message:

Added 'calibrate' command for the joystick
Simply type 'calibrate', move your axes around, center them press enter again.
Values are stored in keybindings.ini

Location:
code/branches/network/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/ConfigValueContainer.cc

    r1062 r1444  
    139139    /**
    140140        @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
    141         @param input The new value
     141        @param input The new value. If bIsVector_ then write "index value"
    142142        @return True if the new value was successfully assigned
    143143    */
  • code/branches/network/src/core/ConfigValueIncludes.h

    r1428 r1444  
    121121    }
    122122
    123 /**
    124     @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).
    125     @param varname The name of the key-variable
    126 */
    127 #define SetKeybind(keyname) \
    128     orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
    129     if (!container##keyname) \
    130     { \
    131         container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
    132         this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
    133     } \
    134     container##keyname->getValue(&varname)
    135 
    136123#endif /* _ConfigValueIncludes_H__ */
  • code/branches/network/src/core/CorePrereqs.h

    r1414 r1444  
    156156  // input
    157157  //class GUIInputHandler;
     158  class Calibrator;
     159  class CalibratorCallback;
    158160  class InputBuffer;
    159161  class InputBufferListener;
  • code/branches/network/src/core/InputInterfaces.h

    r1413 r1444  
    313313    virtual void joyStickButtonReleased(int joyStickID, int button) = 0;
    314314    virtual void joyStickButtonHeld    (int joyStickID, int button) = 0;
    315     virtual void joyStickAxisMoved     (int joyStickID, int axis, int value) = 0;
     315    virtual void joyStickAxisMoved     (int joyStickID, int axis, float value) = 0;
    316316    //virtual bool joyStickVector3Moved  (int joyStickID, int index /*, fill list*/) {return true;}
    317317    //virtual void tickJoyStick          (float dt) { }
  • code/branches/network/src/core/InputManager.cc

    r1428 r1444  
    3434
    3535#include "InputManager.h"
     36#include "util/Convert.h"
    3637#include "CoreIncludes.h"
     38#include "ConfigValueIncludes.h"
    3739#include "Debug.h"
    3840#include "InputBuffer.h"
     
    4547  ConsoleCommandShortcut(InputManager, keyBind, AccessLevel::User);
    4648  ConsoleCommandShortcut(InputManager, storeKeyStroke, AccessLevel::Offline);
     49  ConsoleCommandShortcut(InputManager, calibrate, AccessLevel::User);
    4750
    4851  // ###############################
     
    5861      inputSystem_(0), keyboard_(0), mouse_(0),
    5962      joySticksSize_(0),
    60       keyBinder_(0), buffer_(0), keyDetector_(0),
     63      keyBinder_(0), keyDetector_(0), buffer_(0), calibratorCallback_(0),
    6164      state_(IS_UNINIT), stateRequest_(IS_UNINIT), savedState_(IS_UNINIT),
    6265      keyboardModifiers_(0)
     
    143146      state_ = IS_NONE;
    144147      CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
     148
     149      // InputManager holds the input buffer --> create one and add it.
     150      buffer_ = new InputBuffer();
     151      addKeyHandler(buffer_, "buffer");
     152
     153      keyBinder_ = new KeyBinder();
     154      keyBinder_->loadBindings();
     155      addKeyHandler(keyBinder_, "keybinder");
     156      addMouseHandler(keyBinder_, "keybinder");
     157      addJoyStickHandler(keyBinder_, "keybinder");
     158
     159      keyDetector_ = new KeyDetector();
     160      keyDetector_->loadBindings();
     161      addKeyHandler(keyDetector_, "keydetector");
     162      addMouseHandler(keyDetector_, "keydetector");
     163      addJoyStickHandler(keyDetector_, "keydetector");
     164
     165      calibratorCallback_ = new CalibratorCallback();
     166      addKeyHandler(calibratorCallback_, "calibratorcallback");
     167
     168      setConfigValues();
     169
     170      CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
    145171    }
    146172    else
     
    148174      CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
    149175    }
    150 
    151     // InputManager holds the input buffer --> create one and add it.
    152     buffer_ = new InputBuffer();
    153     addKeyHandler(buffer_, "buffer");
    154 
    155     keyBinder_ = new KeyBinder();
    156     keyBinder_->loadBindings();
    157     addKeyHandler(keyBinder_, "keybinder");
    158     addMouseHandler(keyBinder_, "keybinder");
    159     addJoyStickHandler(keyBinder_, "keybinder");
    160 
    161     keyDetector_ = new KeyDetector();
    162     keyDetector_->loadBindings();
    163     addKeyHandler(keyDetector_, "keydetector");
    164     addMouseHandler(keyDetector_, "keydetector");
    165     addJoyStickHandler(keyDetector_, "keydetector");
    166 
    167     CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
    168176    return true;
    169177  }
     
    285293    povStates_.resize(joySticksSize_);
    286294    sliderStates_.resize(joySticksSize_);
     295    joySticksCalibration_.resize(joySticksSize_);
     296    for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++)
     297    {
     298      // reset the calibration with default values
     299      for (unsigned int i = 0; i < 24; i++)
     300      {
     301        joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f;
     302        joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f;
     303        joySticksCalibration_[iJoyStick].zeroStates[i] = 0;
     304      }
     305    }
    287306    return success;
     307  }
     308
     309  /**
     310    @brief Sets the configurable values. Use keybindings.ini as file..
     311  */
     312  void InputManager::setConfigValues()
     313  {
     314    if (joySticksSize_)
     315    {
     316      std::vector<MultiTypeMath> coeffPos;
     317      std::vector<MultiTypeMath> coeffNeg;
     318      std::vector<MultiTypeMath> zero;
     319      coeffPos.resize(24);
     320      coeffNeg.resize(24);
     321      zero.resize(24);
     322      for (unsigned int i = 0; i < 24; i++)
     323      {
     324        coeffPos[i] =  1.0f/32767.0f;
     325        coeffNeg[i] =  1.0f/32768.0f;
     326        zero[i]     =  0;
     327      }
     328
     329      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     330      if (!cont)
     331      {
     332          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);
     333          getIdentifier()->addConfigValueContainer("CoeffPos", cont);
     334      }
     335      cont->getValue(&coeffPos);
     336
     337      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     338      if (!cont)
     339      {
     340          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);
     341          getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
     342      }
     343      cont->getValue(&coeffNeg);
     344
     345      cont = getIdentifier()->getConfigValueContainer("Zero");
     346      if (!cont)
     347      {
     348          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);
     349          getIdentifier()->addConfigValueContainer("Zero", cont);
     350      }
     351      cont->getValue(&zero);
     352
     353      // copy values to our own variables
     354      for (unsigned int i = 0; i < 24; i++)
     355      {
     356        joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i];
     357        joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i];
     358        joySticksCalibration_[0].zeroStates[i]    = zero[i];
     359      }
     360    }
    288361  }
    289362
     
    305378      if (keyDetector_)
    306379        delete keyDetector_;
     380
     381      if (calibratorCallback_)
     382        delete calibratorCallback_;
    307383
    308384      keyHandlers_.clear();
     
    313389      _destroyMouse();
    314390      _destroyJoySticks();
     391
     392      activeHandlers_.clear();
    315393
    316394      // inputSystem_ can never be 0, or else the code is mistaken
     
    367445      activeJoyStickHandlers_.clear();
    368446      joyStickButtonsDown_.clear();
     447      povStates_.clear();
     448      sliderStates_.clear();
     449      joySticksCalibration_.clear();
    369450    }
    370451    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
     
    423504    if (state_ != stateRequest_)
    424505    {
    425       if (stateRequest_ != IS_CUSTOM)
    426       {
    427         if (stateRequest_ != IS_DETECT)
     506      InputState sr = stateRequest_;
     507      switch (sr)
     508      {
     509      case IS_NORMAL:
     510        activeKeyHandlers_.clear();
     511        activeMouseHandlers_.clear();
     512        for (unsigned int i = 0; i < joySticksSize_; i++)
     513          activeJoyStickHandlers_[i].clear();
     514
     515        // normal play mode
     516        // note: we assume that the handlers exist since otherwise, something's wrong anyway.
     517        enableKeyHandler("keybinder");
     518        enableMouseHandler("keybinder");
     519        enableJoyStickHandler("keybinder", 0);
     520        stateRequest_ = IS_NORMAL;
     521        state_ = IS_NORMAL;
     522        break;
     523
     524      case IS_GUI:
     525        state_ = IS_GUI;
     526        break;
     527
     528      case IS_CONSOLE:
     529        activeKeyHandlers_.clear();
     530        activeMouseHandlers_.clear();
     531        for (unsigned int i = 0; i < joySticksSize_; i++)
     532          activeJoyStickHandlers_[i].clear();
     533
     534        enableMouseHandler("keybinder");
     535        enableJoyStickHandler("keybinder", 0);
     536        enableKeyHandler("buffer");
     537        stateRequest_ = IS_CONSOLE;
     538        state_ = IS_CONSOLE;
     539        break;
     540
     541      case IS_DETECT:
     542        savedState_ = state_;
     543        _saveState();
     544
     545        activeKeyHandlers_.clear();
     546        activeMouseHandlers_.clear();
     547        for (unsigned int i = 0; i < joySticksSize_; i++)
     548          activeJoyStickHandlers_[i].clear();
     549
     550        enableKeyHandler("keydetector");
     551        enableMouseHandler("keydetector");
     552        enableJoyStickHandler("keydetector", 0);
     553
     554        stateRequest_ = IS_DETECT;
     555        state_ = IS_DETECT;
     556        break;
     557
     558      case IS_NODETECT:
     559        _restoreState();
     560        state_ = IS_NODETECT;
     561        stateRequest_ = savedState_;
     562        break;
     563
     564      case IS_CALIBRATE:
     565        if (joySticksSize_)
    428566        {
     567          savedState_ = _getSingleton().state_;
     568          for (unsigned int i = 0; i < 24; i++)
     569          {
     570            marginalsMax_[i] = INT_MIN;
     571            marginalsMin_[i] = INT_MAX;
     572          }
     573          COUT(3) << "Move all joy stick axes in all directions a few times. "
     574            << "Then put all axes in zero state and hit enter." << std::endl;
     575
     576          savedState_ = state_;
     577          _saveState();
     578
    429579          activeKeyHandlers_.clear();
    430580          activeMouseHandlers_.clear();
    431581          for (unsigned int i = 0; i < joySticksSize_; i++)
    432582            activeJoyStickHandlers_[i].clear();
     583
     584          enableKeyHandler("calibratorcallback");
     585          stateRequest_ = IS_CALIBRATE;
     586          state_ = IS_CALIBRATE;
    433587        }
    434 
    435         switch (stateRequest_)
     588        else
    436589        {
    437         case IS_NORMAL:
    438           // normal play mode
    439           // note: we assume that the handlers exist since otherwise, something's wrong anyway.
    440           enableKeyHandler("keybinder");
    441           enableMouseHandler("keybinder");
    442           enableJoyStickHandler("keybinder", 0);
    443           break;
    444 
    445         case IS_GUI:
    446           break;
    447 
    448         case IS_CONSOLE:
    449           enableMouseHandler("keybinder");
    450           enableJoyStickHandler("keybinder", 0);
    451           enableKeyHandler("buffer");
    452           break;
    453 
    454         case IS_DETECT:
    455           savedState_ = state_;
    456           _saveState();
    457 
    458           activeKeyHandlers_.clear();
    459           activeMouseHandlers_.clear();
    460           for (unsigned int i = 0; i < joySticksSize_; i++)
    461             activeJoyStickHandlers_[i].clear();
    462 
    463           enableKeyHandler("keydetector");
    464           enableMouseHandler("keydetector");
    465           enableJoyStickHandler("keydetector", 0);
    466           break;
    467 
    468         case IS_NODETECT:
    469           _restoreState();
    470           break;
    471 
    472         default:
    473           break;
     590          COUT(3) << "Connot calibrate, no joy stick found!" << std::endl;
     591          stateRequest_ = state_;
    474592        }
    475 
    476         if (stateRequest_ == IS_NODETECT)
    477           state_ = savedState_;
    478         else
    479           state_ = stateRequest_;
     593        break;
     594
     595      case IS_NOCALIBRATE:
     596        _completeCalibration();
     597        _restoreState();
     598        state_ = IS_NOCALIBRATE;
     599        stateRequest_ = savedState_;
     600        break;
     601
     602      case IS_NONE:
     603        activeKeyHandlers_.clear();
     604        activeMouseHandlers_.clear();
     605        for (unsigned int i = 0; i < joySticksSize_; i++)
     606          activeJoyStickHandlers_[i].clear();
     607        state_ = IS_NONE;
     608
     609      default:
     610        break;
    480611      }
    481612    }
     
    489620      joySticks_[i]->capture();
    490621
    491 
    492     // call all the handlers for the held key events
    493     for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    494       for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
    495         activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
    496 
    497     // call all the handlers for the held mouse button events
    498     for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    499       for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    500         activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    501 
    502     // call all the handlers for the held joy stick button events
    503     for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    504       for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    505         for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    506           activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    507 
     622    if (state_ != IS_CALIBRATE)
     623    {
     624      // call all the handlers for the held key events
     625      for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
     626        for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     627          activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
     628
     629      // call all the handlers for the held mouse button events
     630      for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
     631        for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     632          activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
     633
     634      // call all the handlers for the held joy stick button events
     635      for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     636        for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
     637          for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     638            activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     639    }
    508640
    509641    // call the ticks for the handlers (need to be treated specially)
    510642    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
    511643      activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second);
    512 
    513     /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
    514       activeKeyHandlers_[iHandler]->tickKey(dt);
    515     for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    516       activeMouseHandlers_[iHandler]->tickMouse(dt);
    517     for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    518       for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    519         activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/
     644  }
     645
     646  void InputManager::_completeCalibration()
     647  {
     648    for (unsigned int i = 0; i < 24; i++)
     649    {
     650      // positive coefficient
     651      if (marginalsMax_[i] == INT_MIN)
     652        marginalsMax_[i] =  32767;
     653      // coefficients
     654      if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i])
     655        joySticksCalibration_[0].positiveCoeff[i] =  1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]);
     656      else
     657        joySticksCalibration_[0].positiveCoeff[i] =  1.0f;
     658
     659      // config value
     660      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     661      assert(cont);
     662      cont->set(getConvertedValue<int, std::string>(i) + " "
     663        + getConvertedValue<float, std::string>(joySticksCalibration_[0].positiveCoeff[i]));
     664
     665      // negative coefficient
     666      if (marginalsMin_[i] == INT_MAX)
     667        marginalsMin_[i] = -32768;
     668      // coefficients
     669      if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i])
     670        joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]);
     671      else
     672        joySticksCalibration_[0].negativeCoeff[i] =  1.0f;
     673      // config value
     674      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     675      assert(cont);
     676      cont->set(getConvertedValue<int, std::string>(i) + " "
     677        + getConvertedValue<float, std::string>(joySticksCalibration_[0].negativeCoeff[i]));
     678
     679      // zero states
     680      if (i < 8)
     681      {
     682        if (!(i & 1))
     683          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX;
     684        else
     685          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY;
     686      }
     687      else
     688      {
     689        if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size())
     690          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs;
     691        else
     692          joySticksCalibration_[0].zeroStates[i] = 0;
     693      }
     694      // config value
     695      cont = getIdentifier()->getConfigValueContainer("Zero");
     696      assert(cont);
     697      cont->set(getConvertedValue<int, std::string>(i) + " "
     698        + getConvertedValue<int, std::string>(joySticksCalibration_[0].zeroStates[i]));
     699    }
    520700  }
    521701
     
    652832  // ###### Joy Stick Events ######
    653833
    654   bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     834  inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg)
    655835  {
    656836    // use the device to identify which one called the method
     
    658838    unsigned int iJoyStick = 0;
    659839    while (joySticks_[iJoyStick] != joyStick)
     840    {
    660841      iJoyStick++;
     842      if (iJoyStick == joySticksSize_)
     843      {
     844        CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl;
     845        abort();
     846      }
     847    }
     848    return iJoyStick;
     849  }
     850
     851  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     852  {
     853    unsigned int iJoyStick = _getJoystick(arg);
    661854
    662855    // check whether the button already is in the list (can happen when focus was lost)
     
    676869  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
    677870  {
    678     // use the device to identify which one called the method
    679     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    680     unsigned int iJoyStick = 0;
    681     while (joySticks_[iJoyStick] != joyStick)
    682       iJoyStick++;
     871    unsigned int iJoyStick = _getJoystick(arg);
    683872
    684873    // remove the button from the joyStickButtonsDown_ list
     
    699888  }
    700889
     890  void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value)
     891  {
     892    if (state_ == IS_CALIBRATE)
     893    {
     894      if (value > marginalsMax_[axis])
     895        marginalsMax_[axis] = value;
     896      if (value < marginalsMin_[axis])
     897        marginalsMin_[axis] = value;
     898    }
     899    else
     900    {
     901      float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis];
     902      if (fValue > 0.0f)
     903        fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis];
     904      else
     905        fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis];
     906
     907      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     908        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue);
     909    }   
     910  }
     911
    701912  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    702913  {
    703914    //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000)
    704915    //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;}
    705     // use the device to identify which one called the method
    706     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    707     unsigned int iJoyStick = 0;
    708     while (joySticks_[iJoyStick] != joyStick)
    709       iJoyStick++;
     916
     917    unsigned int iJoyStick = _getJoystick(arg);
    710918
    711919    // keep in mind that the first 8 axes are reserved for the sliders
    712     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    713       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
     920    _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
    714921
    715922    return true;
     
    721928    //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;}
    722929    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
    723     // use the device to identify which one called the method
    724     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    725     unsigned int iJoyStick = 0;
    726     while (joySticks_[iJoyStick] != joyStick)
    727       iJoyStick++;
     930
     931    unsigned int iJoyStick = _getJoystick(arg);
    728932
    729933    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
    730     {
    731       // slider X axis changed
    732       sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
    733       for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    734         activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
    735     }
     934      _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX);
    736935    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
    737     {
    738       // slider Y axis changed
    739       sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
    740       for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    741         activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
    742     }
     936      _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
    743937
    744938    return true;
     
    747941  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
    748942  {
    749     // use the device to identify which one called the method
    750     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    751     unsigned int iJoyStick = 0;
    752     while (joySticks_[iJoyStick] != joyStick)
    753       iJoyStick++;
     943    unsigned int iJoyStick = _getJoystick(arg);
    754944
    755945    // translate the POV into 8 simple buttons
     
    765955   
    766956    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
     957
    767958    int currentState = povStates_[iJoyStick][id];
    768959    if (currentState & OIS::Pov::North)
     
    780971  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    781972  {
    782     // use the device to identify which one called the method
    783     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    784     unsigned int iJoyStick = 0;
    785     while (joySticks_[iJoyStick] != joyStick)
    786       iJoyStick++;
     973    unsigned int iJoyStick = _getJoystick(arg);
    787974
    788975    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     
    9431130    bindingCommmandString_s = command;
    9441131    setInputState(IS_DETECT);
     1132    COUT(3) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     1133  }
     1134
     1135  void InputManager::calibrate()
     1136  {
     1137    _getSingleton().setInputState(IS_CALIBRATE);
    9451138  }
    9461139
  • code/branches/network/src/core/InputManager.h

    r1428 r1444  
    7676    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
    7777    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
     78  };
     79
     80  struct JoyStickCalibration
     81  {
     82    int zeroStates[24];
     83    float positiveCoeff[24];
     84    float negativeCoeff[24];
    7885  };
    7986
     
    98105      IS_DETECT,    //!< All the input additionally goes to the KeyDetector
    99106      IS_NODETECT,  //!< remove KeyDetector
     107      IS_NOCALIBRATE,
     108      IS_CALIBRATE,
    100109      IS_CUSTOM     //!< Any possible configuration.
    101110    };
     111
     112  public: // member functions
     113    void setConfigValues();
    102114
    103115  public: // static functions
     
    129141    static void keyBind(const std::string& command);
    130142
     143    static void calibrate();
     144
    131145    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
    132146    static bool removeKeyHandler              (const std::string& name);
     
    171185    void _saveState();
    172186    void _restoreState();
     187
     188    void _completeCalibration();
     189
     190    void _fireAxis(unsigned int iJoyStick, int axis, int value);
     191    unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
    173192
    174193    void tick(float dt);
     
    200219    KeyDetector*                                keyDetector_;     //!< KeyDetector instance
    201220    InputBuffer*                                buffer_;          //!< InputBuffer instance
     221    CalibratorCallback*                         calibratorCallback_;
    202222
    203223    InputState state_;
    204224    InputState stateRequest_;
     225    InputState savedState_;
    205226    unsigned int keyboardModifiers_;
    206     InputState savedState_;
    207227    StoredState savedHandlers_;
     228
     229    // joystick calibration
     230    //std::vector<int> marginalsMaxConfig_;
     231    //std::vector<int> marginalsMinConfig_;
     232    int marginalsMax_[24];
     233    int marginalsMin_[24];
     234    bool bCalibrated_;
    208235
    209236    //! Keeps track of the joy stick POV states
     
    211238    //! Keeps track of the possibly two slider axes
    212239    std::vector<SliderStates>                   sliderStates_;
     240    std::vector<JoyStickCalibration>            joySticksCalibration_;
    213241
    214242    std::map<std::string, KeyHandler*>          keyHandlers_;
  • code/branches/network/src/core/KeyBinder.cc

    r1428 r1444  
    3434#include "KeyBinder.h"
    3535#include <fstream>
     36#include <limits.h>
    3637#include "util/Convert.h"
    3738#include "util/SubString.h"
     
    4243#include "CommandExecutor.h"
    4344#include "Executor.h"
     45// TODO: only needed by the CalibratorCallback class; move to new file
     46#include "InputManager.h"
    4447
    4548namespace orxonox
     
    805808  }
    806809
    807   void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, int value)
     810  void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, float value)
    808811  {
    809812    // TODO: Use proper calibration values instead of generally 16-bit integer
     
    814817      //{ CCOUT(3) << halfAxes_[i].name_ << std::endl; }
    815818
    816       halfAxes_[i].absVal_ = ((float)value)/0x8000;
    817       halfAxes_[i].relVal_ = ((float)value)/0x8000;
     819      halfAxes_[i].absVal_ = value;
     820      halfAxes_[i].relVal_ = value;
    818821      halfAxes_[i].hasChanged_ = true;
    819       if (halfAxes_[i + 1].absVal_ > 0)
     822      if (halfAxes_[i + 1].absVal_ > 0.0f)
    820823      {
    821824        halfAxes_[i + 1].absVal_ = -0.0f;
     
    829832      //{ CCOUT(3) << halfAxes_[i + 1].name_ << std::endl; }
    830833
    831       halfAxes_[i + 1].absVal_ = -((float)value)/0x8000;
    832       halfAxes_[i + 1].relVal_ = -((float)value)/0x8000;
     834      halfAxes_[i + 1].absVal_ = -value;
     835      halfAxes_[i + 1].relVal_ = -value;
    833836      halfAxes_[i + 1].hasChanged_ = true;
    834       if (halfAxes_[i].absVal_ > 0)
     837      if (halfAxes_[i].absVal_ > 0.0f)
    835838      {
    836839        halfAxes_[i].absVal_ = -0.0f;
     
    879882    button.nCommands_[KeybindMode::OnPress] = 1;
    880883  }
    881  
     884
     885
     886  // ###############################
     887  // ##### CalibratorCallback  #####
     888  // ###############################
     889
     890  void CalibratorCallback::keyPressed(const orxonox::KeyEvent &evt)
     891  {
     892    if (evt.key == KeyCode::Return)
     893    {
     894      InputManager::setInputState(InputManager::IS_NOCALIBRATE);
     895    }
     896  }
    882897}
  • code/branches/network/src/core/KeyBinder.h

    r1428 r1444  
    165165    void joyStickButtonReleased(int joyStickID, int button);
    166166    void joyStickButtonHeld    (int joyStickID, int button);
    167     void joyStickAxisMoved     (int joyStickID, int axis, int value);
     167    void joyStickAxisMoved     (int joyStickID, int axis, float value);
    168168
    169169  protected: // variables
     
    192192    *  0 -  3: Mouse x and y
    193193    *  4 -  7: empty
    194     *  8 - 23: joy stick (slider) axes 1 to 8
     194    *  8 - 23: joy stick slider axes 1 to 8
    195195    * 24 - 55: joy stick axes 1 - 16
    196196    */
     
    237237    void readTrigger(Button& button);
    238238  };
     239
     240  class _CoreExport CalibratorCallback : public KeyHandler
     241  {
     242  public:
     243    CalibratorCallback() {}
     244    ~CalibratorCallback() {}
     245
     246  private:
     247    void keyPressed (const KeyEvent& evt);
     248    void keyReleased(const KeyEvent& evt) {}
     249    void keyHeld    (const KeyEvent& evt) {}
     250
     251    void tickInput(float dt, const HandlerState &state) { }
     252  };
    239253}
    240254
  • code/branches/network/src/orxonox/hud/Navigation.cc

    r1411 r1444  
    125125                // top right quadrant
    126126                if(-phiNav<phiUpperCorner){
    127                     COUT(3) << "arrow up\n";
     127                    //COUT(3) << "arrow up\n";
    128128                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
    129129                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     
    132132                }
    133133                else {
    134                     COUT(3) << "arrow right\n";
     134                    //COUT(3) << "arrow right\n";
    135135                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    136136                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
     
    142142                // bottom right quadrant
    143143                if(phiNav<phiUpperCorner) {
    144                     COUT(3) << "arrow down\n";
     144                    //COUT(3) << "arrow down\n";
    145145                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    146146                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     
    149149                }
    150150                else {
    151                     COUT(3) << "arrow right\n";
     151                    //COUT(3) << "arrow right\n";
    152152                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    153153                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
     
    159159                // top left quadrant
    160160                if(phiNav<phiUpperCorner){
    161                     COUT(3) << "arrow up\n";
     161                    //COUT(3) << "arrow up\n";
    162162                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
    163163                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     
    166166                }
    167167                else {
    168                     COUT(3) << "arrow left\n";
     168                    //COUT(3) << "arrow left\n";
    169169                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    170170                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     
    176176                // bottom left quadrant
    177177                if(phiNav>-phiUpperCorner) {
    178                     COUT(3) << "arrow down\n";
     178                    //COUT(3) << "arrow down\n";
    179179                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    180180                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     
    183183                }
    184184                else {
    185                     COUT(3) << "arrow left\n";
     185                    //COUT(3) << "arrow left\n";
    186186                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    187187                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
Note: See TracChangeset for help on using the changeset viewer.