mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
TouchscreenVirtualPadDevice rename of variables related to movement or view controls instead of left-right controls
This commit is contained in:
parent
ce0d76be2b
commit
b24e574315
2 changed files with 87 additions and 103 deletions
|
@ -73,8 +73,8 @@ void TouchscreenVirtualPadDevice::setupFixedCenter(VirtualPad::Manager& virtualP
|
||||||
QScreen* eventScreen = qApp->primaryScreen(); // do not call every time
|
QScreen* eventScreen = qApp->primaryScreen(); // do not call every time
|
||||||
_fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius - _extraBottomMargin);
|
_fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius - _extraBottomMargin);
|
||||||
|
|
||||||
_firstTouchLeftPoint = _fixedCenterPosition;
|
_moveRefTouchPoint = _fixedCenterPosition;
|
||||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_moveRefTouchPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
float clip(float n, float lower, float upper) {
|
float clip(float n, float lower, float upper) {
|
||||||
|
@ -116,42 +116,32 @@ glm::vec2 TouchscreenVirtualPadDevice::clippedPointInCircle(float radius, glm::v
|
||||||
return vec2(finalX, finalY);
|
return vec2(finalX, finalY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager) {
|
void TouchscreenVirtualPadDevice::processInputDeviceForMove(VirtualPad::Manager& virtualPadManager) {
|
||||||
vec2 clippedPoint = clippedPointInCircle(_fixedRadiusForCalc, _firstTouchLeftPoint, _currentTouchLeftPoint);
|
vec2 clippedPoint = clippedPointInCircle(_fixedRadiusForCalc, _moveRefTouchPoint, _moveCurrentTouchPoint);
|
||||||
|
|
||||||
_inputDevice->_axisStateMap[controller::LX] = (clippedPoint.x - _firstTouchLeftPoint.x) / _fixedRadiusForCalc;
|
_inputDevice->_axisStateMap[controller::LX] = (clippedPoint.x - _moveRefTouchPoint.x) / _fixedRadiusForCalc;
|
||||||
_inputDevice->_axisStateMap[controller::LY] = (clippedPoint.y - _firstTouchLeftPoint.y) / _fixedRadiusForCalc;
|
_inputDevice->_axisStateMap[controller::LY] = (clippedPoint.y - _moveRefTouchPoint.y) / _fixedRadiusForCalc;
|
||||||
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_moveRefTouchPoint);
|
||||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(clippedPoint);
|
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(clippedPoint);
|
||||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
||||||
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager) {
|
void TouchscreenVirtualPadDevice::processInputDeviceForView() {
|
||||||
float leftDistanceScaleX, leftDistanceScaleY;
|
float rightDistanceScaleX, rightDistanceScaleY;
|
||||||
leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x;
|
rightDistanceScaleX = (_viewCurrentTouchPoint.x - _viewRefTouchPoint.x) / _screenDPIScale.x;
|
||||||
leftDistanceScaleY = (_currentTouchLeftPoint.y - _firstTouchLeftPoint.y) / _screenDPIScale.y;
|
rightDistanceScaleY = (_viewCurrentTouchPoint.y - _viewRefTouchPoint.y) / _screenDPIScale.y;
|
||||||
|
|
||||||
leftDistanceScaleX = clip(leftDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
rightDistanceScaleX = clip(rightDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||||
leftDistanceScaleY = clip(leftDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
rightDistanceScaleY = clip(rightDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||||
|
|
||||||
// NOW BETWEEN -1 1
|
// NOW BETWEEN -1 1
|
||||||
leftDistanceScaleX /= STICK_RADIUS_INCHES;
|
rightDistanceScaleX /= STICK_RADIUS_INCHES;
|
||||||
leftDistanceScaleY /= STICK_RADIUS_INCHES;
|
rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower
|
||||||
|
|
||||||
_inputDevice->_axisStateMap[controller::LX] = leftDistanceScaleX;
|
_inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX;
|
||||||
_inputDevice->_axisStateMap[controller::LY] = leftDistanceScaleY;
|
_inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY;
|
||||||
|
|
||||||
/* Shared variables for stick rendering (clipped to the stick radius)*/
|
|
||||||
// Prevent this for being done when not in first person view
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(
|
|
||||||
glm::vec2(clip(_currentTouchLeftPoint.x, -STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x, STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x),
|
|
||||||
clip(_currentTouchLeftPoint.y, -STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y, STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y))
|
|
||||||
);
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
|
@ -163,8 +153,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
setupFixedCenter(virtualPadManager);
|
setupFixedCenter(virtualPadManager);
|
||||||
|
|
||||||
if (_validTouchLeft) {
|
if (_moveHasValidTouch) {
|
||||||
processInputUseCircleMethod(virtualPadManager);
|
processInputDeviceForMove(virtualPadManager);
|
||||||
} else {
|
} else {
|
||||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(false);
|
virtualPadManager.getLeftVirtualPad()->setBeingTouched(false);
|
||||||
if (_fixedPosition) {
|
if (_fixedPosition) {
|
||||||
|
@ -175,20 +165,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_validTouchRight) {
|
if (_viewHasValidTouch) {
|
||||||
float rightDistanceScaleX, rightDistanceScaleY;
|
processInputDeviceForView();
|
||||||
rightDistanceScaleX = (_currentTouchRightPoint.x - _firstTouchRightPoint.x) / _screenDPIScale.x;
|
|
||||||
rightDistanceScaleY = (_currentTouchRightPoint.y - _firstTouchRightPoint.y) / _screenDPIScale.y;
|
|
||||||
|
|
||||||
rightDistanceScaleX = clip(rightDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
|
||||||
rightDistanceScaleY = clip(rightDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
|
||||||
|
|
||||||
// NOW BETWEEN -1 1
|
|
||||||
rightDistanceScaleX /= STICK_RADIUS_INCHES;
|
|
||||||
rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower
|
|
||||||
|
|
||||||
_inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX;
|
|
||||||
_inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -237,67 +215,67 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) {
|
||||||
void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
touchLeftEnd();
|
moveTouchEnd();
|
||||||
touchRightEnd();
|
viewTouchEnd();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// touch end here is a big reset -> resets both pads
|
// touch end here is a big reset -> resets both pads
|
||||||
_touchPointCount = 0;
|
_touchPointCount = 0;
|
||||||
KeyboardMouseDevice::enableTouch(true);
|
KeyboardMouseDevice::enableTouch(true);
|
||||||
debugPoints(event, " END ----------------");
|
debugPoints(event, " END ----------------");
|
||||||
touchLeftEnd();
|
moveTouchEnd();
|
||||||
touchRightEnd();
|
viewTouchEnd();
|
||||||
_inputDevice->_axisStateMap.clear();
|
_inputDevice->_axisStateMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
touchLeftEnd();
|
moveTouchEnd();
|
||||||
touchRightEnd();
|
viewTouchEnd();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_touchPointCount = event->touchPoints().count();
|
_touchPointCount = event->touchPoints().count();
|
||||||
|
|
||||||
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
|
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
|
||||||
bool leftTouchFound = false;
|
bool moveTouchFound = false;
|
||||||
bool rightTouchFound = false;
|
bool viewTouchFound = false;
|
||||||
glm::vec2 thisPoint;
|
glm::vec2 thisPoint;
|
||||||
for (int i = 0; i < _touchPointCount; ++i) {
|
for (int i = 0; i < _touchPointCount; ++i) {
|
||||||
thisPoint.x = tPoints[i].pos().x();
|
thisPoint.x = tPoints[i].pos().x();
|
||||||
thisPoint.y = tPoints[i].pos().y();
|
thisPoint.y = tPoints[i].pos().y();
|
||||||
// left side and the first one detected counts
|
// movew touch and the first one detected counts
|
||||||
if (thisPoint.x < _screenWidthCenter && !leftTouchFound) {
|
if (thisPoint.x < _screenWidthCenter && !moveTouchFound) {
|
||||||
if (_validTouchLeft) {
|
if (_moveHasValidTouch) {
|
||||||
// valid if it's an ongoing touch
|
// valid if it's an ongoing touch
|
||||||
leftTouchFound = true;
|
moveTouchFound = true;
|
||||||
touchLeftUpdate(thisPoint);
|
moveTouchUpdate(thisPoint);
|
||||||
} else if (touchLeftBeginPointIsValid(thisPoint)) {
|
} else if (moveTouchBeginIsValid(thisPoint)) {
|
||||||
// valid if it's start point is valid
|
// starting point should be valid
|
||||||
leftTouchFound = true;
|
moveTouchFound = true;
|
||||||
touchLeftBegin(thisPoint);
|
moveTouchBegin(thisPoint);
|
||||||
} // if it wasn't even a valid starting point, it won't count as left touch valid
|
} // if it wasn't even a valid starting point, it won't count as a valid movement touch
|
||||||
} else if (thisPoint.x >= _screenWidthCenter) { // right side
|
} else if (thisPoint.x >= _screenWidthCenter) { // right side
|
||||||
if (!rightTouchFound) {
|
if (!viewTouchFound) {
|
||||||
rightTouchFound = true;
|
viewTouchFound = true;
|
||||||
if (!_validTouchRight) {
|
if (!_viewHasValidTouch) {
|
||||||
touchRightBegin(thisPoint);
|
viewTouchBegin(thisPoint);
|
||||||
} else {
|
} else {
|
||||||
// as we don't have a stick on the right side, there is no condition to process right touch
|
// as we don't have a stick on the right side, there is no condition to process right touch
|
||||||
touchRightUpdate(thisPoint);
|
viewTouchUpdate(thisPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!leftTouchFound) {
|
if (!moveTouchFound) {
|
||||||
touchLeftEnd();
|
moveTouchEnd();
|
||||||
}
|
}
|
||||||
if (!rightTouchFound) {
|
if (!viewTouchFound) {
|
||||||
touchRightEnd();
|
viewTouchEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoint) {
|
bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
|
||||||
if (_fixedPosition) {
|
if (_fixedPosition) {
|
||||||
// inside circle
|
// inside circle
|
||||||
return pow(touchPoint.x - _fixedCenterPosition.x,2.0) + pow(touchPoint.y - _fixedCenterPosition.y, 2.0) < pow(_fixedRadius, 2.0);
|
return pow(touchPoint.x - _fixedCenterPosition.x,2.0) + pow(touchPoint.y - _fixedCenterPosition.y, 2.0) < pow(_fixedRadius, 2.0);
|
||||||
|
@ -307,45 +285,45 @@ bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchLeftBegin(glm::vec2 touchPoint) {
|
void TouchscreenVirtualPadDevice::moveTouchBegin(glm::vec2 touchPoint) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
if (_fixedPosition) {
|
if (_fixedPosition) {
|
||||||
_firstTouchLeftPoint = _fixedCenterPosition;
|
_moveRefTouchPoint = _fixedCenterPosition;
|
||||||
} else {
|
} else {
|
||||||
_firstTouchLeftPoint = touchPoint;
|
_moveRefTouchPoint = touchPoint;
|
||||||
}
|
}
|
||||||
_validTouchLeft = true;
|
_moveHasValidTouch = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchLeftUpdate(glm::vec2 touchPoint) {
|
void TouchscreenVirtualPadDevice::moveTouchUpdate(glm::vec2 touchPoint) {
|
||||||
_currentTouchLeftPoint = touchPoint;
|
_moveCurrentTouchPoint = touchPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchLeftEnd() {
|
void TouchscreenVirtualPadDevice::moveTouchEnd() {
|
||||||
if (_validTouchLeft) { // do stuff once
|
if (_moveHasValidTouch) { // do stuff once
|
||||||
_validTouchLeft = false;
|
_moveHasValidTouch = false;
|
||||||
_inputDevice->_axisStateMap[controller::LX] = 0;
|
_inputDevice->_axisStateMap[controller::LX] = 0;
|
||||||
_inputDevice->_axisStateMap[controller::LY] = 0;
|
_inputDevice->_axisStateMap[controller::LY] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchRightBegin(glm::vec2 touchPoint) {
|
void TouchscreenVirtualPadDevice::viewTouchBegin(glm::vec2 touchPoint) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
_firstTouchRightPoint = touchPoint;
|
_viewRefTouchPoint = touchPoint;
|
||||||
_validTouchRight = true;
|
_viewHasValidTouch = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchRightUpdate(glm::vec2 touchPoint) {
|
void TouchscreenVirtualPadDevice::viewTouchUpdate(glm::vec2 touchPoint) {
|
||||||
_currentTouchRightPoint = touchPoint;
|
_viewCurrentTouchPoint = touchPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchRightEnd() {
|
void TouchscreenVirtualPadDevice::viewTouchEnd() {
|
||||||
if (_validTouchRight) { // do stuff once
|
if (_viewHasValidTouch) { // do stuff once
|
||||||
_validTouchRight = false;
|
_viewHasValidTouch = false;
|
||||||
_inputDevice->_axisStateMap[controller::RX] = 0;
|
_inputDevice->_axisStateMap[controller::RX] = 0;
|
||||||
_inputDevice->_axisStateMap[controller::RY] = 0;
|
_inputDevice->_axisStateMap[controller::RY] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,12 +67,15 @@ protected:
|
||||||
float _screenDPI;
|
float _screenDPI;
|
||||||
qreal _screenDPIProvided;
|
qreal _screenDPIProvided;
|
||||||
glm::vec2 _screenDPIScale;
|
glm::vec2 _screenDPIScale;
|
||||||
bool _validTouchLeft;
|
|
||||||
glm::vec2 _firstTouchLeftPoint;
|
bool _moveHasValidTouch;
|
||||||
glm::vec2 _currentTouchLeftPoint;
|
glm::vec2 _moveRefTouchPoint;
|
||||||
bool _validTouchRight;
|
glm::vec2 _moveCurrentTouchPoint;
|
||||||
glm::vec2 _firstTouchRightPoint;
|
|
||||||
glm::vec2 _currentTouchRightPoint;
|
bool _viewHasValidTouch;
|
||||||
|
glm::vec2 _viewRefTouchPoint;
|
||||||
|
glm::vec2 _viewCurrentTouchPoint;
|
||||||
|
|
||||||
int _touchPointCount;
|
int _touchPointCount;
|
||||||
int _screenWidthCenter;
|
int _screenWidthCenter;
|
||||||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||||
|
@ -83,18 +86,21 @@ protected:
|
||||||
float _fixedRadiusForCalc;
|
float _fixedRadiusForCalc;
|
||||||
int _extraBottomMargin {0};
|
int _extraBottomMargin {0};
|
||||||
|
|
||||||
void touchLeftBegin(glm::vec2 touchPoint);
|
void moveTouchBegin(glm::vec2 touchPoint);
|
||||||
void touchLeftUpdate(glm::vec2 touchPoint);
|
void moveTouchUpdate(glm::vec2 touchPoint);
|
||||||
void touchLeftEnd();
|
void moveTouchEnd();
|
||||||
bool touchLeftBeginPointIsValid(glm::vec2 touchPoint);
|
bool moveTouchBeginIsValid(glm::vec2 touchPoint);
|
||||||
void touchRightBegin(glm::vec2 touchPoint);
|
|
||||||
void touchRightUpdate(glm::vec2 touchPoint);
|
void viewTouchBegin(glm::vec2 touchPoint);
|
||||||
void touchRightEnd();
|
void viewTouchUpdate(glm::vec2 touchPoint);
|
||||||
|
void viewTouchEnd();
|
||||||
|
|
||||||
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);
|
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);
|
||||||
|
|
||||||
void processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager);
|
void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager);
|
||||||
void processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager);
|
|
||||||
glm::vec2 clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint);
|
glm::vec2 clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint);
|
||||||
|
|
||||||
|
void processInputDeviceForView();
|
||||||
// just for debug
|
// just for debug
|
||||||
private:
|
private:
|
||||||
void debugPoints(const QTouchEvent* event, QString who);
|
void debugPoints(const QTouchEvent* event, QString who);
|
||||||
|
|
Loading…
Reference in a new issue