Changeset 2001 for code/branches/objecthierarchy/src
- Timestamp:
- Oct 23, 2008, 12:15:09 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/ConsoleCommand.cc
r1755 r2001 41 41 42 42 this->keybindMode_ = KeybindMode::OnPress; 43 this->axisParamIndex_ = -1; 44 this->bAxisRelative_ = false; 43 this->inputConfiguredParam_ = -1; 45 44 } 46 45 -
code/branches/objecthierarchy/src/core/ConsoleCommand.h
r1755 r2001 122 122 { return this->argumentList_.end(); } 123 123 124 inline ConsoleCommand& setAsInputCommand() 125 { 126 this->keybindMode(KeybindMode::OnHold); 127 this->defaultValue(0, Vector2(0.0f, 0.0f)); 128 this->inputConfiguredParam(0); 129 return *this; 130 } 131 124 132 inline ConsoleCommand& keybindMode(KeybindMode::Enum mode) 125 133 { this->keybindMode_ = mode; return *this; } … … 127 135 { return this->keybindMode_; } 128 136 129 inline ConsoleCommand& axisParamIndex(int index) 130 { this->axisParamIndex_ = index; return *this; } 131 inline int getAxisParamIndex() const 132 { return this->axisParamIndex_; } 133 134 inline ConsoleCommand& isAxisRelative(bool val) 135 { this->bAxisRelative_ = val; return *this; } 136 inline int getIsAxisRelative() const 137 { return this->bAxisRelative_; } 137 inline ConsoleCommand& inputConfiguredParam(int index) 138 { this->inputConfiguredParam_ = index; return *this; } 139 inline int getInputConfiguredParam_() const 140 { return this->inputConfiguredParam_; } 138 141 139 142 private: … … 143 146 144 147 KeybindMode::Enum keybindMode_; 145 int axisParamIndex_; 146 bool bAxisRelative_; 148 int inputConfiguredParam_; 147 149 }; 148 150 -
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 -
code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.cc
r1993 r2001 36 36 namespace orxonox 37 37 { 38 SetConsoleCommand(HumanController, moveFrontBack, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);39 SetConsoleCommand(HumanController, moveRightLeft, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);40 SetConsoleCommand(HumanController, moveUpDown, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);41 SetConsoleCommand(HumanController, rotateYaw, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);42 SetConsoleCommand(HumanController, rotatePitch, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);43 SetConsoleCommand(HumanController, rotateRoll, true). defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);44 SetConsoleCommand(HumanController, fire, true). axisParamIndex(0).keybindMode(KeybindMode::OnHold);45 SetConsoleCommand(HumanController, altFire, true). axisParamIndex(0).keybindMode(KeybindMode::OnHold);38 SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand(); 39 SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand(); 40 SetConsoleCommand(HumanController, moveUpDown, true).setAsInputCommand(); 41 SetConsoleCommand(HumanController, rotateYaw, true).setAsInputCommand(); 42 SetConsoleCommand(HumanController, rotatePitch, true).setAsInputCommand(); 43 SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); 44 SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); 45 SetConsoleCommand(HumanController, altFire, true).keybindMode(KeybindMode::OnHold); 46 46 SetConsoleCommand(HumanController, greet, true); 47 47 SetConsoleCommand(HumanController, use, true); … … 64 64 } 65 65 66 void HumanController::moveFrontBack( floatvalue)66 void HumanController::moveFrontBack(const Vector2& value) 67 67 { 68 68 if (HumanController::localController_s && HumanController::localController_s->pawn_) 69 HumanController::localController_s->pawn_->moveFrontBack(value );69 HumanController::localController_s->pawn_->moveFrontBack(value.y); 70 70 } 71 71 72 void HumanController::moveRightLeft( floatvalue)72 void HumanController::moveRightLeft(const Vector2& value) 73 73 { 74 74 if (HumanController::localController_s && HumanController::localController_s->pawn_) 75 HumanController::localController_s->pawn_->moveRightLeft(value );75 HumanController::localController_s->pawn_->moveRightLeft(value.y); 76 76 } 77 77 78 void HumanController::moveUpDown( floatvalue)78 void HumanController::moveUpDown(const Vector2& value) 79 79 { 80 80 if (HumanController::localController_s && HumanController::localController_s->pawn_) 81 HumanController::localController_s->pawn_->moveUpDown(value );81 HumanController::localController_s->pawn_->moveUpDown(value.y); 82 82 } 83 83 84 void HumanController::rotateYaw( floatvalue)84 void HumanController::rotateYaw(const Vector2& value) 85 85 { 86 86 if (HumanController::localController_s && HumanController::localController_s->pawn_) 87 HumanController::localController_s->pawn_->rotateYaw(value );87 HumanController::localController_s->pawn_->rotateYaw(value.y); 88 88 } 89 89 90 void HumanController::rotatePitch( floatvalue)90 void HumanController::rotatePitch(const Vector2& value) 91 91 { 92 92 if (HumanController::localController_s && HumanController::localController_s->pawn_) 93 HumanController::localController_s->pawn_->rotatePitch(value );93 HumanController::localController_s->pawn_->rotatePitch(value.y); 94 94 } 95 95 96 void HumanController::rotateRoll( floatvalue)96 void HumanController::rotateRoll(const Vector2& value) 97 97 { 98 98 if (HumanController::localController_s && HumanController::localController_s->pawn_) 99 HumanController::localController_s->pawn_->rotateRoll(value );99 HumanController::localController_s->pawn_->rotateRoll(value.y); 100 100 } 101 101 -
code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.h
r1993 r2001 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "util/Math.h" 34 35 #include "Controller.h" 35 36 … … 42 43 virtual ~HumanController(); 43 44 44 static void moveFrontBack( floatvalue);45 static void moveRightLeft( floatvalue);46 static void moveUpDown( floatvalue);45 static void moveFrontBack(const Vector2& value); 46 static void moveRightLeft(const Vector2& value); 47 static void moveUpDown(const Vector2& value); 47 48 48 static void rotateYaw( floatvalue);49 static void rotatePitch( floatvalue);50 static void rotateRoll( floatvalue);49 static void rotateYaw(const Vector2& value); 50 static void rotatePitch(const Vector2& value); 51 static void rotateRoll(const Vector2& value); 51 52 52 53 static void fire(); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.cc
r1994 r2001 66 66 this->setVelocity(velocity * this->speed_); 67 67 68 this->yaw(Radian(this->yaw_ * dt * this->rotationSpeed_)); 69 this->pitch(Radian(this->pitch_ * dt * this->rotationSpeed_)); 70 this->roll(Radian(this->roll_ * dt * this->rotationSpeed_)); 68 // TODO: Check why I have removed *dt (1337) 69 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); 70 this->pitch(Radian(this->pitch_ * this->rotationSpeed_)); 71 this->roll(Radian(this->roll_ * this->rotationSpeed_)); 71 72 72 73 this->yaw_ = this->pitch_ = this->roll_ = 0;
Note: See TracChangeset
for help on using the changeset viewer.