예제 #1
0
        // Handle thumbs up gesture
        // See if it is a thumbs up based on the direction it's pointing
        // If this is a thumbs up from the (right | left) hand and the (blue | orange) marker is on the wall,
        // Move the (blue | orange) portal to the position of the marker and remove the marker
        bool handleThumbsUp(Hand hand)
        {
            Finger  thumb               = leapGestures.getFingerOfType(hand.Fingers, thumbOnly[0]);
            Vector3 direction           = UnityVectorExtension.ToVector3(thumb.Direction);
            Vector3 normalizedDirection = direction.normalized;

            if (normalizedDirection.y >= 0.9 && normalizedDirection.y > normalizedDirection.x && normalizedDirection.y > normalizedDirection.z)
            {
                if (hand.IsRight && leapGestures.planeMarkerRight.activeSelf)
                {
                    leapGestures.attachmentObjectRight.SetActive(true);
                    leapGestures.attachmentObjectRight.transform.position = leapGestures.planeMarkerRight.transform.position;
                    leapGestures.attachmentObjectRight.transform.rotation = leapGestures.planeMarkerRight.transform.rotation;
                    leapGestures.planeMarkerRight.SetActive(false);
                    return(true);
                }
                else if (hand.IsLeft && leapGestures.planeMarkerLeft.activeSelf)
                {
                    leapGestures.attachmentObjectLeft.SetActive(true);
                    leapGestures.attachmentObjectLeft.transform.position = leapGestures.planeMarkerLeft.transform.position;
                    leapGestures.attachmentObjectLeft.transform.rotation = leapGestures.planeMarkerLeft.transform.rotation;
                    leapGestures.planeMarkerLeft.SetActive(false);
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        // Handle palm down action
        // Make sure the palm is facing down, then clear all objects and arrows spawned
        bool handlePalmDown(Hand hand)
        {
            Vector3 palmNormal           = UnityVectorExtension.ToVector3(hand.PalmNormal);
            Vector3 palmNormalNormalized = palmNormal.normalized;

            if (palmNormalNormalized.y <= -0.8)
            {
                collisionObjectManager.GetComponent <CollisionObjectManager>().objAllClear();
                portalManager.destroyAllArrows();
                return(true);
            }
            return(false);
        }
예제 #3
0
        // Removed this gesture since it's very easy to accidentally trigger.
        bool handlePalmSide(Hand hand)
        {
            Vector3 palmNormal           = UnityVectorExtension.ToVector3(hand.PalmNormal);
            Vector3 palmPosition         = UnityVectorExtension.ToVector3(hand.PalmPosition);
            Vector3 palmNormalNormalized = palmNormal.normalized;

            if (hand.IsLeft && (palmNormalNormalized.x >= .8 || palmNormalNormalized.z <= -.9 || palmNormalNormalized.z >= .9))
            {
            }
            if (hand.IsRight && (palmNormalNormalized.x <= -.8 || palmNormalNormalized.z <= -.9 || palmNormalNormalized.z >= .9))
            {
            }
            return(false);
        }
예제 #4
0
        // Handle thumbs down gesture
        // Leap motion seems to have difficulties detecting the thumb's position correctly when it's pointing down,
        //   so the threshold here is a little nicer.
        // Disables the portals and the wall markers.
        bool handleThumbsDown(Hand hand)
        {
            Finger  thumb               = leapGestures.getFingerOfType(hand.Fingers, thumbOnly[0]);
            Vector3 direction           = UnityVectorExtension.ToVector3(thumb.Direction);
            Vector3 normalizedDirection = direction.normalized;

            if (normalizedDirection.y <= -0.7)
            {
                leapGestures.attachmentObjectRight.SetActive(false);
                leapGestures.planeMarkerRight.SetActive(false);
                leapGestures.attachmentObjectLeft.SetActive(false);
                leapGestures.planeMarkerLeft.SetActive(false);
                return(true);
            }
            return(false);
        }
예제 #5
0
        // Handle palm up action
        // Make sure it's facing up and then spawn a random prefab from the CollisionObjectManager in your palm
        // The palmSpawnLock prevents a bunch of objects being spawned immediately when the palm is facing up
        // The palmSpawnLock gets flipped off when you arent doing a palm up/down gesture.
        bool handlePalmUp(Hand hand)
        {
            Vector3 palmNormal           = UnityVectorExtension.ToVector3(hand.PalmNormal);
            Vector3 palmPosition         = UnityVectorExtension.ToVector3(hand.PalmPosition);
            Vector3 palmNormalNormalized = palmNormal.normalized;

            if (palmNormalNormalized.y >= 0.9)
            {
                if (palmSpawnLock)
                {
                    return(false);
                }

                collisionObjectManager.GetComponent <CollisionObjectManager>().objPlacement(palmPosition, palmNormal);
                palmSpawnLock = true;
                return(true);
            }
            return(false);
        }
예제 #6
0
        // Handle menu spawning and attachment
        // Attach the menu to the position the finger is plus an offset so that it doesnt spawn on the hand itself
        // Make the menu face the normal direction of hand's palm instead of finger
        bool handleMenuGesture(Hand hand)
        {
            Finger  pointer    = leapGestures.getFingerOfType(hand.Fingers, menuSign[0]);
            Vector3 fingerPos  = UnityVectorExtension.ToVector3(pointer.TipPosition);
            Vector3 palmNormal = UnityVectorExtension.ToVector3(hand.PalmNormal);

            float offset;

            if (hand.IsLeft)
            {
                offset = .3f;
            }
            else
            {
                offset = -.3f;
            }

            Vector3 positionOffset = new Vector3(fingerPos.x + offset, fingerPos.y, fingerPos.z);

            surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToSomeSurface(leapGestures.menuObject, positionOffset, palmNormal);
            return(true);
        }
예제 #7
0
        // Handle index finger pointing action
        // First clear and draw a new pointer line
        // Check if you're pointing at a portal. If you are pointing at a portal for long enough, handle moving the portal around.
        // Check if you're pointing at a plane. If you are, create a blue/orange marker on that plane, depending on your right/left hand.
        // Markers will timeout if the portal spawn gesture isnt done soon enough.
        // Left hand = orange marker for orange portal, right = blue.
        void handlePointMarker(Hand hand)
        {
            Finger  pointer   = leapGestures.getFingerOfType(hand.Fingers, indexPointingOnly[0]);
            Vector3 fingerPos = UnityVectorExtension.ToVector3(pointer.TipPosition);
            Vector3 fingerDir = UnityVectorExtension.ToVector3(pointer.Direction);

            if (hand.IsLeft)
            {
                drawPointer(fingerPos, fingerDir, ref leftPointer);
            }
            else
            {
                drawPointer(fingerPos, fingerDir, ref rightPointer);
            }

            // Move portal instead of dealing with markers
            if (portalMove)
            {
                movePortal(fingerPos, fingerDir);
                return;
            }

            // Raycast in advance to see what we're pointing at
            RaycastHit hit;
            int        castDistance = 20;

            Physics.Raycast(fingerPos, fingerDir * castDistance, out hit);

            if (hit.collider == null)
            {
                return;
            }

            // If pointing at a portal
            if (hit.collider != null && hit.collider.gameObject.tag == portalTag)
            {
                pointingAtPortalTimeCurrent += Time.deltaTime;
                if (pointingAtPortalTimeCurrent > pointingAtPortalTime)
                {
                    moveablePortal = hit.collider.gameObject;
                    portalMove     = true;
                    portalDistance = hit.distance;
                    pointingAtPortalTimeCurrent = 0f;
                }
                return;
            }

            // If pointing at a ZEDPlane, do marker placing.
            if (!surfacePlacementManager.GetComponent <SurfacePlacementManager>().checkIfHitPlane(hit))
            {
                return;
            }

            if (leapGestures.planeMarkerRight != null && hand.IsRight)
            {
                // Disable any old timers that may be running
                if (markerTimeoutRight != null)
                {
                    StopCoroutine(markerTimeoutRight);
                }
                surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToPlaneFromWorldSpace(leapGestures.planeMarkerRight, hit);
                markerTimeoutRight = markerTimeout(leapGestures.planeMarkerRight);
                StartCoroutine(markerTimeoutRight);
            }
            else if (leapGestures.planeMarkerLeft != null && hand.IsLeft)
            {
                // Disable any old timers that may be running
                if (markerTimeoutLeft != null)
                {
                    StopCoroutine(markerTimeoutLeft);
                }
                surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToPlaneFromWorldSpace(leapGestures.planeMarkerLeft, hit);
                markerTimeoutLeft = markerTimeout(leapGestures.planeMarkerLeft);
                StartCoroutine(markerTimeoutLeft);
            }
        }