private IEnumerator fingerPointingWatcher() { Hand hand; Vector3 fingerDirection; Vector3 targetDirection; int selectedFinger = selectedFingerOrdinal(); while (true) { if (HandModel != null && HandModel.IsTracked) { hand = HandModel.GetLeapHand(); if (hand != null) { targetDirection = selectedDirection(hand.Fingers[selectedFinger].TipPosition.ToVector3()); fingerDirection = hand.Fingers[selectedFinger].Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); float angleTo = Vector3.Angle(fingerDirection, targetDirection); if (HandModel.IsTracked && angleTo <= OnAngle) { Activate(); } else if (!HandModel.IsTracked || angleTo >= OffAngle) { Deactivate(); } } } yield return(new WaitForSeconds(Period)); } }
IEnumerator extendedFingerWatcher() { Hand hand; while(true){ bool fingerState = false; if(HandModel != null && HandModel.IsTracked){ hand = HandModel.GetLeapHand(); if(hand != null){ fingerState = matchFingerState(hand.Fingers[0], Thumb) && matchFingerState(hand.Fingers[1], Index) && matchFingerState(hand.Fingers[2], Middle) && matchFingerState(hand.Fingers[3], Ring) && matchFingerState(hand.Fingers[4], Pinky); int extendedCount = 0; for (int f = 0; f < 5; f++) { if (hand.Fingers[f].IsExtended) { extendedCount++; } } fingerState = fingerState && (extendedCount <= MaximumExtendedCount) && (extendedCount >= MinimumExtendedCount); if(HandModel.IsTracked && fingerState){ Activate(); } else if(!HandModel.IsTracked || !fingerState) { Deactivate(); } } } else if(IsActive){ Deactivate(); } yield return new WaitForSeconds(Period); } }
private IEnumerator palmWatcher() { Hand hand; Vector3 normal; while (true) { if (HandModel != null) { hand = HandModel.GetLeapHand(); if (hand != null) { normal = hand.PalmNormal.ToVector3(); float angleTo = Vector3.Angle(normal, selectedDirection(hand.PalmPosition.ToVector3())); if (angleTo <= OnAngle) { Activate(); } else if (angleTo > OffAngle) { Deactivate(); } } } yield return(new WaitForSeconds(Period)); } }
private IEnumerator palmWatcher() { Hand hand; Vector3 normal; while (true) { if (HandModel != null) { hand = HandModel.GetLeapHand(); if (hand != null) { normal = hand.PalmNormal.ToVector3(); //hand.PalmPosition.ToVector3() = position of the camera; hand is a child of the camera angleTo = Vector3.SignedAngle(normal, selectedDirection(hand.PalmPosition.ToVector3()), Vector3.up); if (Math.Abs(angleTo) < 105 && Math.Abs(angleTo) > 83) { Deactivate(); Debug.Log("Deactivate -> angleTo = " + angleTo); } else if (!(Math.Abs(angleTo) < 105 && Math.Abs(angleTo) > 83)) { // Debug.Log("Deactivate: angleTo -> " + angleTo + "; OnAngle -> " + OnAngle + "; OffAngle -> " + OffAngle + "; normal = " + normal); Activate(); } } } yield return(new WaitForSeconds(Period)); } }
private Vector3 GetFingerPosition() { Finger finger = HandModel.GetLeapHand().Fingers[1]; Vector3 fingerDirection = finger.Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); Vector3 from = finger.TipPosition.ToVector3(); Vector3 Direction = finger.Direction.ToVector3(); return(Direction); }
public void scaleDown() { transform.localScale = new Vector3(0.001f, 0.001f, 0.001f); transform.rotation = Quaternion.Euler(-90, -30, -90); //handModel = GameObject.Find("RigidRoundHand_L").GetComponent<ExtendedFingerDetector>().HandModel; if (handModel != null) { transform.position = handModel.GetLeapHand().PalmPosition.ToVector3(); } }
private IEnumerator fingerPointingWatcher() { Hand hand; Vector3 fingerDirection; Vector3 targetDirection; int selectedFinger = selectedFingerOrdinal(); while (true) { if (HandModel != null && HandModel.IsTracked) { hand = HandModel.GetLeapHand(); if (hand != null) { targetDirection = selectedDirection(hand.Fingers[selectedFinger].TipPosition.ToVector3()); fingerDirection = hand.Fingers[selectedFinger].Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); float angleTo = Vector3.Angle(fingerDirection, targetDirection); Finger finger = HandModel.GetLeapHand().Fingers[selectedFingerOrdinal()]; Vector3 Direction = finger.Direction.ToVector3(); tippos = finger.TipPosition.ToVector3(); if (HandModel.IsTracked && angleTo <= OnAngle) { Activate(); //Finger°¡ È°¼ºÈ ‰çÀ»¶§ Finger TipPositionÀ¸·ÎºÎÅÍÀÇ Á÷¼± ¹æÁ¤½Ä°ú Canvas°¡ ÀÖ´Â //ZÃàÀÇ Æò¸éÀ¸·ÎºÎÅÍÀÇ Á¢Á¡À» ã¾Æ Cube¸¦ ¶ç¿öÁØ´Ù cube.transform.position = tippos + (-(tippos.z)) * Direction / (Direction.z); } else if (!HandModel.IsTracked || angleTo >= OffAngle) { Deactivate(); cube.transform.position = new Vector3(0, 0, 0); } } } yield return(new WaitForSeconds(Period)); } }
public void AddModel(HandModelBase model) { if (handModels == null) { handModels = new List <HandModelBase>(); } handModels.Add(model); if (model.GetLeapHand() == null) { model.SetLeapHand(MostRecentHand); model.InitHand(); model.BeginHand(); model.UpdateHand(); } else { model.SetLeapHand(MostRecentHand); model.BeginHand(); } }
IEnumerator extendedFingerWatcher() { Hand hand; while (true) { if (HandModel != null && HandModel.IsTracked) { hand = HandModel.GetLeapHand(); if (HandModel.IsTracked) { extendedCount = 0; for (int f = 0; f < 5; f++) { if (hand.Fingers[f].IsExtended) { extendedCount++; } } EstadoThumb = fn_fingerState(hand.Fingers[0]); EstadoIndex = fn_fingerState(hand.Fingers[1]); EstadoMiddle = fn_fingerState(hand.Fingers[2]); EstadoPinky = fn_fingerState(hand.Fingers[4]); EstadoRing = fn_fingerState(hand.Fingers[3]); } } else { EstadoThumb = EstadoIndex = EstadoMiddle = EstadoPinky = EstadoRing = 0; extendedCount = 0; } yield return(new WaitForSeconds(Period)); } }
void Update() { selectedObject = GameObject.FindWithTag("Selected"); if (selectedObject != null) { ///Create box collider of the selected object if it doesn't exist yet if (selectedObject.GetComponent <BoxCollider>() == null) { if (selectedObject.transform.childCount == 0) { //Assets.Scripts.Support.Collider.CreateBoxColliderOfPart(selectedObject); } else { //Assets.Scripts.Support.Collider.CreateBoxColliderOfComponent(selectedObject); } } var bbox = selectedObject.GetComponent <BoxCollider>(); //Coordinates of the center of the box collider Vector3 barycenterSelectedObject = bbox.center; //Scale of the selectedObject Vector3 scaleFactor = selectedObject.transform.localScale; ///---> actually the scale is homogeneus on the three dimensions //Multiply scales of all parents of the selectedObject Transform tranformParent = selectedObject.transform.parent; scaleParents = new Vector3(1, 1, 1); rotationsParent = Quaternion.Euler(0, 0, 0); while (tranformParent != null) { rotationsParent = tranformParent.localRotation * rotationsParent; scaleParents = Vector3.Scale(scaleParents, tranformParent.localScale); tranformParent = tranformParent.parent; } if (extendedFingerDetectorL != null && extendedFingerDetectorL.IsActive && extendedFingerDetectorR != null && extendedFingerDetectorR.IsActive) { //if (time > ReferencialDisplay.gestureWaitingTime) { /// When the gesture is avtive disable the scripts for the hand menu appearance to disambiguate the functionalities. //GameObject.Find("Attachment Hands").GetComponent<HandMenuAppearance>().enabled = false; //GameObject.Find("CenterEyeAnchor").GetComponent<Gaze>().enabled = false; selectedObject.gameObject.GetComponent <InteractionBehaviour>().ignoreGrasping = true; /// Store direction between palms palmPosition_L = HandModel_L.GetLeapHand().PalmPosition.ToVector3(); palmPosition_R = HandModel_R.GetLeapHand().PalmPosition.ToVector3(); palmsDirection = palmPosition_R - palmPosition_L; /// If it is the first frame in which there are two palms (again) set "lastpalmsDirection" /// equals to "palmsDirection" in order to have, at first, deltaAngle=0 and not to rotate the object at /// the first time according to the direction of palms. if (_rotationActive == false) { var assemblies = GameObject.Find("Assemblies"); var soundPath = @"Audio/activation"; //FeedBack.AudioPlay(assemblies, soundPath); lastPalmsDirection = palmsDirection; // Save in a list the selectedObject and its transform before each transformation ( for the UNDO operation) var position = new Vector3(); var rotation = new Quaternion(); var scale = new Vector3(); position = selectedObject.transform.localPosition; scale = selectedObject.transform.localScale; rotation = selectedObject.transform.localRotation; TransformGameObject transformSelectedObject = new TransformGameObject(selectedObject, position, rotation, scale); //VoiceController.transformationsFlow.Add(transformSelectedObject); _rotationActive = true; } Quaternion handRot = Quaternion.FromToRotation(lastPalmsDirection, palmsDirection); /// Rotate and replace the object. Two different cases: if the object is an assembly or /// if it is a comonent/part. The assembly must be set in the origin (0,0,0) before rotate, /// the component/part no because locally it is in (0,0,0) yet. if (selectedObject.transform.parent.name == "Assemblies") { // Translation of the selectedObject from the _userPlace (add this vector after the rotation to replace the object in its initial position) //Vector3 translation = selectedObject.transform.position - ReferencialDisplay._userPlace + selectedObject.transform.localRotation * Vector3.Scale(barycenterSelectedObject, scaleFactor); // Put the selectedObject in the origin (0,0,0) selectedObject.transform.position = -Vector3.Scale(barycenterSelectedObject, scaleFactor); // Rotate the selectedObject selectedObject.transform.rotation = handRot * selectedObject.transform.rotation; // Replace the selectedObject in the origin (0,0,0) by applying the inverse transformation to the position selectedObject.transform.position = selectedObject.transform.localRotation * selectedObject.transform.position; // Put the selectedObject in the initial position (userPlace + translation) //selectedObject.transform.position = selectedObject.transform.position + ReferencialDisplay._userPlace + translation; } else { // Calculate the translation of the selectedObject after a scale (if the object hasn't been scaled scaleTranslation = 0 ) // (add this vector, correctly rotated, to the final position in order to replace the object in its initial position ) Vector3 translationScale = -barycenterSelectedObject * (selectedObject.transform.localScale.x - 1); // Translation of the selectedObject from its position in the assembly (add this vector after the rotation to replace the object in its initial position) Vector3 translation = selectedObject.transform.localPosition - (barycenterSelectedObject - selectedObject.transform.localRotation * barycenterSelectedObject + selectedObject.transform.localRotation * translationScale); // Rotate the selectedObject selectedObject.transform.rotation = handRot * selectedObject.transform.rotation; // Replace the selectedObject in the initial position (locally) selectedObject.transform.localPosition = barycenterSelectedObject - selectedObject.transform.localRotation * barycenterSelectedObject + selectedObject.transform.localRotation * translationScale + translation; } lastPalmsDirection = palmsDirection; } } else { _rotationActive = false; selectedObject.gameObject.GetComponent <InteractionBehaviour>().ignoreGrasping = false; //GameObject.Find("Attachment Hands").GetComponent<HandMenuAppearance>().enabled = true; //GameObject.Find("CenterEyeAnchor").GetComponent<Gaze>().enabled = true; time = 0.0f; } time += Time.deltaTime; } }
IEnumerator extendedFingerWatcher() { Hand ManoDerecha = new Hand(); Hand ManoIzquierda = new Hand(); while (true) { if (v_HandModelDerecha != null && v_HandModelDerecha.IsTracked) { v_ManoDerechaActiva = true; if (v_HandModelDerecha.GetLeapHand().IsRight) { ManoDerecha = v_HandModelDerecha.GetLeapHand(); } if (v_HandModelDerecha.IsTracked) { v_NumeroDeDedosActivosHDerecha = 0; for (int f = 0; f < 5; f++) { if (ManoDerecha.Fingers[f].IsExtended) { v_NumeroDeDedosActivosHDerecha++; } } v_EstadoThumbDerecho = fn_fingerState(ManoDerecha.Fingers[0]); v_EstadoIndexDerecho = fn_fingerState(ManoDerecha.Fingers[1]); v_EstadoMiddleDerecho = fn_fingerState(ManoDerecha.Fingers[2]); v_EstadoPinkyDerecho = fn_fingerState(ManoDerecha.Fingers[4]); v_EstadoRingDerecho = fn_fingerState(ManoDerecha.Fingers[3]); } } else { v_EstadoIndexDerecho = v_EstadoMiddleDerecho = v_EstadoPinkyDerecho = v_EstadoRingDerecho = v_EstadoThumbDerecho = 0; v_NumeroDeDedosActivosHDerecha = 0; v_ManoDerechaActiva = false; v_PosicionManoDerecha = ""; } if (v_HandModelIzquierda != null && v_HandModelIzquierda.IsTracked) { v_ManoIzquierdaActiva = true; if (v_HandModelIzquierda.GetLeapHand().IsLeft) { ManoIzquierda = v_HandModelIzquierda.GetLeapHand(); } if (v_HandModelIzquierda.IsTracked) { v_NumeroDeDedosActivosHIzquierda = 0; for (int f = 0; f < 5; f++) { if (ManoIzquierda.Fingers[f].IsExtended) { v_NumeroDeDedosActivosHIzquierda++; } } v_EstadoThumbIzquierdo = fn_fingerState(ManoIzquierda.Fingers[0]); v_EstadoIndexIzquierdo = fn_fingerState(ManoIzquierda.Fingers[1]); v_EstadoMiddleIzquierdo = fn_fingerState(ManoIzquierda.Fingers[2]); v_EstadoPinkyIzquierdo = fn_fingerState(ManoIzquierda.Fingers[4]); v_EstadoRingIzquierdo = fn_fingerState(ManoIzquierda.Fingers[3]); } } else { v_EstadoPinkyIzquierdo = v_EstadoMiddleIzquierdo = v_EstadoIndexIzquierdo = v_EstadoRingIzquierdo = v_EstadoThumbIzquierdo = 0; v_NumeroDeDedosActivosHIzquierda = 0; v_ManoIzquierdaActiva = false; v_PosicionManoIzquierda = ""; } yield return(new WaitForSeconds(v_periodoActualizacion)); } }
// Update is called once per frame void Update() { if (Leapcamera == null) { Leapcamera = GameObject.FindGameObjectWithTag("MainCamera"); } if (actor == null) { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); } actor = player.GetComponentInChildren <Actor>(); } if (rotateRight) { if (handRight == null) { handRight = right.GetLeapHand(); } Leapcamera.transform.RotateAround(this.transform.position, Vector3.up, 30 * Time.deltaTime); } else if (rotateLeft) { if (handLeft == null) { handLeft = left.GetLeapHand(); } Leapcamera.transform.RotateAround(this.transform.position, Vector3.up, -30 * Time.deltaTime); } else if (moveUp) { if (handRight == null) { handRight = right.GetLeapHand(); } Vector3 dir = new Vector3(handRight.PalmNormal.x, 0.0f, handRight.PalmNormal.z); Vector3 cameraPos = Leapcamera.transform.position; Vector3 newPos = cameraPos + (dir / 60.0f); Vector3 checkPos = cameraPos + (dir / 10.0f); if (actor != null) { actor.NetworkUpateLeapPos(checkPos); } // Debug.Log("checkPos: " + checkPos + " newPos: " + newPos); Debug.Log("distance: " + actor.getDistanceToOtherPlayer()); // print(Vector3.Distance(newPos, Vector3.zero)); if (actor.getDistanceToOtherPlayer() < 500) { Leapcamera.transform.position = newPos; } } }