Android - Handshake implementation - two important notes - IK was disabled on android and this enables it (needs a well thought review) - TouchscreenVirtualPadDevice buttons code does not scale well, it needs a refactor

This commit is contained in:
Cristian Luis Duarte 2018-08-29 18:53:14 -03:00
parent 657373d02f
commit 4f3a730d6d
10 changed files with 130 additions and 6 deletions

View file

@ -23,7 +23,9 @@
"invert"
],
"to": "Actions.Pitch"
}
},
{ "from": "TouchscreenVirtualPad.RB", "to": "Standard.RB"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View file

@ -851,10 +851,12 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
//virtual
const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut, const AnimPoseVec& underPoses) {
/* We need this working so body parts can move
#ifdef Q_OS_ANDROID
// disable IK on android
return underPoses;
#endif
*/
// allows solutionSource to be overridden by an animVar
auto solutionSource = animVars.lookup(_solutionSourceVar, (int)_solutionSource);

View file

@ -99,6 +99,31 @@ void Basic2DWindowOpenGLDisplayPlugin::customizeContext() {
_virtualPadJumpBtnTexture->setAutoGenerateMips(true);
}
}
_virtualPadRbBtnPixelSize = dpi * VirtualPad::Manager::JUMP_BTN_FULL_PIXELS / VirtualPad::Manager::DPI;
if (!_virtualPadRbBtnTexture) {
auto iconPath = PathUtils::resourcesPath() + "images/handshake.png";
auto image = QImage(iconPath);
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
}
if ((image.width() > 0) && (image.height() > 0)) {
image = image.scaled(_virtualPadRbBtnPixelSize, _virtualPadRbBtnPixelSize, Qt::KeepAspectRatio);
image = image.mirrored();
_virtualPadRbBtnTexture = gpu::Texture::createStrict(
gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA),
image.width(), image.height(),
gpu::Texture::MAX_NUM_MIPS,
gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR));
_virtualPadRbBtnTexture->setSource("virtualPad handshake");
auto usage = gpu::Texture::Usage::Builder().withColor().withAlpha();
_virtualPadRbBtnTexture->setUsage(usage.build());
_virtualPadRbBtnTexture->setStoredMipFormat(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA));
_virtualPadRbBtnTexture->assignStoredMip(0, image.byteCount(), image.constBits());
_virtualPadRbBtnTexture->setAutoGenerateMips(true);
}
}
#endif
Parent::customizeContext();
}
@ -135,6 +160,8 @@ void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
_virtualPadPixelSize, _virtualPadPixelSize);
auto jumpTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getJumpButtonPosition(),
_virtualPadJumpBtnPixelSize, _virtualPadJumpBtnPixelSize);
auto rbTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getRbButtonPosition(),
_virtualPadRbBtnPixelSize, _virtualPadRbBtnPixelSize);
render([&](gpu::Batch& batch) {
batch.enableStereo(false);
@ -154,6 +181,10 @@ void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
batch.setResourceTexture(0, _virtualPadJumpBtnTexture);
batch.setModelTransform(jumpTransform);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(0, _virtualPadRbBtnTexture);
batch.setModelTransform(rbTransform);
batch.draw(gpu::TRIANGLE_STRIP, 4);
});
}
#endif

View file

@ -49,5 +49,8 @@ private:
gpu::TexturePointer _virtualPadJumpBtnTexture;
qreal _virtualPadJumpBtnPixelSize;
gpu::TexturePointer _virtualPadRbBtnTexture;
qreal _virtualPadRbBtnPixelSize;
#endif
};

View file

@ -67,6 +67,7 @@ void TouchscreenVirtualPadDevice::resize() {
_fixedRadiusForCalc = _fixedRadius - _screenDPI * VirtualPad::Manager::STICK_RADIUS_PIXELS / VirtualPad::Manager::DPI;
_jumpButtonRadius = _screenDPI * VirtualPad::Manager::JUMP_BTN_TRIMMED_RADIUS_PIXELS / VirtualPad::Manager::DPI;
_rbButtonRadius = _jumpButtonRadius;
}
auto& virtualPadManager = VirtualPad::Manager::instance();
@ -91,6 +92,10 @@ void TouchscreenVirtualPadDevice::setupControlsPositions(VirtualPad::Manager& vi
float bottomMargin = _screenDPI * VirtualPad::Manager::JUMP_BTN_BOTTOM_MARGIN_PIXELS/ VirtualPad::Manager::DPI;
_jumpButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - bottomMargin - _jumpButtonRadius - _extraBottomMargin);
virtualPadManager.setJumpButtonPosition(_jumpButtonPosition);
// RB button (use same size as jump)
_rbButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - 2 * bottomMargin - 3 * _rbButtonRadius - _extraBottomMargin);
virtualPadManager.setRbButtonPosition(_rbButtonPosition);
}
float clip(float n, float lower, float upper) {
@ -236,6 +241,7 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
moveTouchEnd();
viewTouchEnd();
jumpTouchEnd();
rbTouchEnd();
return;
}
// touch end here is a big reset -> resets both pads
@ -245,6 +251,7 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
moveTouchEnd();
viewTouchEnd();
jumpTouchEnd();
rbTouchEnd();
_inputDevice->_axisStateMap.clear();
_inputDevice->_buttonPressedMap.clear();
}
@ -281,10 +288,12 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
bool moveTouchFound = false;
bool viewTouchFound = false;
bool jumpTouchFound = false;
bool rbTouchFound = false;
int idxMoveStartingPointCandidate = -1;
int idxViewStartingPointCandidate = -1;
int idxJumpStartingPointCandidate = -1;
int idxRbStartingPointCandidate = -1;
glm::vec2 thisPoint;
int thisPointId;
@ -316,6 +325,13 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
continue;
}
if (!rbTouchFound && _rbHasValidTouch && _rbCurrentTouchId == thisPointId) {
// valid if it's an ongoing touch
rbTouchFound = true;
rbTouchUpdate(thisPoint);
continue;
}
if (!moveTouchFound && idxMoveStartingPointCandidate == -1 && moveTouchBeginIsValid(thisPoint) &&
(!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == MOVE )) {
idxMoveStartingPointCandidate = i;
@ -334,12 +350,20 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
continue;
}
if (!rbTouchFound && idxRbStartingPointCandidate == -1 && rbTouchBeginIsValid(thisPoint) &&
(!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == RB_BUTTON )) {
idxRbStartingPointCandidate = i;
continue;
}
if (moveTouchBeginIsValid(thisPoint)) {
unusedTouchesInEvent[thisPointId] = MOVE;
} else if (jumpTouchBeginIsValid(thisPoint)) {
unusedTouchesInEvent[thisPointId] = JUMP;
} else if (viewTouchBeginIsValid(thisPoint)) {
unusedTouchesInEvent[thisPointId] = VIEW;
} else if (rbTouchBeginIsValid(thisPoint)) {
unusedTouchesInEvent[thisPointId] = RB_BUTTON;
}
}
@ -381,11 +405,24 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
}
}
}
if (!rbTouchFound) {
if (idxRbStartingPointCandidate != -1) {
_rbCurrentTouchId = tPoints[idxRbStartingPointCandidate].id();
_unusedTouches.erase(_rbCurrentTouchId);
thisPoint.x = tPoints[idxRbStartingPointCandidate].pos().x();
thisPoint.y = tPoints[idxRbStartingPointCandidate].pos().y();
rbTouchBegin(thisPoint);
} else {
if (_rbHasValidTouch) {
rbTouchEnd();
}
}
}
}
bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) {
return !moveTouchBeginIsValid(touchPoint) && !jumpTouchBeginIsValid(touchPoint);
return !moveTouchBeginIsValid(touchPoint) && !jumpTouchBeginIsValid(touchPoint) && !rbTouchBeginIsValid(touchPoint);
}
bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
@ -419,6 +456,29 @@ void TouchscreenVirtualPadDevice::jumpTouchEnd() {
_jumpHasValidTouch = false;
_inputDevice->_buttonPressedMap.erase(TouchButtonChannel::JUMP_BUTTON_PRESS);
}
}
bool TouchscreenVirtualPadDevice::rbTouchBeginIsValid(glm::vec2 touchPoint) {
return glm::distance2(touchPoint, _rbButtonPosition) < _rbButtonRadius * _rbButtonRadius;
}
void TouchscreenVirtualPadDevice::rbTouchBegin(glm::vec2 touchPoint) {
auto& virtualPadManager = VirtualPad::Manager::instance();
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
_rbHasValidTouch = true;
_inputDevice->_buttonPressedMap.insert(TouchButtonChannel::RB);
}
}
void TouchscreenVirtualPadDevice::rbTouchUpdate(glm::vec2 touchPoint) {}
void TouchscreenVirtualPadDevice::rbTouchEnd() {
if (_rbHasValidTouch) {
_rbHasValidTouch = false;
_inputDevice->_buttonPressedMap.erase(TouchButtonChannel::RB);
}
}
@ -496,7 +556,8 @@ controller::Input::NamedVector TouchscreenVirtualPadDevice::InputDevice::getAvai
Input::NamedPair(makeInput(TouchAxisChannel::LY), "LY"),
Input::NamedPair(makeInput(TouchAxisChannel::RX), "RX"),
Input::NamedPair(makeInput(TouchAxisChannel::RY), "RY"),
Input::NamedPair(makeInput(TouchButtonChannel::JUMP_BUTTON_PRESS), "JUMP_BUTTON_PRESS")
Input::NamedPair(makeInput(TouchButtonChannel::JUMP_BUTTON_PRESS), "JUMP_BUTTON_PRESS"),
Input::NamedPair(makeInput(TouchButtonChannel::RB), "RB")
};
return availableInputs;
}

View file

@ -51,7 +51,8 @@ public:
};
enum TouchButtonChannel {
JUMP_BUTTON_PRESS
JUMP_BUTTON_PRESS,
RB
};
protected:
@ -82,7 +83,8 @@ protected:
enum TouchType {
MOVE = 1,
VIEW,
JUMP
JUMP,
RB_BUTTON
};
float _lastPinchScale;
@ -104,6 +106,9 @@ protected:
bool _jumpHasValidTouch;
int _jumpCurrentTouchId;
bool _rbHasValidTouch;
int _rbCurrentTouchId;
std::map<int, TouchType> _unusedTouches;
int _touchPointCount;
@ -119,6 +124,9 @@ protected:
glm::vec2 _jumpButtonPosition;
float _jumpButtonRadius;
glm::vec2 _rbButtonPosition;
float _rbButtonRadius;
void moveTouchBegin(glm::vec2 touchPoint);
void moveTouchUpdate(glm::vec2 touchPoint);
void moveTouchEnd();
@ -134,6 +142,11 @@ protected:
void jumpTouchEnd();
bool jumpTouchBeginIsValid(glm::vec2 touchPoint);
void rbTouchBegin(glm::vec2 touchPoint);
void rbTouchUpdate(glm::vec2 touchPoint);
void rbTouchEnd();
bool rbTouchBeginIsValid(glm::vec2 touchPoint);
void setupControlsPositions(VirtualPad::Manager& virtualPadManager, bool force = false);
void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager);

View file

@ -84,6 +84,14 @@ namespace VirtualPad {
_jumpButtonPosition = point;
}
glm::vec2 Manager::getRbButtonPosition() {
return _rbButtonPosition;
}
void Manager::setRbButtonPosition(glm::vec2 point) {
_rbButtonPosition = point;
}
void Manager::requestHapticFeedback(int duration) {
emit hapticFeedbackRequested(duration);
}

View file

@ -46,6 +46,8 @@ namespace VirtualPad {
void setExtraBottomMargin(int margin);
glm::vec2 getJumpButtonPosition();
void setJumpButtonPosition(glm::vec2 point);
glm::vec2 getRbButtonPosition();
void setRbButtonPosition(glm::vec2 point);
void requestHapticFeedback(int duration);
static const float DPI;
@ -65,6 +67,7 @@ namespace VirtualPad {
bool _enabled {true};
bool _hidden;
glm::vec2 _jumpButtonPosition;
glm::vec2 _rbButtonPosition;
int _extraBottomMargin {0};
};
}

View file

@ -16,7 +16,8 @@ var DEFAULT_SCRIPTS_COMBINED = [
"system/+android/touchscreenvirtualpad.js",
"system/+android/actionbar.js",
"system/+android/audio.js" ,
"system/+android/modes.js"/*,
"system/+android/modes.js",
"system/makeUserConnection.js"/*,
"system/away.js",
"system/controllers/controllerDisplayManager.js",
"system/controllers/handControllerGrabAndroid.js",