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