Changeset 2087 for code/trunk/src/core/input/InputCommands.cc
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/core/input/InputCommands.cc
r1887 r2087 34 34 35 35 #include "InputCommands.h" 36 #include "util/Math.h" 36 37 #include "core/CommandExecutor.h" 37 38 … … 51 52 bool BufferedParamCommand::execute() 52 53 { 53 if ( nValuesAdded_)54 if (this->abs_ != 0.0f || this->rel_ != 0.0f) 54 55 { 55 BufferedParamCommand& cmd = *this; 56 cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_); 56 evaluation_.setEvaluatedParameter(paramIndex_, Vector2(abs_, rel_)); 57 57 // 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(); 61 61 } 62 62 else … … 79 79 BufferedParamCommand& cmd = *paramCommand_; 80 80 // command has an additional parameter 81 if ( bRelative_)81 if (rel != 0.0f) 82 82 { 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; 89 86 } 90 else if (abs != 0.0f) 87 88 if (abs != 0.0f) 91 89 { 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; 116 95 } 117 96 return true;
Note: See TracChangeset
for help on using the changeset viewer.