/*****************************************************
    * 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));
                        }
                    }
                }
            }
        }
    }
Exemple #2
0
    /*****************************************************
    * 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);
    }
    /*****************************************************
    * 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);
    }