Exemplo n.º 1
0
        //fight method determines the winner and returns the winners text
        public string Fight()
        {
            //get the gestures winTables
            GestureName[] combat1WinTab = combatant1.GeteWinTable();
            GestureName[] combat2WinTab = combatant2.GeteWinTable();

            //get the gesture choice for each combatant
            GestureName combatant1Choice = combatant1.GetChoice();
            GestureName combatant2Choice = combatant2.GetChoice();

            //win lose draw strings
            string userWin  = "You Win!";
            string userLose = "You Lost!";
            string userDraw = "You Drew... ";

            //combatant1 win condition check loop this is the User
            for (int i = 0; i < combat1WinTab.Length; i++)
            {
                //if the
                if (combatant2Choice == combat1WinTab[i])
                {
                    return(string.Concat(userWin, winTextGenerator(i, combatant1, combatant2)));
                }
            }
            //combatant2 win condition check loop this is the random selection
            for (int i = 0; i < combat2WinTab.Length; i++)
            {
                if (combatant1Choice == combat2WinTab[i])
                {
                    return(string.Concat(userLose, winTextGenerator(i, combatant2, combatant1)));
                }
            }

            return(string.Concat(userDraw, combatant1, " VS ", combatant2));
        }
Exemplo n.º 2
0
    bool IsClickingGesture()
    {
        GestureName currentGesture = hand.IsDetected() ? hand.GetGestureName() : GestureName.None;

        return(currentGesture == GestureName.Point || currentGesture == GestureName.ShootEm ||
               currentGesture == GestureName.Peace || currentGesture == GestureName.MiddleFinger);
    }
Exemplo n.º 3
0
    void TrackGesture()
    {
        Vector3 thumbTipPos           = hand.GetTipPosition(TipIndex.ThumbTip);
        Vector3 indexTipPos           = hand.GetTipPosition(TipIndex.IndexTip);
        float   thumbIndexTipDistance = Vector3.Distance(thumbTipPos, indexTipPos);

        GestureName currentGesture = hand.GetGestureName();

        inZoomGesture = (thumbIndexTipDistance < zoomGestureThreshold ||
                         currentGesture == GestureName.PinchCloseMRP ||
                         currentGesture == GestureName.PinchCloseMRP);
    }
Exemplo n.º 4
0
    void UpdateGestureCondition()
    {
        currentFrameGestureName = hand.GetGestureName();

        if (currentFrameGestureName != GestureName.None && currentFrameGestureName == lastFrameGestureName)
        {
            gestureMaintainingCounter += Time.deltaTime;
        }
        else if (currentFrameGestureName != lastFrameGestureName)
        {
            gestureMaintainingCounter = 0f;
            isGestureMaintaining      = false;
        }
    }
Exemplo n.º 5
0
    void UpdateGesture()
    {
        currentFrameGestureName = hand.IsDetected() ? hand.GetGestureName() : GestureName.None;

        if (currentFrameGestureName == lastFrameGestureName)
        {
            gestureMaintainingCounter += Time.deltaTime;
        }
        else if (currentFrameGestureName != lastFrameGestureName)
        {
            gestureMaintainingCounter = 0f;
            isGestureMaintaining      = false;
        }
        lastFrameGestureName = currentFrameGestureName;
    }
Exemplo n.º 6
0
    void Update()
    {
        hand = FingoMain.Instance.GetHand(handType);

        if (hand.IsDetected())
        {
            UpdateGestureCondition();

            BroadcastIfGestureMaintains();
        }
        else
        {
            ClearGesture();
        }

        lastFrameGestureName = currentFrameGestureName;
    }
Exemplo n.º 7
0
    public void ColorChange(HandType handType, GestureName gestureType)
    {
        if (handType == HandType.Right)
        {
            switch (gestureType)
            {
            case GestureName.Okay:
                OnRightHandOkayGesture.Invoke();
                break;

            case GestureName.Peace:
                OnRightHandPeaceGesture.Invoke();
                break;

            case GestureName.Fist:
                OnRightHandFistGesture.Invoke();
                break;

            default:     // Gesture.None or any other gesture
                OnClearRight.Invoke();
                break;
            }
        }
        else if (handType == HandType.Left)
        {
            switch (gestureType)
            {
            case GestureName.Okay:
                OnLeftHandOkayGesture.Invoke();
                break;

            case GestureName.Peace:
                OnLeftHandPeaceGesture.Invoke();
                break;

            case GestureName.Fist:
                OnLeftHandFistGesture.Invoke();
                break;

            default:     // Gesture.None or any other gesture
                OnClearLeft.Invoke();
                break;
            }
        }
    }
Exemplo n.º 8
0
 public void ColorChange(HandType handType, GestureName gestureType)
 {
     if (handType == HandType.Right)
     {
         if (gestureType == GestureName.Okay)
         {
             OnRightHandOkayGesture.Invoke();
         }
         else if (gestureType == GestureName.Peace)
         {
             OnRightHandPeaceSignGesture.Invoke();
         }
         else if (gestureType == GestureName.Fist)
         {
             OnRightHandFistGesture.Invoke();
         }
         else if (gestureType == GestureName.Palm)
         {
             OnRightHandPalmGesture.Invoke();
         }
     }
     else
     {
         if (gestureType == GestureName.Okay)
         {
             OnLeftHandOkayGesture.Invoke();
         }
         else if (gestureType == GestureName.Peace)
         {
             OnLeftHandPeaceSignGesture.Invoke();
         }
         else if (gestureType == GestureName.Fist)
         {
             OnLeftHandFistGesture.Invoke();
         }
         else if (gestureType == GestureName.Palm)
         {
             OnLeftHandPalmGesture.Invoke();
         }
     }
 }
Exemplo n.º 9
0
        void Update()
        {
            hand = FingoMain.Instance.GetHand(handType);

            isDetected = hand.IsDetected();

            currentGesture = hand.GetGestureName();

            if (isDetected)
            {
                transform.localScale = Vector3.one * renderScale;
            }
            else
            {
                transform.localScale = Vector3.zero;
            }

            UpdateMeshHand();

            previousGesture = currentGesture;
        }
Exemplo n.º 10
0
    void ClickGestureTracking()
    {
        if (hand.IsDetected())
        {
            currentGesture = hand.GetGestureName();
        }
        else
        {
            currentGesture = GestureName.None;
        }

        if (currentGesture == GestureName.Point || currentGesture == GestureName.ShootEm ||
            currentGesture == GestureName.Peace || currentGesture == GestureName.MiddleFinger)
        {
            isCollidingGesture = true;
        }
        else
        {
            isCollidingGesture = false;
        }
    }
Exemplo n.º 11
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;
    }
    public void ColorChange(HandType handType, GestureName gestureType)
    {
        //Debug.Log("On GestureEvent handType: "+handType);
        //Debug.Log("On GestureEvent gestureType: " + gestureType);

        if (handType == HandType.Right)
        {
            //OnRightHandGesture.Invoke();
            //OnLeftHandGesture.Invoke();

            switch (gestureType)
            {
            case GestureName.Okay:
                OnRightHandOkayGesture.Invoke();
                break;

            case GestureName.Peace:
                OnRightHandPeaceGesture.Invoke();
                break;

            case GestureName.Fist:
                OnRightHandFistGesture.Invoke();
                break;

            case GestureName.ThumbsUp:
                OnRightHandThumbsUpGesture.Invoke();
                break;

            case GestureName.Palm:
                OnRightHandPalmGesture.Invoke();
                break;

            case GestureName.Point:
                OnRightHandPointGesture.Invoke();
                break;

            case GestureName.ShootEm:
                OnRightHandShootEmGesture.Invoke();
                break;

            case GestureName.CoverEye:
                OnRightHandCoverEyeGesture.Invoke();
                break;

            case GestureName.Pinky:
                OnRightHandPinkyGesture.Invoke();
                break;

            case GestureName.Horns:
                OnRightHandHornsGesture.Invoke();
                break;

            case GestureName.CallMe:
                OnRightHandCallMeGesture.Invoke();
                break;

            default:     // Gesture.None or any other gesture
                OnClearRight.Invoke();
                break;
            }
        }
        else if (handType == HandType.Left)
        {
            switch (gestureType)
            {
            case GestureName.Okay:
                OnLeftHandOkayGesture.Invoke();
                break;

            case GestureName.Peace:
                OnLeftHandPeaceGesture.Invoke();
                break;

            case GestureName.Fist:
                OnLeftHandFistGesture.Invoke();
                break;

            case GestureName.ThumbsUp:
                OnLeftHandThumbsUpGesture.Invoke();
                break;

            case GestureName.Palm:
                OnLeftHandPalmGesture.Invoke();
                break;

            case GestureName.Point:
                OnLeftHandPointGesture.Invoke();
                break;

            case GestureName.ShootEm:
                OnLeftHandShootEmGesture.Invoke();
                break;

            case GestureName.CoverEye:
                OnLeftHandCoverEyeGesture.Invoke();
                break;

            case GestureName.Pinky:
                OnLeftHandPinkyGesture.Invoke();
                break;

            case GestureName.Horns:
                OnLeftHandHornsGesture.Invoke();
                break;

            case GestureName.CallMe:
                OnLeftHandCallMeGesture.Invoke();
                break;

            default:     // Gesture.None or any other gesture
                OnClearLeft.Invoke();
                break;
            }
        }
    }
Exemplo n.º 13
0
 void ClearGesture()
 {
     currentFrameGestureName = GestureName.None;
 }
Exemplo n.º 14
0
    void UpdateGrabState()
    {
        GestureName currentGesture = hand.GetGestureName();

        bool isClosingFingers = (bendingAngularSpeed > anguarSpeedThresh);
        bool isOpeningFingers = (bendingAngularSpeed < -anguarSpeedThresh);

        if (activeObject != null && activeObject.IsAvailableForGrab() == false &&
            grabState != GrabState.ObjectInHold) // grabbed by the other hand
        {
            activeObject = null;
            grabState    = GrabState.ObjectOutOfReach;
        }

        if ((grabState == GrabState.ObjectOutOfReach) ||
            (grabState == GrabState.ObjectInReach && !isClosingFingers) ||
            (grabState == GrabState.ObjectReleased))
        {
            // Iterate all grabbable objects, find the closest available one.
            GrabbaleObject closestAvailableObj = null;
            float          minDistance         = 1000f;
            foreach (GrabbaleObject obj in GrabbaleObject.instances)
            {
                if (obj.IsAvailableForGrab())
                {
                    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 < grabEnableDistance);

            if (activeObject != null && (currentGesture == GestureName.Grab || currentGesture == GestureName.Palm ||
                                         currentBendingAngle < grabEnableAngle))
            {
                // 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 close enough to grab the currently active object
                if (inReach && (grabState != GrabState.ObjectInReach || activeObject != prevActiveObject))
                {
                    activeObject.OnGetInReach.Invoke();
                    grabState = GrabState.ObjectInReach;
                }
            }

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

                    grabState = GrabState.ObjectOutOfReach;
                }
            }
        }

        if (grabState == GrabState.ObjectInReach)
        {
            if ((currentBendingAngle > grabStartAngle || currentGesture == GestureName.Fist) && isClosingFingers)
            {
                // To give user visual feedbacks, make the hand transparent.
                if (meshHandRenderMgr != null)
                {
                    meshHandRenderMgr.DisableHandOutline();
                    meshHandRenderMgr.FadeOut();
                }

                if (activeObject != null)
                {
                    activeObject.OnGrab.Invoke();
                    // Save the parent transform
                    grabbedObjectParent                  = activeObject.transform.parent;
                    activeObject.transform.parent        = this.transform;
                    activeObject.transform.localPosition = Vector3.zero;
                    // Disable the object for grab
                    activeObject.SetAvailableForGrab(false);
                }
                grabState = GrabState.ObjectInHold;
            }
        }

        if (grabState == GrabState.ObjectInHold)
        {
            if (currentBendingAngle < grabEndAngle && 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 grab later
                        activeObject.SetAvailableForGrab(true, activeObject.FlyBackTime());
                    }
                    else
                    {
                        // Enable the object for grab right away
                        activeObject.SetAvailableForGrab(true, 0);
                    }
                    // Restore the parent transform
                    activeObject.transform.parent = grabbedObjectParent;
                }

                grabState = GrabState.ObjectReleased;
            }
        }

        //Debug.Log("Grab state = " + grabState);


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

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

        prevActiveObject = activeObject;
    }
Exemplo n.º 15
0
 //constructor that takes the users choice
 public Gesture(GestureName gestureChoice)
 {
     //set instance variable to inputted choice
     this.gestureChoice = gestureChoice;
 }