// 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); }
// 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); }
// 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); } }