MirrorZAxis() public method

public MirrorZAxis ( bool mirror = true ) : void
mirror bool
return void
    /** Creates a new HandModel instance. */
    protected HandModel CreateHand(Hand leap_hand, HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                               as HandModel;

        hand_model.gameObject.SetActive(true);
        Leap.Utils.IgnoreCollisions(hand_model.gameObject, gameObject);
        hand_model.transform.SetParent(transform);
        hand_model.SetLeapHand(leap_hand);
        hand_model.MirrorZAxis(mirrorZAxis);
        hand_model.SetController(this);

        handEvent handHandler = onCreateHand;

        if (handHandler != null)
        {
            handHandler(hand_model);
        }

        return(hand_model);
    }
示例#2
0
    /** Creates a new HandModel instance. */
    protected HandModel CreateHand(Hand leap_hand, HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                               as HandModel;

        hand_model.gameObject.SetActive(true);
        Leap.Utils.IgnoreCollisions(hand_model.gameObject, gameObject);
        hand_model.transform.SetParent(transform);
        hand_model.SetLeapHand(leap_hand);
        hand_model.MirrorZAxis(mirrorZAxis);
        hand_model.SetController(this);

        //Marcamos con la etiqueta "Manos" para una posterior detección por colisiones
        hand_model.gameObject.tag = "Manos";

        handEvent handHandler = onCreateHand;

        if (handHandler != null)
        {
            handHandler(hand_model);
        }

        return(hand_model);
    }
    new protected void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                        HandList leap_hands,
                                        HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int>(all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands[h];

            HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

            // hmm, quite stupid way to keep track of the right hand ID...
            if (leap_hand.IsRight && !(right_model.GetType() == typeof(RigidHand)))
            {
                this.currentRightHandID = leap_hand.Id;
            }

            // If we've mirrored since this hand was updated, destroy it.
            if (all_hands.ContainsKey(leap_hand.Id) &&
                all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis)
            {
                DestroyHand(all_hands[leap_hand.Id]);
                all_hands.Remove(leap_hand.Id);
            }

            // Only create or update if the hand is enabled.
            if (model != null)
            {
                ids_to_check.Remove(leap_hand.Id);

                // Create the hand and initialized it if it doesn't exist yet.
                if (!all_hands.ContainsKey(leap_hand.Id))
                {
                    HandModel new_hand = CreateHand(model);
                    new_hand.SetLeapHand(leap_hand);
                    new_hand.MirrorZAxis(mirrorZAxis);
                    new_hand.SetController(this);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                    new_hand.transform.localScale = hand_scale * transform.lossyScale;

                    new_hand.InitHand();
                    new_hand.UpdateHand();
                    all_hands[leap_hand.Id] = new_hand;
                    if (leap_hand.Id == this.currentRightHandID)
                    {
                        this.currentRelevantPalmPosition = all_hands[leap_hand.Id].GetPalmPosition();
                        foreach (FingerModel finger in all_hands[leap_hand.Id].fingers)
                        {
                            if (finger.fingerType == Finger.FingerType.TYPE_INDEX)
                            {
                                this.currentRelevantIndexPosition = finger.GetTipPosition();
                            }
                            else if (finger.fingerType == Finger.FingerType.TYPE_THUMB)
                            {
                                this.currentRelevantThumbPosition = finger.GetTipPosition();
                            }
                        }
                    }
                }
                else
                {
                    // Make sure we update the Leap Hand reference.
                    HandModel hand_model = all_hands[leap_hand.Id];
                    hand_model.SetLeapHand(leap_hand);
                    hand_model.MirrorZAxis(mirrorZAxis);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                    hand_model.transform.localScale = hand_scale * transform.lossyScale;
                    hand_model.UpdateHand();
                    if (leap_hand.Id == this.currentRightHandID)
                    {
                        this.currentRelevantPalmPosition = all_hands[leap_hand.Id].GetPalmPosition();
                        foreach (FingerModel finger in all_hands[leap_hand.Id].fingers)
                        {
                            if (finger.fingerType == Finger.FingerType.TYPE_INDEX)
                            {
                                this.currentRelevantIndexPosition = finger.GetTipPosition();
                            }
                            else if (finger.fingerType == Finger.FingerType.TYPE_THUMB)
                            {
                                this.currentRelevantThumbPosition = finger.GetTipPosition();
                            }
                        }
                    }
                }
            }
        }

        // Destroy all hands with defunct IDs.
        for (int i = 0; i < ids_to_check.Count; ++i)
        {
            DestroyHand(all_hands[ids_to_check[i]]);
            all_hands.Remove(ids_to_check[i]);
            if (ids_to_check[i] == this.currentRightHandID)
            {
                this.currentRightHandID = -1;
            }
        }
    }
        /**
         * Makes sure the physics hands are instantiated or updated as required
         * */
        protected void UpdatePhysicsHandModels(Dictionary <int, HandModel> all_hands,
                                               HandList leap_hands,
                                               HandModel left_model, HandModel right_model)
        {
            List <int> ids_to_check = new List <int>(all_hands.Keys);

            // Go through all the active hands and update them.
            int num_hands = leap_hands.Count;

            for (int h = 0; h < num_hands; ++h)
            {
                Hand leap_hand = leap_hands[h];

                HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

                // If we've mirrored since this hand was updated, destroy it.
                if (all_hands.ContainsKey(leap_hand.Id) &&
                    all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis)
                {
                    DestroyHand(all_hands[leap_hand.Id]);
                    all_hands.Remove(leap_hand.Id);
                }

                // Only create or update if the hand is enabled.
                if (model != null)
                {
                    ids_to_check.Remove(leap_hand.Id);
                    // Create the hand and initialized it if it doesn't exist yet.
                    if (!all_hands.ContainsKey(leap_hand.Id))
                    {
                        HandModel new_hand = CreateHand(model, leap_hand.IsLeft);
                        new_hand.SetLeapHand(leap_hand);
                        new_hand.MirrorZAxis(mirrorZAxis);
                        new_hand.SetController(this);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                        new_hand.transform.localScale = hand_scale * transform.lossyScale;

                        all_hands[leap_hand.Id] = new_hand;                     //bugfix: adding to list before init/update, because if it errors during that process then it'll never get into the list and thus never be removed...
                        new_hand.InitHand();
                        new_hand.UpdateHand();

                        //Debug.Log ("Added " + leap_hand.Id + " to physics list");
                        //Debug.Log ("Created a physics hand and added to active physics hands list, now contains " + all_hands.Count + " hands");
                    }
                    else
                    {
                        //Debug.Log ("Updated a physics hand");
                        // Make sure we update the Leap Hand reference.
                        HandModel hand_model = all_hands[leap_hand.Id];
                        hand_model.SetLeapHand(leap_hand);
                        hand_model.MirrorZAxis(mirrorZAxis);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                        hand_model.transform.localScale = hand_scale * transform.lossyScale;
                        hand_model.UpdateHand();
                    }
                }
            }

            // Destroy all hands with defunct IDs.
            for (int i = 0; i < ids_to_check.Count; ++i)
            {
                DestroyHand(all_hands[ids_to_check[i]]);
                //Debug.Log ("Destroyed " + ids_to_check[i] + " from physics list because it was defunct");
                all_hands.Remove(ids_to_check[i]);
            }
        }
        /**
         * Updates the graphics hands so that they're drawn properly
         * */
        protected new void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                            HandList leap_hands,
                                            HandModel left_model, HandModel right_model)
        {
            List <int> ids_to_check = new List <int>(all_hands.Keys);

            // Go through all the active hands in the Leap motion frame and update them.
            int num_hands = leap_hands.Count;

            for (int h = 0; h < num_hands; ++h)
            {
                Hand leap_hand = leap_hands[h];

                HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

                // Only create or update if the hand is enabled.
                if (model != null)
                {
                    ids_to_check.Remove(leap_hand.Id);                  //this prevents the hand from being made inactive, since it is active.

                    // Create the hand and initialized it if it doesn't exist yet.
                    if (!all_hands.ContainsKey(leap_hand.Id))
                    {
                        HandModel new_hand = InitializeHand(model);                     //We don't instantiate these ones - they're already on the avatar, so we just init them instead of CreateHand them
                        new_hand.SetLeapHand(leap_hand);
                        new_hand.MirrorZAxis(mirrorZAxis);
                        new_hand.SetController(this);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                        new_hand.transform.localScale = hand_scale * transform.lossyScale;

                        new_hand.InitHand();
                        new_hand.UpdateHand();
                        all_hands[leap_hand.Id] = new_hand;

                        if (new_hand.GetLeapHand().IsLeft)
                        {
                            leftActive = true;
                        }
                        else
                        {
                            rightActive = true;
                        }
                        //Debug.Log ("Initialised graphics hand and added to active hands list, now contains " + all_hands.Count + " hands");
                    }
                    else
                    {
                        // Make sure we update the Leap Hand reference.
                        HandModel hand_model = all_hands[leap_hand.Id];
                        hand_model.SetLeapHand(leap_hand);
                        hand_model.MirrorZAxis(mirrorZAxis);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                        hand_model.transform.localScale = hand_scale * transform.lossyScale;
                        hand_model.UpdateHand();

                        if (hand_model.GetLeapHand().IsLeft)
                        {
                            leftActive = true;
                        }
                        else
                        {
                            rightActive = true;
                        }
                        //Debug.Log ("Updated graphics hand");
                    }
                }
            }

            // flag hands that are no longer active, so IK knows to turn off
            for (int i = 0; i < ids_to_check.Count; ++i)
            {
                if (all_hands[ids_to_check[i]].GetLeapHand().IsLeft)
                {
                    leftActive = false;
                }
                else
                {
                    rightActive = false;
                }
                all_hands.Remove(ids_to_check[i]);
            }
        }
示例#6
0
    /**
     * Updates hands based on tracking data in the specified Leap HandList object.
     * Active HandModel instances are updated if the hand they represent is still
     * present in the Leap HandList; otherwise, the HandModel is removed. If new
     * Leap Hand objects are present in the Leap HandList, new HandModels are
     * created and added to the HandController hand list.
     * @param all_hands The dictionary containing the HandModels to update.
     * @param leap_hands The list of hands from the a Leap Frame instance.
     * @param left_model The HandModel instance to use for new left hands.
     * @param right_model The HandModel instance to use for new right hands.
     */
    protected void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                    HandList leap_hands,
                                    HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int> (all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands [h];

            //Get the finger_tip location if finger is pinched
            if (leap_hand.PinchStrength > 0.2)
            {
                if (linePoints.Count == 0)
                {
                    lineRenderer.SetVertexCount(0);
                }

                FingerList point   = leap_hand.Fingers.FingerType(Finger.FingerType.TYPE_INDEX);
                Vector3    new_tip = UnityVectorExtension.ToUnity(point [0].TipPosition);
                new_tip.x = new_tip.x * 1.5f;



                lineRenderer.SetPosition(lineRenderer.positionCount - 1, new_tip);

                lineRenderer.positionCount = lineRenderer.positionCount + 1;
                lineRenderer.SetPosition(lineRenderer.positionCount - 1, new_tip);
                linePoints.Add(new_tip);
                Debug.Log("pinching: " + linePoints.Count);
                //Debug.Log (linePoints [linePoints.Count - 1]);
                if (numPoint % 15 == 0)
                {
                    lineRenderer.Simplify(.1f);
                }
                numPoint++;
            }
            else
            {
                //transform.Translate(Vector3.up * Time.deltaTime*50);

                if (linePoints.Count > 0)
                {
                    Debug.Log("not pinching: " + convertVectorListToString(linePoints) + linePoints.Count);
                    StartCoroutine(GetText());
                    //lineRenderer = gameObject.AddComponent<LineRenderer> ();
                    //lineRenderer.positionCount = 100;

                    tex = new Texture2D(128, 128);

                    string fromBase64 = equaIMG;
                    byte[] data       = System.Convert.FromBase64String(fromBase64);
                    tex.LoadImage(data);


                    cube = GameObject.Find("Cube");
                    cube.transform.position   = new Vector3(0, -100, 0);
                    cube.transform.localScale = new Vector3(tex.width * 2, tex.height * 2, 10);
                    //cube.transform.Rotate(new Vector3(0, 0, 180));

                    m_Material             = cube.GetComponent <Renderer> ().material;
                    m_Material.mainTexture = tex;


                    linePoints.Clear();
                    lineRenderer.SetVertexCount(0);

                    //lineRenderer = GetComponent<LineRenderer>();
                    lineRenderer.positionCount = equaPoints.Count;
                    lineRenderer.SetPositions(equaPoints.ToArray());
                }
                else
                {
                }
                int b = checkSwipe(leap_hand);
                if (b != 0)
                {
                    curAngle     = b * 30 * Time.deltaTime;
                    cameraObj    = GameObject.Find("Main Camera");
                    rotateAround = GameObject.Find("HandController").GetComponent <Transform> ();

                    cameraObj.transform.LookAt(rotateAround.position);
                    cameraObj.transform.RotateAround(rotateAround.position, Vector3.up, curAngle);                     //.5f);
                    //lineRenderer.transform.RotateAround(Vector3.zero, Vector3.up, b*30 * Time.deltaTime);
                }



                HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

                // If we've mirrored since this hand was updated, destroy it.
                if (all_hands.ContainsKey(leap_hand.Id) &&
                    all_hands [leap_hand.Id].IsMirrored() != mirrorZAxis)
                {
                    DestroyHand(all_hands [leap_hand.Id]);
                    all_hands.Remove(leap_hand.Id);
                }

                // Only create or update if the hand is enabled.
                if (model != null)
                {
                    ids_to_check.Remove(leap_hand.Id);
                    // Create the hand and initialized it if it doesn't exist yet.
                    if (!all_hands.ContainsKey(leap_hand.Id))
                    {
                        HandModel new_hand = CreateHand(model);
                        new_hand.SetLeapHand(leap_hand);
                        new_hand.MirrorZAxis(mirrorZAxis);
                        new_hand.SetController(this);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                        new_hand.transform.localScale = hand_scale * transform.lossyScale;
                        //new_hand.transform.RotateAround(Vector3.zero, Vector3.up, -curAngle);
                        new_hand.InitHand();

                        new_hand.UpdateHand();
                        all_hands [leap_hand.Id] = new_hand;
                    }
                    else
                    {
                        // Make sure we update the Leap Hand reference.
                        HandModel hand_model = all_hands [leap_hand.Id];
                        hand_model.SetLeapHand(leap_hand);
                        hand_model.MirrorZAxis(mirrorZAxis);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                        hand_model.transform.localScale = hand_scale * transform.lossyScale;
                        hand_model.UpdateHand();
                    }
                }
            }

            // Destroy all hands with defunct IDs.
            for (int i = 0; i < ids_to_check.Count; ++i)
            {
                DestroyHand(all_hands [ids_to_check [i]]);
                all_hands.Remove(ids_to_check [i]);
            }
        }
    }