public override void Unsubscribe(PinchState state, Action <PinchInputEventArgs> listener)
        {
            if (_detector == null)
            {
                return;
            }

            switch (state)
            {
            case PinchState.Start:
                getDetector().OnPinchStart -= listener;
                break;

            case PinchState.Ongoing:
                getDetector().OnPinch -= listener;
                break;

            case PinchState.Ended:
                getDetector().OnPinchEnd -= listener;
                break;

            case PinchState.None:
                throw new ArgumentException();

            default:
                throw new NotImplementedException();
            }
        }
				// Update is called once per frame
				void Update ()
				{
						FingerModel index = GetIndex ();
						FingerModel thumb = GetThumb ();
			
						if (index != null && thumb != null) {
								AnimateCursor (index, thumb);
								SetPinchAnimation ();
								switch (GetPinch ()) {
								case 1:
										state = PinchState.Full;
										break;

								case 2: 
										state = PinchState.Part;
										break;

								case 3:
										state = PinchState.Open;
										break;
								}
						} else {
								state = PinchState.NoHands;
						}

						SetFingerSpritePosition (index, thumb);
				}
Example #3
0
    void Start()
    {
        StreamReader streamReader = new StreamReader("settings.txt");

        //scorro le prime linee che non mi servono
        for (int i = 0; i < 2; i++)
        {
            streamReader.ReadLine();
        }
        //converto da string a float

        grabObjectDistanceStr = streamReader.ReadLine();
        grabObjectDistance    = float.Parse(grabObjectDistanceStr);
        //chiudo il read
        streamReader.Close();


        pinch_state_               = PinchState.kReleased;
        active_object_             = null;
        last_max_angular_velocity_ = 0.0f;
        rotation_from_palm_        = Quaternion.identity;
        current_pinch_position_    = Vector3.zero;
        filtered_pinch_position_   = Vector3.zero;
        object_pinch_offset_       = Vector3.zero;
        palm_rotation_             = Quaternion.identity;
    }
Example #4
0
        // Update is called once per frame
        void Update()
        {
            FingerModel index = GetIndex();
            FingerModel thumb = GetThumb();

            if (index != null && thumb != null)
            {
                AnimateCursor(index, thumb);
                SetPinchAnimation();
                switch (GetPinch())
                {
                case 1:
                    state = PinchState.Full;
                    break;

                case 2:
                    state = PinchState.Part;
                    break;

                case 3:
                    state = PinchState.Open;
                    break;
                }
            }
            else
            {
                state = PinchState.NoHands;
            }

            SetFingerSpritePosition(index, thumb);
        }
        public void UpdateState(Hand hand, Interactable currFocusedInteractable)
        {
            float pinchStrength = hand.PinchStrength(OVRPlugin.HandFinger.Index);
            bool  isPinching    = Mathf.Abs(PINCH_STRENGTH_THRESHOLD - pinchStrength) < Mathf.Epsilon;
            var   oldPinchState = _currPinchState;

            switch (oldPinchState)
            {
            case PinchState.PinchUp:
                // can only be in pinch up for a single frame, so consider
                // next frame carefully
                if (isPinching)
                {
                    _currPinchState = PinchState.PinchDown;
                    if (currFocusedInteractable != _firstFocusedInteractable)
                    {
                        _firstFocusedInteractable = null;
                    }
                }
                else
                {
                    _currPinchState           = PinchState.None;
                    _firstFocusedInteractable = null;
                }
                break;

            case PinchState.PinchStay:
                if (!isPinching)
                {
                    _currPinchState = PinchState.PinchUp;
                }
                // if object is not focused anymore, then forget it
                if (currFocusedInteractable != _firstFocusedInteractable)
                {
                    _firstFocusedInteractable = null;
                }
                break;

            // pinch down lasts for a max of 1 frame. either go to pinch stay or up
            case PinchState.PinchDown:
                _currPinchState = isPinching ? PinchState.PinchStay : PinchState.PinchUp;
                // if the focused interactable changes, then the original one is now invalid
                if (_firstFocusedInteractable != currFocusedInteractable)
                {
                    _firstFocusedInteractable = null;
                }
                break;

            default:
                if (isPinching)
                {
                    _currPinchState = PinchState.PinchDown;
                    // this is the interactable that must be focused through out the pinch up and down
                    // gesture.
                    _firstFocusedInteractable = currFocusedInteractable;
                }
                break;
            }
        }
 void Start() {
   pinch_state_ = PinchState.kReleased;
   active_object_ = null;
   last_max_angular_velocity_ = 0.0f;
   rotation_from_palm_ = Quaternion.identity;
   current_pinch_position_ = Vector3.zero;
   filtered_pinch_position_ = Vector3.zero;
   object_pinch_offset_ = Vector3.zero;
   palm_rotation_ = Quaternion.identity;
 }
    void FixedUpdate()
    {
        muslukbas.rigidbody.angularVelocity = new Vector3(0, 0, 0);

        UpdatePalmRotation();
        UpdatePinchPosition();
        HandModel hand_model = GetComponent <HandModel>();
        Hand      leap_hand  = hand_model.GetLeapHand();

        if (leap_hand == null)
        {
            return;
        }

        PinchState new_pinch_state = GetNewPinchState();

        if (pinch_state_ == PinchState.kPinched)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (active_object_ != null)
            {
                ContinueHardPinch();
            }
        }
        else if (pinch_state_ == PinchState.kReleasing)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else if (active_object_ != null)
            {
                ContinueSoftPinch();
            }
        }
        else
        {
            if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else
            {
                Hover();
            }
        }
        pinch_state_ = new_pinch_state;
    }
 void Start()
 {
     pinch_state_               = PinchState.kReleased;
     active_object_             = null;
     last_max_angular_velocity_ = 0.0f;
     rotation_from_palm_        = Quaternion.identity;
     current_pinch_position_    = Vector3.zero;
     filtered_pinch_position_   = Vector3.zero;
     object_pinch_offset_       = Vector3.zero;
     palm_rotation_             = Quaternion.identity;
 }
    void FixedUpdate()
    {
        UpdatePalmRotation();
        UpdatePinchPosition();
        Leap.Unity.HandModel hand_model = GetComponent <Leap.Unity.HandModel>();
        Hand leap_hand = hand_model.GetLeapHand();

        if (leap_hand == null)
        {
            return;
        }

        PinchState new_pinch_state = GetNewPinchState();

        if (pinch_state_ == PinchState.kPinched)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (active_object_ != null)
            {
                ContinueHardPinch();
            }
        }
        else if (pinch_state_ == PinchState.kReleasing)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else if (active_object_ != null)
            {
                ContinueSoftPinch();
            }
        }
        else
        {
            if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else
            {
                Hover();
            }
        }
        pinch_state_ = new_pinch_state;
    }
 public PinchInputEventArgs(
     PinchState state,
     Vector2 axis,
     float delta,
     PointerInputEventArgs[] pointerInput,
     float duration)
 {
     State        = state;
     Axis         = axis;
     Delta        = delta;
     PointerInput = pointerInput;
     Duration     = duration;
 }
Example #11
0
    void FixedUpdate()
    {
        //assign to sculptVerts if it doesn't have a hand this is pretty much a failsafe thing
        if (SculptVerts.instance.hand == null)
        {
            SculptVerts.instance.hand = this;
        }

        UpdatePalmRotation();
        UpdatePinchPosition();

        HandModel hand_model = GetComponent <HandModel>();
        Hand      leap_hand  = hand_model.GetLeapHand();



        if (leap_hand == null)
        {
            return;
        }

        PinchState new_pinch_state = GetNewPinchState();

        if (pinch_state_ == PinchState.kPinched)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
        }
        else if (pinch_state_ == PinchState.kReleasing)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
        }
        else
        {
            if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
        }
        pinch_state_ = new_pinch_state;
    }
Example #12
0
        protected override void OnReset()
        {
            for (int i = 0; i < kNumTouchesRequired; ++i)
            {
                m_FingerIdx[i]        = -1;
                m_AccumulatedDelta[i] = Vector2.Zero;
                m_PreviousPosition[i] = Vector2.Zero;
            }

            if (!m_bPinching)
            {
                m_DeltaScale = 0.0f;
                m_pinchState = PinchState.Invalid;
            }

            m_bPinching = false;
        }
        public override void Subscribe(PinchState state, Action <PinchInputEventArgs> listener)
        {
            switch (state)
            {
            case PinchState.Start:
                getDetector().OnPinchStart += listener;
                break;

            case PinchState.Ongoing:
                getDetector().OnPinch += listener;
                break;

            case PinchState.Ended:
                getDetector().OnPinchEnd += listener;
                break;

            case PinchState.None:
                throw new ArgumentException();

            default:
                throw new NotImplementedException();
            }
        }
Example #14
0
    void UpdatePinchState()
    {
        GestureName currentGesture = hand.GetGestureName();

        bool isClosingFingers = (pinchSpeed < -closingSpeedThresh);
        bool isOpeningFingers = (pinchSpeed > openingSpeedThresh);


        if (activeObject != null && activeObject.IsAvailableForPinch() == false &&
            pinchState != PinchState.ObjectInHold) // pinched by the other hand
        {
            activeObject = null;
            pinchState   = PinchState.ObjectOutOfReach;
        }

        if ((pinchState == PinchState.ObjectOutOfReach) ||
            (pinchState == PinchState.ObjectInReach && !isClosingFingers) ||
            (pinchState == PinchState.ObjectReleased))
        {
            // Iterate all pinchable objects, find the closest available one.
            PinchableObject closestAvailableObj = null;
            float           minDistance         = 1000f;
            foreach (PinchableObject obj in PinchableObject.instances)
            {
                if (obj.IsAvailableForPinch())
                {
                    float distance = Vector3.Distance(this.transform.position, obj.transform.position);
                    if (distance < minDistance)
                    {
                        minDistance         = distance;
                        closestAvailableObj = obj;
                    }
                }
            }

            // Mark the closest available object as active
            activeObject = closestAvailableObj;

            // Check if it is range.
            bool inReach = (minDistance < pinchEnableDistance);

            if (activeObject != null)
            {
                // To give user visual feedbacks, update the outline color on the active object
                // based on its current distance to the hand.
                activeObject.UpdateOutlineColorBasedOnDistance(minDistance);

                // Reset the outline color (fully transparent) on the last active object if it was different
                if (prevActiveObject != null && prevActiveObject != activeObject)
                {
                    prevActiveObject.SetOutlineColorTransparency(0);
                }

                // If we are able to pinch the currently active object
                if (inReach && currentTipDist > pinchEnableTipDistance)
                {
                    if (pinchState != PinchState.ObjectInReach || activeObject != prevActiveObject)
                    {
                        activeObject.OnGetInReach.Invoke();
                        pinchState = PinchState.ObjectInReach;
                    }
                }
            }

            // Note, we want to ignore movement (which can cause ObjectInReach state to change to ObjectOutOfReach)
            // if user is already in the middle of pinching the object
            if (!inReach && !(pinchState == PinchState.ObjectInReach && isClosingFingers))
            {
                if (pinchState != PinchState.ObjectOutOfReach || activeObject != prevActiveObject)
                {
                    if (activeObject != null)
                    {
                        activeObject.OnOutOfReach.Invoke();
                    }

                    pinchState = PinchState.ObjectOutOfReach;
                }
            }
        }

        if (pinchState == PinchState.ObjectInReach)
        {
            if ((currentTipDist < pinchStartTipDistance || currentGesture == GestureName.PinchCloseMRP ||
                 currentGesture == GestureName.PinchOpenMRP) && isClosingFingers)
            {
                // To give user visual feedbacks, make the hand transparent.
                if (meshHandRenderMgr != null)
                {
                    meshHandRenderMgr.DisableHandOutline();
                    meshHandRenderMgr.FadeOut();
                }

                if (activeObject != null)
                {
                    activeObject.OnPickUp.Invoke();
                    // Save the parent transform
                    pinchedObjectParent                  = activeObject.transform.parent;
                    activeObject.transform.parent        = this.transform;
                    activeObject.transform.localPosition = Vector3.zero;
                    // Disable the object for pinch
                    activeObject.SetAvailableForPinch(false);
                }
                pinchState = PinchState.ObjectInHold;
            }
        }

        if (pinchState == PinchState.ObjectInHold)
        {
            if (currentTipDist > pinchEndTipDistance && isOpeningFingers)
            {
                // To give user visual feedbacks, make the hand opaque (default).
                if (meshHandRenderMgr != null)
                {
                    meshHandRenderMgr.FadeIn();
                }

                if (activeObject != null)
                {
                    activeObject.OnRelease.Invoke();

                    Vector3 velocity = (velocityCalculator != null) ? velocityCalculator.CalculateVelocity() : Vector3.zero;
                    if (Vector3.Magnitude(velocity) > 0)
                    {
                        activeObject.OnThrow.Invoke(velocity);
                        // Enable the object for pinch later
                        activeObject.SetAvailableForPinch(true, activeObject.FlyBackTime());
                    }
                    else
                    {
                        // Enable the object for pinch right away
                        activeObject.SetAvailableForPinch(true, 0);
                    }
                    // Restore the parent transform
                    activeObject.transform.parent = pinchedObjectParent;
                }

                pinchState = PinchState.ObjectReleased;
            }
        }

        //Debug.Log("Pinch state = " + pinchState);


        // To give user visual feedbacks, highlight hand outline if it is hovering an object, otherwise disable outline.
        bool isHovering = (pinchState == PinchState.ObjectInReach);

        if (meshHandRenderMgr != null)
        {
            if (isHovering && !isHoveringLastFrame)
            {
                meshHandRenderMgr.EnableHandOutline();
            }
            else if (!isHovering && isHoveringLastFrame)
            {
                meshHandRenderMgr.DisableHandOutline();
            }
        }
        isHoveringLastFrame = isHovering;

        prevActiveObject = activeObject;
    }
Example #15
0
 void OnEnable()
 {
     pinchState = PinchState.ObjectOutOfReach;
 }
Example #16
0
 public void leftHandNotPinching()
 {
     leftPinchState = PinchState.notPinching;
 }
 public PinchStateModule()
 {
     _currPinchState           = PinchState.None;
     _firstFocusedInteractable = null;
 }
Example #18
0
    void Start()
    {
        StreamReader streamReader = new StreamReader("settings.txt");
        //scorro le prime linee che non mi servono
        for (int i = 0; i<2; i++) {
            streamReader.ReadLine();
        }
        //converto da string a float

        grabObjectDistanceStr = streamReader.ReadLine();
        grabObjectDistance = float.Parse(grabObjectDistanceStr);
        //chiudo il read
        streamReader.Close();

        pinch_state_ = PinchState.kReleased;
        active_object_ = null;
        last_max_angular_velocity_ = 0.0f;
        rotation_from_palm_ = Quaternion.identity;
        current_pinch_position_ = Vector3.zero;
        filtered_pinch_position_ = Vector3.zero;
        object_pinch_offset_ = Vector3.zero;
        palm_rotation_ = Quaternion.identity;
    }
Example #19
0
 void Start()
 {
     pinch_state_   = PinchState.kReleased;
     active_object_ = null;
 }
Example #20
0
 public void leftHandPinch()
 {
     leftPinchState = PinchState.pinching;
 }
Example #21
0
    // Update is called once per framesdf
    void Update()
    {
        if (adjustHeightFromHeightMap)
        {
            ApplyHeightAdjustment();
        }

        if (deltaPos.sqrMagnitude > 0 && pinchState == PinchState.None)
        {
            deltaPos = Vector3.Lerp(deltaPos * 0.93f, Vector3.zero, Time.deltaTime);

            // deltaPos *= 0.99f;
            transform.position += deltaPos;
            ApplyLimits();
        }

        if (Mathf.Abs(deltaAngle) > 0 && pinchState == PinchState.None)
        {
            deltaAngle = Mathf.Lerp(deltaAngle * 0.97f, 0, Time.deltaTime);
            transform.parent.Rotate(deltaAngle * Vector3.up);
        }

        if (rightControlPoint.handLocation != MapControlPoint.HandLocation.Far &&
            leftControlPoint.handLocation != MapControlPoint.HandLocation.Far &&
            HandUIManager.pinchLeft.isActive && HandUIManager.pinchRight.isActive)
        {
            // two handed control
            Vector3 midpoint = (lPoint.position + lPoint.position) / 2;

            if (pinchState != PinchState.Both)
            {
                pinchState = PinchState.Both;

                deltaPos = Vector3.zero;

                onGrabDistanceBetweenHands = Vector3.Distance(lPoint.position, rPoint.position);
                onGrabScale       = transform.localScale;
                onGrabEulerAngles = transform.eulerAngles;

                prevMidpointPos = midpoint;
                deltaAngle      = 0;
                reset           = true;

                onGrabMidpointOffset = midpoint - transform.position;
                onGrabRightToLeft    = lPoint.position - rPoint.position;
                // onGrabRightToLeft.y = 0;
            }


            float   currentDistance    = Vector3.Distance(lPoint.position, rPoint.position);
            Vector3 currentRightToLeft = lPoint.position - rPoint.position;
            currentRightToLeft.y = 0;

            float angle = Vector3.SignedAngle(currentRightToLeft, onGrabRightToLeft, Vector3.up);
            if (!reset)
            {
                deltaAngle = prevAngle - angle;
            }
            else
            {
                reset = false;
            }

            prevAngle            = angle;
            onGrabMidpointOffset = Quaternion.Euler(0, deltaAngle, 0) * onGrabMidpointOffset;
            transform.parent.Rotate(deltaAngle * Vector3.up);

            Vector3 pos    = transform.position;
            Vector3 target = midpoint - onGrabMidpointOffset * currentDistance / onGrabDistanceBetweenHands;

            target.y = pos.y;

            transform.position   = target;
            transform.localScale = Vector3.one * Mathf.Clamp(onGrabScale.x * currentDistance / onGrabDistanceBetweenHands, scaleRange.x, scaleRange.y);

            prevMidpointPos = midpoint;
        }
        else if (rightControlPoint.handLocation != MapControlPoint.HandLocation.Far &&
                 HandUIManager.pinchRight.isActive)
        {
            //right point only
            if (pinchState != PinchState.Right)
            {
                pinchState = PinchState.Right;
                ResetLinearMotion(rPoint);
            }

            MoveAlongWith(rPoint);
        }
        else if (leftControlPoint.handLocation != MapControlPoint.HandLocation.Far &&
                 HandUIManager.pinchLeft.isActive)
        {
            //left point only
            if (pinchState != PinchState.Left)
            {
                pinchState = PinchState.Left;
                ResetLinearMotion(lPoint);
            }

            MoveAlongWith(lPoint);

            // prevPointPos = lep
        }
        else
        {
            if (pinchState != PinchState.None)
            {
                pinchState = PinchState.None;
            }
        }
    }
Example #22
0
 public void rightHandPinch()
 {
     rightPinchState = PinchState.pinching;
 }
Example #23
0
 public void rightHandNotPinching()
 {
     rightPinchState = PinchState.notPinching;
 }
Example #24
0
 // Use this for initialization
 void Start()
 {
     leftPinchState  = PinchState.notPinching;
     rightPinchState = PinchState.notPinching;
 }
Example #25
0
    void FixedUpdate()
    {
        UpdatePalmRotation();
        UpdatePinchPosition();
        HandModel hand_model = GetComponent <HandModel>();
        Hand      leap_hand  = hand_model.GetLeapHand();

        //-------------------------------------------------------------------------------

//		Debug.Log (pinch_state_.ToString()+" : "+hand_model.GetLeapHand().IsLeft);


        if (pinch_state_ == PinchState.kPinched && hand_model.GetLeapHand().IsLeft)
        {
            closedLeft = true;
        }
        else
        {
            closedLeft = false;
        }

        if (pinch_state_ == PinchState.kPinched && hand_model.GetLeapHand().IsRight)
        {
            closedRight = true;
        }
        else
        {
            closedRight = false;
        }

//		Debug.Log("closedLeft: " + closedLeft + " - closedRight: " + closedRight);

        //-------------------------------------------------------------------------------


        if (leap_hand == null)
        {
            return;
        }

        PinchState new_pinch_state = GetNewPinchState();

        if (pinch_state_ == PinchState.kPinched)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (active_object_ != null)
            {
                ContinueHardPinch();
            }
        }
        else if (pinch_state_ == PinchState.kReleasing)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else if (active_object_ != null)
            {
                ContinueSoftPinch();
            }
        }
        else
        {
            if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else
            {
                Hover();
            }
        }
        pinch_state_ = new_pinch_state;
    }
Example #26
0
        protected override void OnTouchMoved(TouchContact[] touches)
        {
            int numTouch = GetRequiredTouchCount();

            bool bFailed = touches.Length != numTouch;

            TouchContact[] tc = new TouchContact[numTouch];
            if (!bFailed)
            {
                if (AreFingerIDValid())
                {
                    for (int i = 0; !bFailed && i < numTouch; ++i)
                    {
                        tc[i]    = TouchInput.GetTouchContactByFingerId(m_FingerIdx[i], touches);
                        bFailed |= (null == tc[i]); //Fail if we didn't find the touch.
                    }
                }
                else
                {
                    for (int i = 0; i < numTouch; ++i)
                    {
                        tc[i]                 = touches[i];
                        m_FingerIdx[i]        = touches[i].fingerId;
                        m_AccumulatedDelta[i] = Vector2.Zero;
                        m_PreviousPosition[i] = touches[i].position;
                    }

                    m_IdleTime = Time.WallClockTotalSeconds;
                    m_AccumulatedDeltaLength = 0.0f;
                }
            }

            if (!bFailed)
            {
                Debug.Assert(tc.Length >= 2);
                Vector2 currentDir = tc[1].position - tc[0].position;
                Vector2 prevDir    = m_PreviousPosition[1] - m_PreviousPosition[0];

                m_AccumulatedDelta[0] += tc[0].position - m_PreviousPosition[0];
                m_AccumulatedDelta[1] += tc[1].position - m_PreviousPosition[1];

                //update previous positions
                m_PreviousPosition[0] = tc[0].position;
                m_PreviousPosition[1] = tc[1].position;

                float currentLength  = currentDir.Length();
                float previousLength = prevDir.Length();
                float deltaLength    = currentLength - previousLength;

                //determine pinch direction based on one frame change, but only if the change is big enough
                //and only switch to static after a time out period
                if (Math.Abs(deltaLength) > k_MinStateChangeDistance && currentLength > previousLength)
                {
                    //big change apart, pinch is growing
                    m_StaticTime = 0.0f;
                    m_pinchState = PinchState.Growing;
                }
                else if (Math.Abs(deltaLength) > k_MinStateChangeDistance && previousLength > currentLength)
                {
                    //big change together, pinch is shrinking
                    m_StaticTime = 0.0f;
                    m_pinchState = PinchState.Shrinking;
                }
                else if (m_pinchState != PinchState.Static)
                {
                    //not enough change, count up the static timer
                    m_StaticTime += Time.WallClockFrameSeconds;
                    if (m_StaticTime > k_PinchStaticTimeout)
                    {
                        m_pinchState = PinchState.Static;
                    }
                }

                //accumulate changes until we reach a threshold, at that point, check to make sure direction conditions still apply
                m_AccumulatedDeltaLength += deltaLength;

                bool Finger1LengthOk = (m_AccumulatedDelta[0].LengthSquared() > (k_PinchStaticDeadZone * k_PinchStaticDeadZone));
                bool Finger2LengthOk = (m_AccumulatedDelta[1].LengthSquared() > (k_PinchStaticDeadZone * k_PinchStaticDeadZone));

                if (Math.Abs(m_AccumulatedDeltaLength) > k_MinDeltaDistance && (Finger1LengthOk || Finger2LengthOk))
                {
                    if (GestureState.Possible == GetState())
                    {
                        //Fix the original distance and scale. Since we started pinching here but we've moved the fingers some amount to actual
                        if (!m_bPinching)
                        {
                            m_StaticTime   = 0.0f;
                            m_Scale        = 1.0f;
                            m_originalDist = currentLength;
                            m_bPinching    = true;
                        }

                        bFailed |= Finger1LengthOk && !AreVectorsParallel(prevDir, m_AccumulatedDelta[0], k_MovementAlongLineDot);
                        bFailed |= Finger2LengthOk && !AreVectorsParallel(prevDir, m_AccumulatedDelta[1], k_MovementAlongLineDot);
                    }
                    else
                    {
                        bFailed |= Finger1LengthOk && !AreVectorsParallel(prevDir, m_AccumulatedDelta[0], k_MovementAlongLineDot_PostBegin);
                        bFailed |= Finger2LengthOk && !AreVectorsParallel(prevDir, m_AccumulatedDelta[1], k_MovementAlongLineDot_PostBegin);
                    }

                    m_AccumulatedDelta[0] = Vector2.Zero;
                    m_AccumulatedDelta[1] = Vector2.Zero;

                    m_AccumulatedDeltaLength = 0.0f;

                    m_IdleTime = Time.WallClockTotalSeconds;
                }
                else
                {
                    bFailed |= (Time.WallClockTotalSeconds - m_IdleTime) > k_PinchIdleTimeout;
                }

                m_DeltaScale = m_Scale;
                m_Scale      = (m_originalDist > 0) ? currentLength / m_originalDist : 1.0f;
                m_DeltaScale = (m_Scale - m_DeltaScale);

                m_averagePosition = (tc[0].position + tc[1].position) * 0.5f;

                if (!m_bPinching)
                {
                    m_pinchState = PinchState.Invalid;
                }
            }

            if (bFailed)
            {
                SetState(GestureState.Failed);
            }
            else
            {
                if (GestureState.Possible == GetState())
                {
                    if (m_bPinching)
                    {
                        SetState(GestureState.Began);
                    }
                }
                else
                {
                    SetState(GestureState.Changed);
                }
            }
        }
Example #27
0
    // If we are releasing the object only apply a weaker force to the object
    // like it's sliding through your fingers.
    void FixedUpdate()
    {
        UpdatePalmRotation();
        UpdatePinchPosition();
        HandModel hand_model = GetComponent<HandModel>();
        Hand leap_hand = hand_model.GetLeapHand();

        if (leap_hand == null)
          return;

        PinchState new_pinch_state = GetNewPinchState();
        if (pinch_state_ == PinchState.kPinched) {
          if (new_pinch_state == PinchState.kReleased)
        OnRelease();
          else if (active_object_ != null)
        ContinueHardPinch();
        }
        else if (pinch_state_ == PinchState.kReleasing) {
          if (new_pinch_state == PinchState.kReleased)
        OnRelease();
          else if (new_pinch_state == PinchState.kPinched)
        StartPinch();

        }
        else {
          if (new_pinch_state == PinchState.kPinched)
        StartPinch();
          else
        Hover();
        }
        pinch_state_ = new_pinch_state;
    }
Example #28
0
 public abstract void Unsubscribe(PinchState state, Action <PinchInputEventArgs> listener);
Example #29
0
 void Start()
 {
     pinch_state_ = PinchState.kReleased;
     active_object_ = null;
 }