Make view/rotation control independent of touchUpdate events rate

This commit is contained in:
Cristian Luis Duarte 2018-04-06 16:17:28 -03:00
parent 1a967e45a6
commit bd6f0fd59e
3 changed files with 13 additions and 4 deletions

View file

@ -10,7 +10,7 @@
{ "from": "TouchscreenVirtualPad.RX", "when": "!Application.CameraIndependent",
"filters": [
{ "type": "deadZone", "min": 0.000 },
{ "type": "scale", "scale": 0.014175 },
{ "type": "scale", "scale": 0.06 },
"invert"
],
"to": "Actions.Yaw"
@ -19,7 +19,7 @@
{ "from": "TouchscreenVirtualPad.RY", "when": "!Application.CameraIndependent",
"filters": [
{ "type": "deadZone", "min": 0.000 },
{ "type": "scale", "scale": 0.014175 },
{ "type": "scale", "scale": 0.06 },
"invert"
],
"to": "Actions.Pitch"

View file

@ -41,6 +41,7 @@ bool TouchscreenVirtualPadDevice::isSupported() const {
void TouchscreenVirtualPadDevice::init() {
_fixedPosition = true; // This should be config
_viewTouchUpdateCount = 0;
QScreen* eventScreen = qApp->primaryScreen();
if (_screenDPIProvided != eventScreen->physicalDotsPerInch()) {
@ -137,10 +138,15 @@ void TouchscreenVirtualPadDevice::processInputDeviceForMove(VirtualPad::Manager&
}
void TouchscreenVirtualPadDevice::processInputDeviceForView() {
_inputDevice->_axisStateMap[controller::RX] = _viewCurrentTouchPoint.x - _viewRefTouchPoint.x;
_inputDevice->_axisStateMap[controller::RY] = _viewCurrentTouchPoint.y - _viewRefTouchPoint.y;
// We use average across how many times we've got touchUpdate events.
// Using the average instead of the full deltaX and deltaY, makes deltaTime in MyAvatar dont't accelerate rotation when there is a low touchUpdate rate (heavier domains).
// (Because it multiplies this input value by deltaTime (with a coefficient)).
_inputDevice->_axisStateMap[controller::RX] = _viewTouchUpdateCount==0?0:(_viewCurrentTouchPoint.x - _viewRefTouchPoint.x)/_viewTouchUpdateCount++;
_inputDevice->_axisStateMap[controller::RY] = _viewTouchUpdateCount==0?0:(_viewCurrentTouchPoint.y - _viewRefTouchPoint.y)/_viewTouchUpdateCount++;
// after use, save last touch point as ref
_viewRefTouchPoint = _viewCurrentTouchPoint;
_viewTouchUpdateCount = 0;
}
void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
@ -427,12 +433,14 @@ void TouchscreenVirtualPadDevice::viewTouchBegin(glm::vec2 touchPoint) {
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
_viewRefTouchPoint = touchPoint;
_viewCurrentTouchPoint = touchPoint;
_viewTouchUpdateCount++;
_viewHasValidTouch = true;
}
}
void TouchscreenVirtualPadDevice::viewTouchUpdate(glm::vec2 touchPoint) {
_viewCurrentTouchPoint = touchPoint;
_viewTouchUpdateCount++;
}
void TouchscreenVirtualPadDevice::viewTouchEnd() {

View file

@ -41,6 +41,7 @@ public:
static const char* NAME;
int _viewTouchUpdateCount;
enum TouchAxisChannel {
LX,
LY,