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)); } }
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], 0) && matchFingerState(hand.Fingers[1], 1) && matchFingerState(hand.Fingers[2], 2) && matchFingerState(hand.Fingers[3], 3) && matchFingerState(hand.Fingers[4], 4); if (HandModel.IsTracked && fingerState) { Activate(); } else if (!HandModel.IsTracked || !fingerState) { Deactivate(); } } } else if (IsActive) { Deactivate(); } yield return(new WaitForSeconds(Period)); } }
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)); } }
//A function to run fingerpointing... for all tag objects 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) { foreach (GameObject obj in taggedObjects) { targetDirection = selectedDirection(hand.Fingers[selectedFinger].TipPosition.ToVector3(), obj); fingerDirection = hand.Fingers[selectedFinger].Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); float angleTo = Vector3.Angle(fingerDirection, targetDirection); if (HandModel.IsTracked && angleTo <= OnAngle) { //Activate(); FingerDirectionTarget thisTarget = obj.GetComponent("FingerDirectionTarget") as FingerDirectionTarget; //Access scripts attached to target objects thisTarget.testMethod(); } else if (!HandModel.IsTracked || angleTo >= OffAngle) { //Deactivate(); } } } } yield return(new WaitForSeconds(Period)); } }
protected virtual void ensurePinchInfoUpToDate() { if (Time.frameCount == _lastUpdateFrame) { return; } _lastUpdateFrame = Time.frameCount; _didChange = false; Hand hand = _handModel.GetLeapHand(); if (hand == null || !_handModel.IsTracked) { changePinchState(false); return; } float pinchDistance = hand.PinchDistance * MM_TO_M; transform.rotation = hand.Basis.CalculateRotation(); var fingers = hand.Fingers; transform.position = Vector3.zero; for (int i = 0; i < fingers.Count; i++) { Finger finger = fingers[i]; if (finger.Type == Finger.FingerType.TYPE_INDEX || finger.Type == Finger.FingerType.TYPE_THUMB) { transform.position += finger.Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3(); } } transform.position /= 2.0f; if (_isPinching) { if (pinchDistance > _deactivatePinchDist) { changePinchState(false); return; } } else { if (pinchDistance < _activatePinchDist) { changePinchState(true); } } if (_isPinching) { _pinchPos = transform.position; _pinchRotation = transform.rotation; } }
protected virtual void ensurePinchInfoUpToDate() { if (Time.frameCount == _lastUpdateFrame) { return; } _lastUpdateFrame = Time.frameCount; _didChange = false; Hand hand = _handModel.GetLeapHand(); ////Trying to pinch each finger with thumb handType = hand; //Vector handXBasis = hand.PalmNormal.Cross(hand.Direction).Normalized; //Debug.Log("handXBasis" + handXBasis); //Debug.Log("PalmNorma"+hand.PalmNormal); if (hand == null || !_handModel.IsTracked) { changePinchState(false); return; } FingerTips(hand); // handType(hand); }
protected virtual void ensureGrabInfo() { Hand hand = _handModel.GetLeapHand(); var fingers = hand.Fingers; grabDetection(fingers); }
public override void AddModel(IHandModel model) { // Check is Remote or not if (model.isRemote != this.IsRemote_) { return; } if (handModels == null) { handModels = new List <IHandModel>(); // 有Bug???? } 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) { 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)); } }
public HandProxy(HandPool parent, IHandModel handModel, Hand hand) : base(hand.Id) { this.parent = parent; this.handModel = handModel; // Check to see if the hand model has been initialized yet if (handModel.GetLeapHand() == null) { handModel.SetLeapHand(hand); handModel.InitHand(); } else { handModel.SetLeapHand(hand); } handModel.BeginHand(); }
public override void AddModel(IHandModel model) { if (handModels == null) { handModels = new List<IHandModel>(); } handModels.Add(model); if (model.GetLeapHand() == null) { model.SetLeapHand(MostRecentHand); model.InitHand(); model.BeginHand(); model.UpdateHand(); } else { model.SetLeapHand(MostRecentHand); model.BeginHand(); } }
public override void AddModel(IHandModel model) { if (handModels == null) { handModels = new List <IHandModel>(); } handModels.Add(model); if (model.GetLeapHand() == null) { model.SetLeapHand(MostRecentHand); model.InitHand(); model.BeginHand(); model.UpdateHand(); } else { model.SetLeapHand(MostRecentHand); model.BeginHand(); } }
protected virtual void ensureRollInfo() { Hand hand = _handModel.GetLeapHand(); float roll = -hand.PalmNormal.Roll; float rollDegrees = ToDegrees(roll); Debug.Log(rollDegrees); if ((rollDegrees > 85 || rollDegrees < -85)) { if (canGrow) { SetCounter(); } } else { canGrow = true; } }
IEnumerator extendedFingerWatcher() { Hand hand; while (true) { bool fingerState = false; if (HandModel != null && HandModel.IsTracked) { hand = HandModel.GetLeapHand(); if (hand != null) { string code; if (level == -1) { level = 0; code = getSerialCode(level); sendToSerial(code); } fingerState = matchFingerState(hand.Fingers[0], 0) && matchFingerState(hand.Fingers[1], 1) && matchFingerState(hand.Fingers[2], 2) && matchFingerState(hand.Fingers[3], 3) && matchFingerState(hand.Fingers[4], 4); if (HandModel.IsTracked && fingerState) { if (level < gestures.Length - 1) { level++; setGesture(gestures[level]); } else if (level == gestures.Length - 1) { level++; } code = getSerialCode(level); sendToSerial(code); Activate(); } else if (!HandModel.IsTracked || !fingerState) { Deactivate(); } } } else { if (level != -1 && level != gestures.Length) { level = -1; setGesture(gestures[0]); string code = getSerialCode(level); sendToSerial(code); } if (IsActive) { Deactivate(); } } yield return(new WaitForSeconds(Period)); } }
protected virtual void ensurePinchInfoUpToDate() { if (Time.frameCount == _lastUpdateFrame) { return; } _lastUpdateFrame = Time.frameCount; _didChange = false; Hand hand = _handModel.GetLeapHand(); if (hand == null || !_handModel.IsTracked) { changePinchState(false); return; } float pinchDistance = hand.PinchDistance * MM_TO_M; transform.rotation = hand.Basis.CalculateRotation(); var fingers = hand.Fingers; transform.position = Vector3.zero; for (int i = 0; i < fingers.Count; i++) { Finger finger = fingers[i]; if (finger.Type == Finger.FingerType.TYPE_INDEX || finger.Type == Finger.FingerType.TYPE_THUMB) { transform.position += finger.Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3(); } } transform.position /= 2.0f; if (_isPinching) { if (pinchDistance > _deactivatePinchDist) { changePinchState(false); return; } } else { if (pinchDistance < _activatePinchDist) { changePinchState(true); } } if (_isPinching) { _pinchPos = transform.position; _pinchRotation = transform.rotation; } GameObject cube = GameObject.Find("Cube"); if (_isPinching) { cube.GetComponent <Renderer>().sharedMaterial.color = Color.red; //cube.GetComponent<Rigidbody>().useGravity = false; } else { cube.GetComponent <Renderer>().material.color = Color.green; } }