History

FINe tune the scales for the Mac Book

samcake committed 11 years ago

Commit 8e65ce31 parent 116e29a3 files · +79 −66Browse files

Showing the changes to interface/src/ui/UserInputMapper.cpp (1 of 3 files). Show all

Unified · Split

interface/src/ui/UserInputMapper.cpp+63−51
@@ -11,6 +11,21 @@ · 10 unmodified lines
11#include "UserInputMapper.h"11#include "UserInputMapper.h"
12#include <algorithm>12#include <algorithm>
13 13
14void KeyboardMouseDevice::update() {
15 _axisStateMap.clear();
16
17 // For touch event, we need to check that the last event is not too long ago
18 // Maybe it's a Qt issue, but the touch event sequence (begin, update, end) is not always called properly
19 // The following is a workaround to detect that the touch sequence is over in case we didn;t see the end event
20 if (_isTouching) {
21 const auto TOUCH_EVENT_MAXIMUM_WAIT = 100; //ms
22 auto currentTime = _clock.now();
23 auto sinceLastTouch = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - _lastTouchTime);
24 if (sinceLastTouch.count() > TOUCH_EVENT_MAXIMUM_WAIT) {
25 _isTouching = false;
26 }
27 }
28}
14 29
15void KeyboardMouseDevice::keyPressEvent(QKeyEvent* event) {30void KeyboardMouseDevice::keyPressEvent(QKeyEvent* event) {
16 auto input = makeInput((Qt::Key) event->key());31 auto input = makeInput((Qt::Key) event->key());
@@ -71,7 +86,6 @@ glm::vec2 KeyboardMouseDevice::evalAverageTouchPoints(const QList<QTouchEvent::T · 54 unmodified lines
71 86
72void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {87void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {
73 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);88 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
74
75 _lastTouch = evalAverageTouchPoints(event->touchPoints());89 _lastTouch = evalAverageTouchPoints(event->touchPoints());
76 _lastTouchTime = _clock.now();90 _lastTouchTime = _clock.now();
77}91}
@@ -82,16 +96,10 @@ void KeyboardMouseDevice::touchEndEvent(const QTouchEvent* event) { · 4 unmodified lines
82}96}
83void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {97void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
84 auto currentPos = evalAverageTouchPoints(event->touchPoints());98 auto currentPos = evalAverageTouchPoints(event->touchPoints());
85 99 _lastTouchTime = _clock.now();
86 auto currentTime = _clock.now();100
87 auto sinceLastTouch = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - _lastTouchTime);
88 if (sinceLastTouch.count() > 50) {
89 _isTouching = false;
90 }
91
92 if (!_isTouching) {101 if (!_isTouching) {
93 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);102 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
94 _lastTouchTime = _clock.now();
95 } else {103 } else {
96 auto currentMove = currentPos - _lastTouch;104 auto currentMove = currentPos - _lastTouch;
97 105
@@ -139,9 +147,13 @@ void KeyboardMouseDevice::registerToUserInputMapper(UserInputMapper& mapper) { · 41 unmodified lines
139 147
140void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) {148void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) {
141 const float BUTTON_MOVE_SPEED = 1.0f;149 const float BUTTON_MOVE_SPEED = 1.0f;
142 const float BUTTON_ROTATION_SPEED = 30.0f;150 const float BUTTON_YAW_SPEED = 0.75f;
143 const float MOUSE_ROTATION_SPEED = 0.5f;151 const float BUTTON_PITCH_SPEED = 0.5f;
144 const float BUTTON_BOOM_SPEED = 0.1f;152 const float MOUSE_YAW_SPEED = 0.5f;
153 const float MOUSE_PITCH_SPEED = 0.25f;
154 const float TOUCH_YAW_SPEED = 0.5f;
155 const float TOUCH_PITCH_SPEED = 0.25f;
156 //const float BUTTON_BOOM_SPEED = 0.1f;
145 157
146 // AWSD keys mapping158 // AWSD keys mapping
147 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_S), BUTTON_MOVE_SPEED);159 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_S), BUTTON_MOVE_SPEED);
@@ -153,10 +165,10 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { · 5 unmodified lines
153 165
154 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_W), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);166 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_W), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
155 // mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(Qt::Key_S), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);167 // mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(Qt::Key_S), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
156 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_A), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);168 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_A), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
157 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_D), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);169 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_D), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
158 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_C), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);170 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_C), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
159 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_E), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);171 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_E), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
160 172
161 // Arrow keys mapping173 // Arrow keys mapping
162 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_Down), BUTTON_MOVE_SPEED);174 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_Down), BUTTON_MOVE_SPEED);
@@ -168,36 +180,36 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { · 5 unmodified lines
168 180
169 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);181 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
170 // mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);182 // mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
171 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_Left), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);183 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_Left), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
172 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_Right), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);184 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_Right), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
173 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);185 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
174 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);186 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
175 187
176 // Mouse move188 // Mouse move
177 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(MOUSE_AXIS_Y_NEG), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);189 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(MOUSE_AXIS_Y_NEG), makeInput(Qt::RightButton), MOUSE_PITCH_SPEED);
178 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(MOUSE_AXIS_Y_POS), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);190 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(MOUSE_AXIS_Y_POS), makeInput(Qt::RightButton), MOUSE_PITCH_SPEED);
179 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(MOUSE_AXIS_X_NEG), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);191 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(MOUSE_AXIS_X_NEG), makeInput(Qt::RightButton), MOUSE_YAW_SPEED);
180 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(MOUSE_AXIS_X_POS), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);192 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(MOUSE_AXIS_X_POS), makeInput(Qt::RightButton), MOUSE_YAW_SPEED);
181 193
182 194
183#ifdef Q_OS_MAC195#ifdef Q_OS_MAC
184 // wheel event modifier on Mac collide with the touchpad scroll event196 // wheel event modifier on Mac collide with the touchpad scroll event
185 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), MOUSE_ROTATION_SPEED);197 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), TOUCH_PITCH_SPEED);
186 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), MOUSE_ROTATION_SPEED);198 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), TOUCH_PITCH_SPEED);
187 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), MOUSE_ROTATION_SPEED);199 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), TOUCH_YAW_SPEED);
188 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), MOUSE_ROTATION_SPEED);200 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), TOUCH_YAW_SPEED);
189#else201#else
190 // Touch pad yaw pitch202 // Touch pad yaw pitch
191 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), MOUSE_ROTATION_SPEED);203 mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), TOUCH_PITCH_SPEED);
192 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), MOUSE_ROTATION_SPEED);204 mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), TOUCH_PITCH_SPEED);
193 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), MOUSE_ROTATION_SPEED);205 mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), TOUCH_YAW_SPEED);
194 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), MOUSE_ROTATION_SPEED);206 mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), TOUCH_YAW_SPEED);
195 207
196 // Wheel move208 // Wheel move
197 mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(MOUSE_AXIS_WHEEL_Y_NEG), BUTTON_BOOM_SPEED);209 mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(MOUSE_AXIS_WHEEL_Y_NEG), BUTTON_BOOM_SPEED);
198 mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(MOUSE_AXIS_WHEEL_Y_POS), BUTTON_BOOM_SPEED);210 mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(MOUSE_AXIS_WHEEL_Y_POS), BUTTON_BOOM_SPEED);
199 mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(MOUSE_AXIS_WHEEL_X_NEG), BUTTON_ROTATION_SPEED);211 mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(MOUSE_AXIS_WHEEL_X_NEG), BUTTON_YAW_SPEED);
200 mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_ROTATION_SPEED);212 mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_YAW_SPEED);
201 213
202#endif214#endif
203 215
@@ -218,7 +230,7 @@ float KeyboardMouseDevice::getAxis(int channel) const { · 14 unmodified lines
218 if (axis != _axisStateMap.end()) {230 if (axis != _axisStateMap.end()) {
219 return (*axis).second;231 return (*axis).second;
220 } else {232 } else {
221 return 0.f;233 return 0.0f;
222 }234 }
223}235}
224 236
@@ -313,7 +325,7 @@ void UserInputMapper::update(float deltaTime) { · 88 unmodified lines
313 auto deviceProxy = getDeviceProxy(inputID);325 auto deviceProxy = getDeviceProxy(inputID);
314 switch (inputMapping._input.getType()) {326 switch (inputMapping._input.getType()) {
315 case ChannelType::BUTTON: {327 case ChannelType::BUTTON: {
316 _actionStates[channelInput.first] += inputMapping._scale * float(deviceProxy->getButton(inputID, currentTimestamp)) * deltaTime;328 _actionStates[channelInput.first] += inputMapping._scale * float(deviceProxy->getButton(inputID, currentTimestamp));// * deltaTime; // weight the impulse by the deltaTime
317 break;329 break;
318 }330 }
319 case ChannelType::AXIS: {331 case ChannelType::AXIS: {
@@ -334,24 +346,24 @@ void UserInputMapper::update(float deltaTime) { · 14 unmodified lines
334 }346 }
335 }347 }
336 348
337 // Scale all the channel step with the the unit scale and the time349 // Scale all the channel step with the scale
338 for (auto i = 0; i < NUM_ACTIONS; i++) {350 for (auto i = 0; i < NUM_ACTIONS; i++) {
339 _actionStates[i] *= _actionUnitScales[i];351 _actionStates[i] *= _actionScales[i];
340 }352 }
341}353}
342 354
343 355
344void UserInputMapper::assignDefaulActionUnitScales() {356void UserInputMapper::assignDefaulActionScales() {
345 _actionUnitScales[LONGITUDINAL_BACKWARD] = 1.0f; // 1m per unit357 _actionScales[LONGITUDINAL_BACKWARD] = 1.0f; // 1m per unit
346 _actionUnitScales[LONGITUDINAL_FORWARD] = 1.0f; // 1m per unit358 _actionScales[LONGITUDINAL_FORWARD] = 1.0f; // 1m per unit
347 _actionUnitScales[LATERAL_LEFT] = 1.0f; // 1m per unit359 _actionScales[LATERAL_LEFT] = 1.0f; // 1m per unit
348 _actionUnitScales[LATERAL_RIGHT] = 1.0f; // 1m per unit360 _actionScales[LATERAL_RIGHT] = 1.0f; // 1m per unit
349 _actionUnitScales[VERTICAL_DOWN] = 1.0f; // 1m per unit361 _actionScales[VERTICAL_DOWN] = 1.0f; // 1m per unit
350 _actionUnitScales[VERTICAL_UP] = 1.0f; // 1m per unit362 _actionScales[VERTICAL_UP] = 1.0f; // 1m per unit
351 _actionUnitScales[YAW_LEFT] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit363 _actionScales[YAW_LEFT] = 1.0f; // 1 degree per unit
352 _actionUnitScales[YAW_RIGHT] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit364 _actionScales[YAW_RIGHT] = 1.0f; // 1 degree per unit
353 _actionUnitScales[PITCH_DOWN] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit365 _actionScales[PITCH_DOWN] = 1.0f; // 1 degree per unit
354 _actionUnitScales[PITCH_UP] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit366 _actionScales[PITCH_UP] = 1.0f; // 1 degree per unit
355 _actionUnitScales[BOOM_IN] = 1.0f; // 1m per unit367 _actionScales[BOOM_IN] = 1.0f; // 1m per unit
356 _actionUnitScales[BOOM_OUT] = 1.0f; // 1m per unit368 _actionScales[BOOM_OUT] = 1.0f; // 1m per unit
357}369}