IEnumerator FingerPointingWatcher() { Hand hand; Vector3 fingerDirection; Vector3 targetDirection; while (true) { if (handModel != null) { hand = handModel.GetLeapHand(); if (hand != null) { targetDirection = Vector3.forward; fingerDirection = hand.Fingers[2].Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); float angleTo = Vector3.Angle(fingerDirection, targetDirection); if (handModel.IsTracked && angleTo <= handOnAngle) { isFingerPointingUp = true; } else if (!handModel.IsTracked || angleTo >= handOffAngle) { isFingerPointingUp = false; } } } yield return new WaitForSeconds(period); } }
private IEnumerator PalmWatcher() { Hand hand; Vector3 normal; bool isPalmUp = false; float angleToDown; float angleToUp; while (true) { if (handModel != null) { hand = handModel.GetLeapHand(); if (hand != null) { normal = hand.PalmNormal.ToVector3(); angleToDown = Vector3.Angle(normal, Vector3.down); angleToUp = Vector3.Angle(normal, Vector3.up); if (angleToDown <= onAngleDown) { isPalmDown = true; } else if (angleToDown > offAngleDown) { if (isPalmDown) { isPalmFlipping = true; } isPalmDown = false; } if (isPalmFlipping) { flipTime += 1 * Time.deltaTime; normal = hand.PalmNormal.ToVector3(); if (angleToUp <= onAngleUp && flipTime <= maximumFlipTime) { Activate(); flipTime = 0; isPalmFlipping = false; isPalmUp = true; Debug.Log("I just flipped palm"); } } if (angleToUp > offAngleUp && isPalmUp) { Deactivate(); isPalmUp = false; Debug.Log("I removed palm from up-position"); } if (flipTime >= maximumFlipTime) { flipTime = 0; isPalmFlipping = false; } } } yield return(new WaitForSeconds(period)); } }
internal bool IsThereMovement() { if (Mathf.Abs(HandModel.GetLeapHand().PalmVelocity.Magnitude) > 0.2f) { return(true); } return(false); }
void Update() { _lastHand = _handModel.GetLeapHand(); if (_lastHand == null || !_handModel.IsTracked) { return; } if (_pinchDetector.IsPinching) { return; } Vector3 palmNorm = _lastHand.PalmNormal.ToVector3(); if (Vector3.Angle(palmNorm, Camera.main.transform.position - _lastHand.PalmPosition.ToVector3()) < _angleThreshold) { isFacingCam = true; } else { isFacingCam = false; } didChanged = (facingCamLastFrame == IsFacingCam) ? false : true; if (didChanged) { HandFacingCamEvent.Invoke(); } facingCamLastFrame = IsFacingCam; }
void Update() { /* * camera.transform.Rotate(new Vector3(-Input.GetAxis("Mouse Y"), 0, 0) * Time.deltaTime * 100.0f); * moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); * moveDirection = transform.TransformDirection(moveDirection); * moveDirection *= 6.0f; * camera.transform.Translate(moveDirection * Time.deltaTime); * * if (Input.GetKeyDown("c")) * { * SwordProximityActive(); * } */ if (freezeMovement || !shouldGuestMove) { return; } if (RightHandModel.IsTracked) { hand = RightHandModel.GetLeapHand(); } else { hand = null; } if (hand != null) { Vector3 handVector = (hand.Fingers [1].Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3()); camera.transform.Translate(new Vector3(handVector.x / speedDivider, handVector.y / speedDivider, handVector.z / speedDivider)); } }
IEnumerator graspWatcher() { bool graspingState = false; IInteractionBehaviour graspedObject; int handId = 0; while (true) { if (interactionManager != null) { Leap.Hand hand = HandModel.GetLeapHand(); if (hand != null) { handId = hand.Id; } else { handId = 0; } interactionManager.TryGetGraspedObject(handId, out graspedObject); graspingState = false; if (graspedObject != null) { if ((AnyInteractionObject || (TagName != "" && graspedObject.gameObject.tag == TagName))) { graspingState = true; } else { for (int o = 0; o < TargetObjects.Length; o++) { if (TargetObjects[o] == graspedObject) { graspingState = true; break; } } } } if (graspingState) { if (_currentObj != graspedObject) { _currentObj = graspedObject; OnGrasp.Invoke(_currentObj); } Activate(); } else { _currentObj = null; 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.Rotation(); 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; } }
void Update() { Hand hand = HandModel.GetLeapHand(); if (hand != null) { this.gameObject.transform.position = hand.PalmPosition.ToVector3(); this.gameObject.transform.rotation = Quaternion.LookRotation(hand.PalmNormal.ToVector3(), hand.Direction.ToVector3()); //Default Code } }
private string GetRotationAngle() { Hand hand = HandModel.GetLeapHand(); var rot = hand.Rotation; Buffer.RemoveAt(0); Buffer.Add(rot); rot = new LeapQuaternion( Buffer.Average(elem => elem.w), Buffer.Average(elem => elem.x), Buffer.Average(elem => elem.y), Buffer.Average(elem => elem.z)); int decimals = 4; return(Math.Round(rot.w, decimals) + " — " + Math.Round(rot.x, decimals) + " — " + Math.Round(rot.y, decimals) + " — " + Math.Round(rot.z, decimals)); }
void Update() { Hand hand = HandModel.GetLeapHand(); if (hand != null) { /* * This line of codes are used for determining angle between hand and object * The objects rotation will follow the hand. * */ Vector3 objectPos = transform.position; Vector3 handPos = hand.PalmPosition.ToVector3(); if (rotateOnX) { float newAngle = Mathf.Atan2(objectPos.z - handPos.z, objectPos.y - handPos.y) * Mathf.Rad2Deg; rotationAmount += Mathf.DeltaAngle(angle, newAngle); angle = newAngle; transform.rotation = Quaternion.Euler(new Vector3(newAngle, transform.rotation.y, transform.rotation.z)); } else if (rotateOnY) { float newAngle = Mathf.Atan2(objectPos.x - handPos.x, objectPos.z - handPos.z) * Mathf.Rad2Deg; rotationAmount -= Mathf.DeltaAngle(angle, newAngle); angle = newAngle; transform.rotation = Quaternion.Euler(new Vector3(transform.rotation.x, newAngle, transform.rotation.z)); } else if (rotateOnZ) { float newAngle = Mathf.Atan2(objectPos.y - handPos.y, objectPos.x - handPos.x) * Mathf.Rad2Deg; rotationAmount -= Mathf.DeltaAngle(angle, newAngle); angle = newAngle; transform.rotation = Quaternion.Euler(new Vector3(transform.rotation.x, transform.rotation.y, newAngle)); } // Determines if the tool has spun from the given amount if ((rotationAmount / 360) >= spinsNeeded && this.gameObject.transform.parent != null) { rotationAmount = 0; angle = 0.0f; ClockWiseSpinDone.Invoke(); this.enabled = false; } else if ((rotationAmount / 360) <= -spinsNeeded && this.gameObject.transform.parent != null) { rotationAmount = 0; angle = 0.0f; CounterClockWiseSpinDone.Invoke(); this.enabled = false; } } }
IEnumerator FollowHand(IHandModel hand) { for (;;) { Vector3 palmPosition = hand.GetLeapHand().PalmPosition.ToVector3(); rb.AddForce((palmPosition - t.position) * force, ForceMode.Acceleration); if (rb.velocity.magnitude > maxVelocity) { rb.velocity = rb.velocity.normalized * maxVelocity; } yield return(null); } }
public HandProxy(HandPool parent, IHandModel handModel, Leap.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 HandProxy(HandPool parent, IHandModel handModel, Leap.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); } handFinishBehavior = handModel.GetComponent<HandTransitionBehavior>(); if (handFinishBehavior) { handFinishBehavior.Reset(); } }
protected virtual void Update() { _didFistClosedChange = false; _didThumbsUpChange = false; Hand hand = _handModel.GetLeapHand(); if (hand == null || !_handModel.IsTracked) { changeFistClosedState(false); changeThumbsUpState(false); return; } int extendedFingers = 0; for (int i = 0; i < hand.Fingers.Count; i++) { if (hand.Fingers[i].IsExtended) { extendedFingers++; } } if (extendedFingers == 0) { changeFistClosedState(true); changeThumbsUpState(false); } else if (extendedFingers == 1 && hand.Fingers[0].IsExtended) { changeFistClosedState(false); changeThumbsUpState(true); } else { changeFistClosedState(false); changeThumbsUpState(false); } }
void Update() { Hand MainHand = HandModel.GetLeapHand(); if (MainHand != null) { float distance = (transform.position - MainHand.PalmPosition.ToVector3()).sqrMagnitude; if (distance <= HoverDistance) { TextBox.text = ObjectName; } else { TextBox.text = ""; } } else { TextBox.text = ""; } }
public HandProxy(HandPool parent, IHandModel handModel, Leap.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); } handFinishBehavior = handModel.GetComponent <HandTransitionBehavior>(); if (handFinishBehavior) { handFinishBehavior.Reset(); } }
private static Leap.Finger GetFinger(IHandModel model, int i) { return(model.GetLeapHand().Fingers[i]); }
public static float GetFingerDirection(IHandModel model, int i) { return((Quaternion.Inverse(model.GetLeapHand().Rotation.ToQuaternion()) * GetFinger(model, i).Direction.ToVector3()).z); }