Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 23, 2008, 12:15:09 AM (16 years ago)
Author:
rgrieder
Message:
  • Fixed issue with relative mouse movements.
  • Fixed bug when parsing commands in keybindings.ini
  • Fixed potential framerate dependency with relative movements
  • Simplified the use of a configured input command
  • Changed how parametrised input is handled (superposition and [-1,1]-clamp instead of average).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/core/input/KeyBinder.cc

    r1887 r2001  
    137137        SetConfigValue(analogThreshold_, 0.05f)
    138138            .description("Threshold for analog axes until which the state is 0.");
     139        SetConfigValue(bFilterAnalogNoise_, false)
     140            .description("Specifies whether to filter small analog values like joy stick fluctuations.");
    139141        SetConfigValue(mouseSensitivity_, 1.0f)
    140142            .description("Mouse sensitivity.");
     
    145147        SetConfigValue(mouseSensitivityDerived_, 1.0f)
    146148            .description("Mouse sensitivity if mouse input is derived.");
    147         SetConfigValue(mouseWheelStepSize_, 120.0f)
     149        SetConfigValue(mouseWheelStepSize_, 120)
    148150            .description("Equals one step of the mousewheel.");
    149151        SetConfigValue(buttonThreshold_, 0.80f)
     
    323325    void KeyBinder::tickMouse(float dt)
    324326    {
    325         tickDevices(mouseAxes_, mouseAxes_ + MouseAxisCode::numberOfAxes * 2);
    326 
    327327        if (bDeriveMouseInput_)
    328328        {
     329            // only update when derive dt has passed
    329330            if (deriveTime_ > derivePeriod_)
    330331            {
     
    357358                deriveTime_ += dt;
    358359        }
    359     }
    360 
    361     void KeyBinder::tickDevices(HalfAxis* begin, HalfAxis* end)
    362     {
    363         for (HalfAxis* current = begin; current < end; ++current) // pointer arithmetic
    364         {
    365             // button mode
    366             // TODO: optimize out all the half axes that don't act as a button at the moment
    367             if (current->hasChanged_)
    368             {
    369                 if (!current->wasDown_ && current->absVal_ > current->buttonThreshold_)
    370                 {
    371                     current->wasDown_ = true;
    372                     if (current->nCommands_[KeybindMode::OnPress])
    373                         current->execute(KeybindMode::OnPress);
    374                 }
    375                 else if (current->wasDown_ && current->absVal_ < current->buttonThreshold_)
    376                 {
    377                     current->wasDown_ = false;
    378                     if (current->nCommands_[KeybindMode::OnRelease])
    379                         current->execute(KeybindMode::OnRelease);
    380                 }
    381                 current->hasChanged_ = false;
    382             }
    383 
    384             if (current->wasDown_)
    385             {
    386                 if (current->nCommands_[KeybindMode::OnHold])
    387                     current->execute(KeybindMode::OnHold);
    388             }
    389 
    390             // these are the actually useful axis bindings for analog input
    391             if (current->relVal_ > analogThreshold_ || current->absVal_ > analogThreshold_)
    392             {
    393                 current->execute();
    394             }
     360
     361        for (int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     362        {
     363            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
     364            // press a button that has relative movement, that value has to be multiplied by dt to be
     365            // frame rate independant. This can easily (and only) be done in tickInput(float).
     366            // Hence we need to divide by dt here for the mouse to compensate, because the relative
     367            // move movements have nothing to do with dt.
     368            if (dt != 0.0f)
     369            {
     370                // just ignore if dt == 0.0 because we have multiplied by 0.0 anyway..
     371                mouseAxes_[i].relVal_ /= dt;
     372            }
     373
     374            tickHalfAxis(mouseAxes_[i]);
     375        }
     376    }
     377
     378    void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     379    {
     380        for (int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
     381        {
     382            tickHalfAxis(joyStickAxes_[joyStick][i]);
     383        }
     384    }
     385
     386    void KeyBinder::tickHalfAxis(HalfAxis& halfAxis)
     387    {
     388        // button mode
     389        // TODO: optimize out all the half axes that don't act as a button at the moment
     390        if (halfAxis.hasChanged_)
     391        {
     392            if (!halfAxis.pressed_ && halfAxis.absVal_ > halfAxis.buttonThreshold_)
     393            {
     394                // key pressed event
     395                halfAxis.pressed_ = true;
     396                if (halfAxis.nCommands_[KeybindMode::OnPress])
     397                    halfAxis.execute(KeybindMode::OnPress);
     398            }
     399            else if (halfAxis.pressed_ && halfAxis.absVal_ < halfAxis.buttonThreshold_)
     400            {
     401                // key released event
     402                halfAxis.pressed_ = false;
     403                if (halfAxis.nCommands_[KeybindMode::OnRelease])
     404                    halfAxis.execute(KeybindMode::OnRelease);
     405            }
     406            halfAxis.hasChanged_ = false;
     407        }
     408
     409        if (halfAxis.pressed_)
     410        {
     411            // key held event
     412            if (halfAxis.nCommands_[KeybindMode::OnHold])
     413                halfAxis.execute(KeybindMode::OnHold);
     414        }
     415
     416        // these are the actually useful axis bindings for analog input
     417        if (!bFilterAnalogNoise_ || halfAxis.relVal_ > analogThreshold_ || halfAxis.absVal_ > analogThreshold_)
     418        {
     419            halfAxis.execute();
    395420        }
    396421    }
     
    407432        int rel[] = { rel_.x, -rel_.y };
    408433
    409         if (!bDeriveMouseInput_)
     434        if (bDeriveMouseInput_)
     435        {
     436            mouseRelative_[0] += rel[0];
     437            mouseRelative_[1] += rel[1];
     438        }
     439        else
    410440        {
    411441            for (int i = 0; i < 2; i++)
     
    437467            }
    438468        }
    439         else
    440         {
    441             mouseRelative_[0] += rel[0];
    442             mouseRelative_[1] += rel[1];
    443         }
    444469
    445470        // relative
Note: See TracChangeset for help on using the changeset viewer.