Changeset 2001 for code/branches/objecthierarchy/src/core/input
- Timestamp:
- Oct 23, 2008, 12:15:09 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/core/input
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/input/Button.cc
r1887 r2001 175 175 176 176 // check for param command 177 int paramIndex = eval.getConsoleCommand()->get AxisParamIndex();177 int paramIndex = eval.getConsoleCommand()->getInputConfiguredParam_(); 178 178 if (paramIndex >= 0) 179 179 { 180 180 // parameter supported command 181 181 ParamCommand* cmd = new ParamCommand(); 182 cmd->paramModifier_ = paramModifier; 183 cmd->bRelative_ = eval.getConsoleCommand()->getIsAxisRelative(); 182 cmd->scale_ = paramModifier; 184 183 185 184 // add command to the buffer if not yet existing 186 185 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer_->size(); iParamCmd++) 187 186 { 188 if ( getLowercase((*paramCommandBuffer_)[iParamCmd]->evaluation_.getOriginalCommand())189 == getLowercase(commandStr))187 if ((*paramCommandBuffer_)[iParamCmd]->evaluation_.getConsoleCommand() 188 == eval.getConsoleCommand()) 190 189 { 191 190 // already in list -
code/branches/objecthierarchy/src/core/input/HalfAxis.h
r1887 r2001 50 50 , paramCommands_(0) 51 51 , nParamCommands_(0) 52 , wasDown_(false)52 , pressed_(false) 53 53 , hasChanged_(false) 54 54 { } … … 65 65 66 66 // button related 67 bool wasDown_;67 bool pressed_; 68 68 bool hasChanged_; 69 69 }; -
code/branches/objecthierarchy/src/core/input/InputCommands.cc
r1887 r2001 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; -
code/branches/objecthierarchy/src/core/input/InputCommands.h
r1887 r2001 44 44 { 45 45 public: 46 BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { }46 BufferedParamCommand() : abs_(0.0f), rel_(0.0), paramIndex_(-1) { } 47 47 bool execute(); 48 48 49 float value_;50 unsigned int nValuesAdded_;49 float abs_; 50 float rel_; 51 51 int paramIndex_; 52 52 CommandEvaluation evaluation_; … … 82 82 { 83 83 public: 84 ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }84 ParamCommand() : scale_(1.0f), paramCommand_(0) { } 85 85 bool execute(float abs = 1.0f, float rel = 1.0f); 86 86 87 bool bRelative_; 88 float paramModifier_; 87 float scale_; 89 88 BufferedParamCommand* paramCommand_; 90 89 }; -
code/branches/objecthierarchy/src/core/input/KeyBinder.cc
r1887 r2001 137 137 SetConfigValue(analogThreshold_, 0.05f) 138 138 .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."); 139 141 SetConfigValue(mouseSensitivity_, 1.0f) 140 142 .description("Mouse sensitivity."); … … 145 147 SetConfigValue(mouseSensitivityDerived_, 1.0f) 146 148 .description("Mouse sensitivity if mouse input is derived."); 147 SetConfigValue(mouseWheelStepSize_, 120 .0f)149 SetConfigValue(mouseWheelStepSize_, 120) 148 150 .description("Equals one step of the mousewheel."); 149 151 SetConfigValue(buttonThreshold_, 0.80f) … … 323 325 void KeyBinder::tickMouse(float dt) 324 326 { 325 tickDevices(mouseAxes_, mouseAxes_ + MouseAxisCode::numberOfAxes * 2);326 327 327 if (bDeriveMouseInput_) 328 328 { 329 // only update when derive dt has passed 329 330 if (deriveTime_ > derivePeriod_) 330 331 { … … 357 358 deriveTime_ += dt; 358 359 } 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(); 395 420 } 396 421 } … … 407 432 int rel[] = { rel_.x, -rel_.y }; 408 433 409 if (!bDeriveMouseInput_) 434 if (bDeriveMouseInput_) 435 { 436 mouseRelative_[0] += rel[0]; 437 mouseRelative_[1] += rel[1]; 438 } 439 else 410 440 { 411 441 for (int i = 0; i < 2; i++) … … 437 467 } 438 468 } 439 else440 {441 mouseRelative_[0] += rel[0];442 mouseRelative_[1] += rel[1];443 }444 469 445 470 // relative -
code/branches/objecthierarchy/src/core/input/KeyBinder.h
r1888 r2001 71 71 void tickJoyStick(float dt, unsigned int joyStick); 72 72 // internal 73 void tick Devices(HalfAxis* begin, HalfAxis* end);73 void tickHalfAxis(HalfAxis& halfAxis); 74 74 75 75 void buttonThresholdChanged(); … … 149 149 //! Filename of default keybindings. 150 150 std::string defaultKeybindings_; 151 //! Whether to filter small value analog input 152 bool bFilterAnalogNoise_; 151 153 //! Threshold for analog triggers until which the state is 0. 152 154 float analogThreshold_; … … 162 164 float mouseSensitivityDerived_; 163 165 //! Equals one step of the mousewheel 164 float mouseWheelStepSize_;166 int mouseWheelStepSize_; 165 167 166 168 //##### Constant config variables ##### … … 198 200 { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); } 199 201 200 inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)201 {202 tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]);203 }204 205 202 inline void KeyBinder::tickInput(float dt) 206 203 { 207 204 // execute all buffered bindings (additional parameter) 208 205 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 206 { 207 paramCommandBuffer_[i]->rel_ *= dt; 209 208 paramCommandBuffer_[i]->execute(); 209 } 210 210 211 211 // always reset the relative movement of the mouse
Note: See TracChangeset
for help on using the changeset viewer.