void GetSwipe(SwipeInfo info) { pivotObj.transform.rotation = defaultRot; float length = Vector2.Distance(info.SwipeStartPos, info.SwipeEndPos); if (info.isEnd || length < lastLength || (lastLength != 0 && lastSwipeDir != info.SwipeDirection)) { defaultRot = pivotObj.transform.rotation; lastLength = 0; } else { lastLength = length; } lastSwipeDir = info.SwipeDirection; float multiplier = 1f; if (Vector2.SignedAngle(info.SwipeStartPos - centre, info.SwipeEndPos - centre) < 0) { multiplier *= -1; } pivotObj.transform.Rotate(Vector3.forward, length * rotationSpeed * multiplier); }
public Input_WI_OnSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float velocity) { FingerIndex = fingerIndex; FingerPos = fingerPos; SwipeDirection = swipeDirection; Velocity = velocity; }
private bool DetectDotDirectionSingleAxis(Vector2 normalizedDirection, Vector2 test, ESwipeDirection testEnum, ESwipeDirection oppositeEnum) { float dot = Vector2.Dot(test, normalizedDirection); // if 0, then it's either left or right. The normalized direction // will exactly equal the Vector2.right or Vector2.left ( in the right left case) if (dot == 0) { if (normalizedDirection == test) { _currentDetectedDirection = testEnum; } else { _currentDetectedDirection = oppositeEnum; } return(true); } // if it isn't 0, then work out which direction it is using the const dot if (dot <= 1 && dot >= cNormalizedDot45Degress) { _currentDetectedDirection = testEnum; return(true); } else if (dot >= -1 && dot <= -cNormalizedDot45Degress) { _currentDetectedDirection = oppositeEnum; return(true); } return(false); }
protected void FireOnRightSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float swipeDelta) { if (OnRightSwipe != null) { OnRightSwipe(new Input_WI_OnRightSwipe(fingerIndex, fingerPos, swipeDirection, swipeDelta)); } }
private void OnEventSwipe(ESwipeDirection aDirection) { EventHandler <EventArgsSwipe> del = EventSwipe; if (del != null) { del(this, new EventArgsSwipe(aDirection)); } }
// Once the swipe has been detected and it's ready, send the data. // The data sent is retrieved by the registered delegates. private void SendSwipeData(ESwipeDirection dir, bool hasEnded) { SwipeInfo swipeInfo = new SwipeInfo() { SwipeDirection = dir, SwipeStartPos = m_touchDownPos, SwipeEndPos = m_touchUpPos, isEnd = hasEnded }; OnSwipe(swipeInfo); }
/// <summary> /// Updates the current swipe gesture for the frame. Must stop touching the trackpad to complete the gesture. /// </summary> private void UpdateSwipeState() { if (_trackedDevice.GetButtonUp(StylusButton.TouchstripTouch)) { if ((Time.time - _touchStartTime) <= _timeToSwipeGesture) { _swipeState = GetSwipeDirection(_initialTouchMoveDistance); return; } } _swipeState = ESwipeDirection.None; }
/* * Set swipe direction based on y and x values of end - start. */ private void DetectSwipe(bool isEnd = false) { if (VertDist() > m_minSwipeThreshold || HorDist() > m_minSwipeThreshold) { if (IsVertSwipe()) { ESwipeDirection dir = m_touchDownPos.y - m_touchUpPos.y > 0 ? ESwipeDirection.Swipe_Down : ESwipeDirection.Swipe_UP; SendSwipeData(dir, isEnd); } else { ESwipeDirection dir = m_touchDownPos.x - m_touchUpPos.x > 0 ? ESwipeDirection.Swipe_Left : ESwipeDirection.Swipe_Right; SendSwipeData(dir, isEnd); } m_touchUpPos = m_touchDownPos; } }
void TryRecognize() { List <ESwipeDirection> detectedSwipes = new List <ESwipeDirection>(); // For now, super basic! for (int i = 0; i < 2; i++) { LinkedList <Vector3> listOfInterest = i == 0 ? PrevLeftHandPositions : PrevRightHandPositions; if (listOfInterest.Count >= 3) { // Need AT LEAST 3 positions Vector2 start = listOfInterest.First.Value; Vector2 end = listOfInterest.Last.Value; Vector2 diff = end - start; if (diff.x > WorldUnitsForHorizontalSwipe) { // Swipe right! detectedSwipes.Add(ESwipeDirection.RIGHT); } else if (diff.x < -WorldUnitsForHorizontalSwipe) { detectedSwipes.Add(ESwipeDirection.LEFT); } } } // If multiple swipes detected, only send one of them, for now if (detectedSwipes.Count > 0) { ESwipeDirection selected = (ESwipeDirection)detectedSwipes.Select((esw) => (int)esw).Min(); SendSwipeEvent(selected); // Clear out the current lists so we don't get confused PrevLeftHandPositions.Clear(); PrevRightHandPositions.Clear(); CurrentSwipeCooldown = 0.0f; } }
/// <summary> /// Checks if the trackpad has been swiped in a direction. /// </summary> /// <param name="swipeDirection">The swipe direction to check against.</param> /// <returns> /// If the tracked has been swiped in the specified direction. /// </returns> public bool OnSwipe(ESwipeDirection swipeDirection) { Update(); return(_swipeState == swipeDirection); }
public Input_WI_OnRightSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float swipeDelta) : base(fingerIndex, fingerPos, swipeDirection, swipeDelta) { }
private void OnSwipeBegin(ESwipeDirection pDirection) { if (mTouchedBalloonObject != null && pDirection == ESwipeDirection.UP/* && mTouchedBalloon.Type == EBalloonType.LIFE*/ && TouchService.CurrentTouchPosition.y > mTouchedBalloonObject.transform.position.y) { mIsJumpCommand = true; } }
public EventArgsSwipe(ESwipeDirection aDirection) { Direction = aDirection; }
public bool OnSwipe(ESwipeDirection swipeDirection) { return(_trackpad.OnSwipe(swipeDirection)); }
public OnSwipeEventArgs(ESwipeDirection direction) { this.Direction = direction; }
void SendSwipeEvent(ESwipeDirection dir) { OnSwipe?.Invoke(this, new OnSwipeEventArgs(dir)); }