/***************************************************** * DETECTED FIST GESTURE * * INFO: Valide la détection du geste qui consiste * à tapper des mains. La fonction * communique directement avec le médiateur * du contrôleur de gestes. * *****************************************************/ public override bool IsDetectedGesture() { bool isClapping = false; //Si les deux mains sont visibles if (DetectionController.GetInstance().IsBothHandsVisible() && cooldownLeft <= 0.0f) { //La main gauche et droite DetectionController.HandController leftHand = DetectionController.GetInstance().GetHand(HandsE.gauche); DetectionController.HandController rightHand = DetectionController.GetInstance().GetHand(HandsE.droite); if (leftHand.GetHandVelocity().magnitude >= clapSpeed && rightHand.GetHandVelocity().magnitude >= clapSpeed) { //Si les deux mains sont assez proche l'une de l'autre if (DetectionController.GetInstance().GetDistanceBetweenHands() <= handsDistance) { cooldownLeft = cooldownTime; isClapping = true; } } } DisplayDectedGesture(isClapping); return(isClapping); }
/***************************************************** * DETECTED ONLY INDEX GESTURE * * INFO: Retourne vrai si seulement ce doigt est ouvert. * *****************************************************/ public override bool IsDetectedGesture() { //Si la main du geste n'est pas détectée. if (!DetectionController.GetInstance().IsHandDetected(hand)) { return(false); } DetectionController.HandController handController = DetectionController.GetInstance().GetHand(hand); onlyThisFingerOpened = false; //Pour tous les doigts de la main, partant de l'auriculaire for (int i = 0; i < (int)FingersE.auriculaire; i++) { FingersE _finger = FingersE.pouce + i; if (handController.GetFinger(_finger).IsFingerOpen()) { //Verifie si seulement le doigt est ouvert et que les autres sont fermés if (_finger == finger) { onlyThisFingerOpened = true; } else { return(false); } } } DisplayDectedGesture(onlyThisFingerOpened); return(onlyThisFingerOpened); }
/***************************************************** * DETECTED SINGLE FINGER GESTURE * * INFO: Valide la détection du geste qui consiste à * garder le pouce ou l'index ou l'index et le pouce * ouvert.La fonction communique directement avec * le médiateur du contrôleur de gestes. * *****************************************************/ public override bool IsDetectedGesture() { bool isFingerOpen = false; //Si la main est détectée if (DetectionController.GetInstance().IsHandDetected(hand)) { //Recupère le contrôleur de la la main DetectionController.HandController detectedHand = DetectionController.GetInstance().GetHand(hand); for (int i = 0; i < 4; i++) { if (detectedHand.GetFinger((FingersE)i).IsFingerOpen()) { //Si le ou les bons doigts de la main sont ouverts if ((FingersE)i == FingersE.pouce || (FingersE)i == FingersE.index) { isFingerOpen = true; } else { return(false); } } } } //DisplayDectedGesture(isFingerOpen); return(isFingerOpen); }
/***************************************************** * UPDATE THUMB/INDEX ROTATION * * INFO: Maintient à jour la rotation de l'objet 3D * en fonction du pouce et de l'index de la main. * Ajuste dynamiquement la vitesse de rotation * selon la position du ou des doigts qui * causent la rotation. C'est ici qu'on valide * quels sont les doigts ouverts. * * *** TO OPTIMIZE *** * *****************************************************/ private void ThumbIndexRotation() { //Si la main qui permet d'effecuer la rotation est détectée. //Si la manipulation contrôlé d'objet est activé. if (DetectionController.GetInstance().IsHandDetected(ThumbOrIndexGesture.GetInstance().GetHand()) && PalmUIController.GetInstance().IsManipulationControlled()) { //La liste des objets sélectionnés avec le raycast List <SelectedObject> objectsToRotateList = SelectionController.GetInstance().GetSelectedObjects(); if (objectsToRotateList.Count > 0) { //Recupère le contrôleur de la la main detectedHand = DetectionController.GetInstance().GetHand(ThumbOrIndexGesture.GetInstance().GetHand()); //Change l'etat des doigts si le pouce et/ou l'index est ouvert if (detectedHand.GetFinger(FingersE.pouce).IsFingerOpen() || detectedHand.GetFinger(FingersE.index).IsFingerOpen()) { isThumbOpen = detectedHand.GetFinger(FingersE.pouce).IsFingerOpen() ? true : false; isIndexOpen = detectedHand.GetFinger(FingersE.index).IsFingerOpen() ? true : false; } foreach (SelectedObject objectToRotate in objectsToRotateList) { //Applique la rotation en fonction de la force Vector3 rotationSpeed = stopPosition * amplifyFingerRotation; Vector3 dynamicRotation = objectToRotate.TransformObject.worldToLocalMatrix * rotationSpeed; objectToRotate.TransformObject.Rotate(dynamicRotation); startPosition = Vector3.Lerp(stopPosition, Vector3.zero, Time.deltaTime); } } } }
/***************************************************** * UPDATE SWIPE ROTATION * * INFO: Evenement qui permet de maintenir a jour la * rotation de l'objet lorsque l'utilisateur effectue * un geste Swipe. * * *** TO OPTIMIZE *** * *****************************************************/ public void UpdateSwipeRotation() { //Si la manipulation contrôlé d'objet est activé if (PalmUIController.GetInstance().IsManipulationControlled()) { //La liste des objets sélectionnés avec le raycast List <SelectedObject> objectsToRotateList = SelectionController.GetInstance().GetSelectedObjects(); if (objectsToRotateList.Count > 0) { //Le type de Swipe effectué (gauche, droite, haut, bas) swipeType = GestureMediator.GetGestureType(); if (swipeType.Contains("Swipe")) { foreach (SelectedObject objectToRotate in objectsToRotateList) { detectedHand = DetectionController.GetInstance().GetHand(GestureMediator.GetDetectedHand()); float velocityX = 0f; float velocityY = 0f; //La velocité du swipe en X ou Y if (isRotationX) { velocityX = -detectedHand.GetHandVelocity().x; } if (isRotationY) { velocityY = detectedHand.GetHandVelocity().y; } allowCoroutine = true; //Rotation horizontale (Swipe gauche ou droite) if (isRotationX && (swipeType.Contains("droite") || swipeType.Contains("gauche"))) { //Demarre la rotation horizontale selon le type choisi (swipe lock angle / swipe velocity) Vector3 axis = Mathf.Sign(velocityX) * Vector3.up; StartCoroutine(isLockRotation ? RotateWhenSwipe(objectToRotate.TransformObject, axis, rotationAngle, secondsToRotate) : RotateFreeWhenSwipe(objectToRotate.TransformObject, axis, velocityX)); } //Rotation verticale (Swipe haut ou bas) if (isRotationY && (swipeType.Contains("haut") || swipeType.Contains("bas"))) { //Demarre la rotation verticale selon le type choisi (swipe lock angle / swipe velocity) Vector3 axis = Mathf.Sign(velocityY) * Vector3.right; StartCoroutine(isLockRotation ? RotateWhenSwipe(objectToRotate.TransformObject, axis, rotationAngle, secondsToRotate) : RotateFreeWhenSwipe(objectToRotate.TransformObject, axis, velocityY)); } } } } } }
/***************************************************** * DETECTED FIST GESTURE * * INFO: Valide la détection du geste qui consiste * à fermer la main (poing). La fonction * communique directement avec le médiateur * du contrôleur de gestes. * *****************************************************/ public override bool IsDetectedGesture() { isFisting = false; if (DetectionController.GetInstance().IsHandDetected(hand)) { DetectionController.HandController handController = DetectionController.GetInstance().GetHand(hand); isFisting = handController.IsFist(tolerance) && handController.IsAllFingersClosed() && !BothFistGesture.GetInstance().IsBothFisting(); } DisplayDectedGesture(isFisting); return(isFisting); }
/***************************************************** * IS HAND SWIPING * * INFO: Valide le sens du glissement effectuée par * la main et retourne la reponse. * *****************************************************/ bool IsHandSwiping(ref DirectionsE _direction) { // Recupere le controleur de la main détectée DetectionController.HandController detectHand = DetectionController.GetInstance().GetHand(hand); // Recupere la velocité de la main Vector3 velocity = detectHand.GetHandVelocity(); velocity = Camera.main.transform.InverseTransformDirection(velocity); // Glissement vers la droite (+X) if (velocity.x >= this.velocity) { _direction = DirectionsE.droite; return(true); } // Glissement vers la gauche (-X) else if (velocity.x <= -this.velocity) { _direction = DirectionsE.gauche; return(true); } // Glissement vers le haut (+Y) else if (velocity.y >= this.velocity) { _direction = DirectionsE.haut; return(true); } // Glissement vers le bas (-Y) else if (velocity.y <= -this.velocity) { _direction = DirectionsE.bas; return(true); } // Glissement vers l'interieur (+Z) else if (velocity.z >= this.velocity) { _direction = DirectionsE.interieur; return(true); } // Glissement vers l'exterieur (-Z) else if (velocity.z <= -this.velocity) { _direction = DirectionsE.exterieur; return(true); } return(false); }
/***************************************************** * DETECTED FIST GESTURE * * INFO: Valide la détection du geste qui consiste * à fermer les deux mains (poing). La fonction * communique directement avec le médiateur * du contrôleur de gestes. * *****************************************************/ public override bool IsDetectedGesture() { isBothFist = false; if (DetectionController.GetInstance().IsHandDetected(HandsE.gauche) && DetectionController.GetInstance().IsHandDetected(HandsE.droite)) { DetectionController.HandController leftHand = DetectionController.GetInstance().GetHand(HandsE.gauche); DetectionController.HandController rightHand = DetectionController.GetInstance().GetHand(HandsE.droite); isBothFist = leftHand.IsFist(tolerance) && leftHand.IsAllFingersClosed() && rightHand.IsFist(tolerance) && rightHand.IsAllFingersClosed(); } DisplayDectedGesture(isBothFist); return(isBothFist); }
// Update is called once per frame void Update() { if (DetectionController.GetInstance().IsHandDetected(hand)) { handController = DetectionController.GetInstance().GetHand(hand); //Si le doigt du raycast est le seul d'ouvert et le Palm UI n'est pas affiché if (handController.IsIndexOpened()) //&& !PalmUIController.GetInstance().IsPalmUIOpen() { //La position du bout du foigt et la direction auquelle il pointe fingerController = handController.GetFinger(finger); light.transform.position = fingerController.GetFingertipPosition(); light.transform.rotation = Quaternion.LookRotation(fingerController.GetFingerDirection()); } } }
/***************************************************** * UPDATE * * INFO: Deplace un objet de sa position vers celle * de la camera en un temps donné. * *****************************************************/ void Update() { //La main utilisé pour sélectionner un objet 3D DetectionController.HandController handController = DetectionController.GetInstance().GetHand(SelectionController.GetInstance().GetHand()); if (handController.IsHandSet()) { //La liste des objets sélectionnés avec le raycast List <SelectedObject> objectsToPullList = SelectionController.GetInstance().GetSelectedObjects(); if (objectsToPullList.Count > 0) { foreach (SelectedObject objectToPull in objectsToPullList) { //Pour rapprocher (tirer) l'objet if (isReadyToPull && isPullObject) { isPullObject = false; wasPullingObject = true; //La position de la camera avec un offset pour garder une certaine distance avec l'objet Transform camera = Camera.main.transform; Vector3 cameraPosition = camera.position + camera.forward * offsetToCamera; //Demarre le deplacement de l'objet vers la camera aen un temps donné StartCoroutine(MoveToPosition(objectToPull, cameraPosition, translationTime)); } //Pour remettre (pousser) l'objet a sa position initial if (isReadyToPush && isPushBackObject && wasPullingObject) { isPushBackObject = false; wasPullingObject = false; //Demarre le deplacement de l'objet vers sa position initiale apres avoir tiré l'objet StartCoroutine(MoveToPosition(objectToPull, objectToPull.GetInitialPosition(), translationTime)); } } } } }
/***************************************************** * DETECTED ONLY INDEX AND THUMB GESTURE * * INFO: Retourne vrai si seulement le pouce et * l'index sont ouverts. * *****************************************************/ public override bool IsDetectedGesture() { bool isGunGesture = false; //Si la bonne main est détectée if (DetectionController.GetInstance().IsHandDetected(hand)) { bool isIndexOpen = false; bool isThumbOpen = false; DetectionController.HandController handController = DetectionController.GetInstance().GetHand(hand); //Pour tous les doigts de la main foreach (DetectionController.FingerController finger in handController.GetFingers()) { //Verifie si l'index et le pouce sont ouverts et que les autres doigts sont fermés if (finger == handController.GetFinger(FingersE.index) || finger == handController.GetFinger(FingersE.pouce)) { if (finger == handController.GetFinger(FingersE.index)) { isIndexOpen = finger.IsFingerOpen(); } if (finger == handController.GetFinger(FingersE.pouce)) { isThumbOpen = finger.IsFingerOpen(); } } //else if (finger == handController.GetFinger(Fingers5.pouce)) { isOnlyIndexThumbOpen = finger.IsFingerOpen(); } else { if (finger.IsFingerOpen()) { isIndexOpen = isThumbOpen = false; } } } isGunGesture = isIndexOpen && isThumbOpen; } DisplayDectedGesture(isGunGesture); return(isGunGesture); }
/***************************************************** * INITIATE RAYCAST * * INFO: Demarre le raycast effectué à partir du bout * d'un doigt pour une main quelconque. * * Initialise le laser et la sélection d'objet * par raycast et Gun gesture. * * Fonction appelé en boucle par le DetectionController. * *****************************************************/ public void InitiateRaycast() { //Si la main du raycast est détecté if (DetectionController.GetInstance().IsHandDetected(raycastHand)) { handController = DetectionController.GetInstance().GetHand(raycastHand); //Si le doigt du raycast est le seul d'ouvert et le Palm UI n'est pas affiché if (handController.IsIndexOpened() && !PalmUIController.GetInstance().IsPalmUIOpen()) { //Les controleurs de la main et doigt fingerController = handController.GetFinger(raycastFinger); Ray ray = fingerController.GetFingerRay(); //Trace la ligne rouge dans le sens que pointe le doigt de la main 3D Debug.DrawRay( fingerController.GetFingertipPosition(), ray.direction, raycastColor, Time.deltaTime, true); //Active le point de lumiere (point raycast) lightDot.SetActive(activateLightDot); //Permet la selection d'objets 3D avec le raycast SelectObjectWithRaycast(ray); } // Si le raycast est désactivé, on reset une fois le highlight des objets else { CheckResetHighlight(); } } // Si la main du raycast n'est plus détecté, on reset une fois le highlight des objets else { CheckResetHighlight(); } }
/***************************************************** * GET FINGER POSITION * * INFO: Supporte la rotation effectuée avec l'index * et/ou le pouce. * * Retourne la position du bout du doigt. On * met la priorité sur l'index. Sinon ce sera * avec la position du bout du pouce pour indiquer * quel sens la rotation doit prendre. * *****************************************************/ private Vector3 GetFingerPosition() { //La main utilisée pour effectuer le geste Pouce ou Index. HandsE hand = ThumbOrIndexGesture.GetInstance().GetHand(); //Si la main initialisée pour effecuer la rotation est détectée if (DetectionController.GetInstance().IsHandDetected(hand)) { Vector3 fingertip = Vector3.zero; detectedHand = DetectionController.GetInstance().GetHand(hand); if (isIndexOpen) { fingertip += detectedHand.GetFinger(FingersE.index).GetFingertipPosition(); } else if (isThumbOpen) { fingertip += detectedHand.GetFinger(FingersE.pouce).GetFingertipPosition(); } return(fingertip); } return(Vector3.zero); }