Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/input/InputCommands.cc

    r1887 r2087  
    3434
    3535#include "InputCommands.h"
     36#include "util/Math.h"
    3637#include "core/CommandExecutor.h"
    3738
     
    5152    bool BufferedParamCommand::execute()
    5253    {
    53         if (nValuesAdded_)
     54        if (this->abs_ != 0.0f || this->rel_ != 0.0f)
    5455        {
    55             BufferedParamCommand& cmd = *this;
    56             cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_);
     56            evaluation_.setEvaluatedParameter(paramIndex_, Vector2(abs_, rel_));
    5757            // reset
    58             cmd.nValuesAdded_ = 0;
    59             cmd.value_ = 0;
    60             return cmd.evaluation_.execute();
     58            rel_ = 0.0;
     59            abs_ = 0.0;
     60            return evaluation_.execute();
    6161        }
    6262        else
     
    7979        BufferedParamCommand& cmd = *paramCommand_;
    8080        // command has an additional parameter
    81         if (bRelative_)
     81        if (rel != 0.0f)
    8282        {
    83             if (rel != 0.0f)
    84             {
    85                 // we have to calculate a relative movement.
    86                 // paramModifier_ says how much one keystroke is
    87                 cmd.value_ += paramModifier_ * rel;
    88             }
     83            // calculate relative movement.
     84            // scale_ says how much one keystroke is
     85            cmd.rel_ += scale_ * rel;
    8986        }
    90         else if (abs != 0.0f)
     87
     88        if (abs != 0.0f)
    9189        {
    92             // Usually, joy sticks create 'noise' (they return values if they're in 0 position)
    93             // and normally this is caught in tickInput(), but that threshold cannot be to high
    94             // in order to preserve accuracy. Instead, we have to catch the problem here. An example:
    95             // Someone only uses buttons with an active joystick. The joy stick value could then
    96             // be 0.05 for instance and the the key value 1. Without handling the problem, the final
    97             // value would be computed to (1+0.05)/2=0.5025 which is not what the user expects.
    98             float absQ = abs * abs;
    99             float valueQ = cmd.value_ * cmd.value_;
    100             if (absQ > 50.0f * valueQ) // ease up comparison by using quadratics
    101             {
    102                 cmd.value_ = abs * paramModifier_;
    103                 cmd.nValuesAdded_ = 1;
    104             }
    105             else if (absQ * 50.0f < valueQ)
    106             {
    107                 // abs is too small, we just don't do anything
    108             }
    109             else
    110             {
    111                 // we have to calculate the absolute position of the axis.
    112                 // Since there might be another axis that is affected, we have to wait and
    113                 // store the result in a temporary place
    114                 cmd.value_ = (cmd.value_ * cmd.nValuesAdded_ + paramModifier_ * abs) / ++cmd.nValuesAdded_;
    115             }
     90            cmd.abs_ += scale_ * abs;
     91            if (cmd.abs_ > 1.0)
     92                cmd.abs_ = 1.0;
     93            if (cmd.abs_ < -1.0)
     94                cmd.abs_ = -1.0;
    11695        }
    11796        return true;
Note: See TracChangeset for help on using the changeset viewer.