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
1111 #include "UserInputMapper.h"
1212 #include <algorithm>
1313
14+void 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+}
1429
1530 void KeyboardMouseDevice::keyPressEvent(QKeyEvent* event) {
1631 auto input = makeInput((Qt::Key) event->key());
@@ -71,7 +86,6 @@ glm::vec2 KeyboardMouseDevice::evalAverageTouchPoints(const QList<QTouchEvent::T · 54 unmodified lines
7186
7287 void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {
7388 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
74−
7589 _lastTouch = evalAverageTouchPoints(event->touchPoints());
7690 _lastTouchTime = _clock.now();
7791 }
@@ -82,16 +96,10 @@ void KeyboardMouseDevice::touchEndEvent(const QTouchEvent* event) { · 4 unmodified lines
8296 }
8397 void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
8498 auto currentPos = evalAverageTouchPoints(event->touchPoints());
85−
86− auto currentTime = _clock.now();
87− auto sinceLastTouch = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - _lastTouchTime);
88− if (sinceLastTouch.count() > 50) {
89− _isTouching = false;
90− }
91−
99+ _lastTouchTime = _clock.now();
100+
92101 if (!_isTouching) {
93102 _isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
94− _lastTouchTime = _clock.now();
95103 } else {
96104 auto currentMove = currentPos - _lastTouch;
97105
@@ -139,9 +147,13 @@ void KeyboardMouseDevice::registerToUserInputMapper(UserInputMapper& mapper) { · 41 unmodified lines
139147
140148 void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) {
141149 const float BUTTON_MOVE_SPEED = 1.0f;
142− const float BUTTON_ROTATION_SPEED = 30.0f;
143− const float MOUSE_ROTATION_SPEED = 0.5f;
144− const float BUTTON_BOOM_SPEED = 0.1f;
150+ const float BUTTON_YAW_SPEED = 0.75f;
151+ const float BUTTON_PITCH_SPEED = 0.5f;
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;
145157
146158 // AWSD keys mapping
147159 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_S), BUTTON_MOVE_SPEED);
@@ -153,10 +165,10 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { · 5 unmodified lines
153165
154166 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_W), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
155167 // 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);
157− mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_D), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
158− mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_C), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
159− mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_E), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
168+ mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_A), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
169+ mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_D), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
170+ mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_C), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
171+ mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_E), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
160172
161173 // Arrow keys mapping
162174 mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(Qt::Key_Down), BUTTON_MOVE_SPEED);
@@ -168,36 +180,36 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { · 5 unmodified lines
168180
169181 // mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_BOOM_SPEED);
170182 // 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);
172− mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_Right), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
173− mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
174− mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_ROTATION_SPEED);
183+ mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(Qt::Key_Left), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
184+ mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(Qt::Key_Right), makeInput(Qt::Key_Shift), BUTTON_YAW_SPEED);
185+ mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(Qt::Key_Down), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
186+ mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(Qt::Key_Up), makeInput(Qt::Key_Shift), BUTTON_PITCH_SPEED);
175187
176188 // Mouse move
177− mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(MOUSE_AXIS_Y_NEG), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);
178− mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(MOUSE_AXIS_Y_POS), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);
179− mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(MOUSE_AXIS_X_NEG), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);
180− mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(MOUSE_AXIS_X_POS), makeInput(Qt::RightButton), MOUSE_ROTATION_SPEED);
189+ mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(MOUSE_AXIS_Y_NEG), makeInput(Qt::RightButton), MOUSE_PITCH_SPEED);
190+ mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(MOUSE_AXIS_Y_POS), makeInput(Qt::RightButton), MOUSE_PITCH_SPEED);
191+ mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(MOUSE_AXIS_X_NEG), makeInput(Qt::RightButton), MOUSE_YAW_SPEED);
192+ mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(MOUSE_AXIS_X_POS), makeInput(Qt::RightButton), MOUSE_YAW_SPEED);
181193
182194
183195 #ifdef Q_OS_MAC
184196 // 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);
186− mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), MOUSE_ROTATION_SPEED);
187− mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), MOUSE_ROTATION_SPEED);
188− mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), MOUSE_ROTATION_SPEED);
197+ mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), TOUCH_PITCH_SPEED);
198+ mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), TOUCH_PITCH_SPEED);
199+ mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), TOUCH_YAW_SPEED);
200+ mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), TOUCH_YAW_SPEED);
189201 #else
190202 // Touch pad yaw pitch
191− mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), MOUSE_ROTATION_SPEED);
192− mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), MOUSE_ROTATION_SPEED);
193− mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), MOUSE_ROTATION_SPEED);
194− mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), MOUSE_ROTATION_SPEED);
203+ mapper.addInputChannel(UserInputMapper::PITCH_DOWN, makeInput(TOUCH_AXIS_Y_NEG), TOUCH_PITCH_SPEED);
204+ mapper.addInputChannel(UserInputMapper::PITCH_UP, makeInput(TOUCH_AXIS_Y_POS), TOUCH_PITCH_SPEED);
205+ mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(TOUCH_AXIS_X_NEG), TOUCH_YAW_SPEED);
206+ mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), TOUCH_YAW_SPEED);
195207
196208 // Wheel move
197209 mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(MOUSE_AXIS_WHEEL_Y_NEG), BUTTON_BOOM_SPEED);
198210 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);
200− mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_ROTATION_SPEED);
211+ mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(MOUSE_AXIS_WHEEL_X_NEG), BUTTON_YAW_SPEED);
212+ mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_YAW_SPEED);
201213
202214 #endif
203215
@@ -218,7 +230,7 @@ float KeyboardMouseDevice::getAxis(int channel) const { · 14 unmodified lines
218230 if (axis != _axisStateMap.end()) {
219231 return (*axis).second;
220232 } else {
221− return 0.f;
233+ return 0.0f;
222234 }
223235 }
224236
@@ -313,7 +325,7 @@ void UserInputMapper::update(float deltaTime) { · 88 unmodified lines
313325 auto deviceProxy = getDeviceProxy(inputID);
314326 switch (inputMapping._input.getType()) {
315327 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
317329 break;
318330 }
319331 case ChannelType::AXIS: {
@@ -334,24 +346,24 @@ void UserInputMapper::update(float deltaTime) { · 14 unmodified lines
334346 }
335347 }
336348
337− // Scale all the channel step with the the unit scale and the time
349+ // Scale all the channel step with the scale
338350 for (auto i = 0; i < NUM_ACTIONS; i++) {
339− _actionStates[i] *= _actionUnitScales[i];
351+ _actionStates[i] *= _actionScales[i];
340352 }
341353 }
342354
343355
344−void UserInputMapper::assignDefaulActionUnitScales() {
345− _actionUnitScales[LONGITUDINAL_BACKWARD] = 1.0f; // 1m per unit
346− _actionUnitScales[LONGITUDINAL_FORWARD] = 1.0f; // 1m per unit
347− _actionUnitScales[LATERAL_LEFT] = 1.0f; // 1m per unit
348− _actionUnitScales[LATERAL_RIGHT] = 1.0f; // 1m per unit
349− _actionUnitScales[VERTICAL_DOWN] = 1.0f; // 1m per unit
350− _actionUnitScales[VERTICAL_UP] = 1.0f; // 1m per unit
351− _actionUnitScales[YAW_LEFT] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit
352− _actionUnitScales[YAW_RIGHT] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit
353− _actionUnitScales[PITCH_DOWN] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit
354− _actionUnitScales[PITCH_UP] = 1.0f;//glm::radians<float>(1.0f); // 3 degree per unit
355− _actionUnitScales[BOOM_IN] = 1.0f; // 1m per unit
356− _actionUnitScales[BOOM_OUT] = 1.0f; // 1m per unit
356+void UserInputMapper::assignDefaulActionScales() {
357+ _actionScales[LONGITUDINAL_BACKWARD] = 1.0f; // 1m per unit
358+ _actionScales[LONGITUDINAL_FORWARD] = 1.0f; // 1m per unit
359+ _actionScales[LATERAL_LEFT] = 1.0f; // 1m per unit
360+ _actionScales[LATERAL_RIGHT] = 1.0f; // 1m per unit
361+ _actionScales[VERTICAL_DOWN] = 1.0f; // 1m per unit
362+ _actionScales[VERTICAL_UP] = 1.0f; // 1m per unit
363+ _actionScales[YAW_LEFT] = 1.0f; // 1 degree per unit
364+ _actionScales[YAW_RIGHT] = 1.0f; // 1 degree per unit
365+ _actionScales[PITCH_DOWN] = 1.0f; // 1 degree per unit
366+ _actionScales[PITCH_UP] = 1.0f; // 1 degree per unit
367+ _actionScales[BOOM_IN] = 1.0f; // 1m per unit
368+ _actionScales[BOOM_OUT] = 1.0f; // 1m per unit
357369 }