Example #1
0
 static void FillHandRotation(Leap.Hand f_hand, ref UnityEngine.Quaternion f_rot)
 {
     f_rot.x = f_hand.Rotation.x;
     f_rot.y = f_hand.Rotation.y;
     f_rot.z = f_hand.Rotation.z;
     f_rot.w = f_hand.Rotation.w;
 }
        public override bool IsFingerBent(Hand handId, Finger fingerId)
        {
#if VRTK_DEFINE_SDK_LEAP_MOTION
            Leap.Hand currentHand = GetLeapHand(handId);
            if (currentHand == null)
            {
                return(false);
            }

            Leap.Finger.FingerType leapFingerType = VirtuosoFingerToLeapFinger(fingerId);

            foreach (Leap.Finger finger in currentHand.Fingers)
            {
                if (finger.Type == leapFingerType)
                {
                    return(!finger.IsExtended);
                }
            }

            // finger not found; therefor no
            return(false);
#else
            throw new System.NotImplementedException();
#endif
        }
        /// <summary>
        /// Retrieves the hand specified by the Virtuoso Hand enum.
        /// This will return null if the specified hand is not available.
        /// </summary>
        protected Leap.Hand GetLeapHand(Hand handId)
        {
            if (leapServiceProvider == null)
            {
                return(null);
            }

            Leap.Frame currentFrame = leapServiceProvider.CurrentFrame;
            Leap.Hand  currentHand  = null;

            foreach (Leap.Hand hand in currentFrame.Hands)
            {
                if (hand.IsLeft && handId == Hand.Left)
                {
                    currentHand = hand;
                    break;
                }
                else if (hand.IsRight && handId == Hand.Right)
                {
                    currentHand = hand;
                    break;
                }
            }

            return(currentHand);
        }
Example #4
0
        public Hand(Leap.Hand hand, Frame frame)
        {
            IsTraveled = false;
            Frame      = frame;
            Id         = hand.Id;
            PalmWidth  = hand.PalmWidth;
            IsLeft     = hand.IsLeft;
            IsRight    = hand.IsRight;
            Pointables = new List <Pointable>();
            Fingers    = new List <Finger>();
            Tools      = new List <Tool>();
            foreach (Leap.Finger lf in hand.Fingers)
            {
                Finger f = new Finger(lf, frame, this);
                Fingers.Add(f);
                Pointables.Add(f);
                switch (f.Type)
                {
                case Finger.FingerType.THUMB:
                    Thumb = f;
                    break;

                case Finger.FingerType.INDEX:
                    Index = f;
                    break;

                case Finger.FingerType.MIDDLE:
                    Middle = f;
                    break;

                case Finger.FingerType.RING:
                    Ring = f;
                    break;

                case Finger.FingerType.PINKY:
                    Pinky = f;
                    break;

                default:
                    throw new Exception("Unknow finger");
                }
            }

            foreach (Leap.Tool lt in hand.Tools)
            {
                Tool t = new Tool(lt, frame, this);
                Tools.Add(t);
                Pointables.Add(t);
            }
            PalmPosition           = new Vector(hand.PalmPosition);
            PalmVelocity           = new Vector(hand.PalmVelocity);
            PalmNormal             = new Vector(hand.PalmNormal);
            SphereCenter           = new Vector(hand.SphereCenter);
            Direction              = new Vector(hand.Direction);
            SphereRadius           = hand.SphereRadius;
            StabilizedPalmPosition = new Vector(hand.StabilizedPalmPosition);
            TimeVisible            = hand.TimeVisible;
            GrabStrength           = hand.GrabStrength;
            PinchStrength          = hand.PinchStrength;
        }
Example #5
0
        public Hand(Leap.Hand hand, Frame frame)
        {
            IsTraveled = false;

            Frame      = frame;
            Id         = hand.Id;
            Pointables = new List <Pointable>();
            Fingers    = new List <Finger>();
            Tools      = new List <Tool>();
            foreach (Leap.Finger lf in hand.Fingers)
            {
                Finger f = new Finger(lf, frame, this);
                Fingers.Add(f);
                Pointables.Add(f);
            }
            foreach (Leap.Tool lt in hand.Tools)
            {
                Tool t = new Tool(lt, frame, this);
                Tools.Add(t);
                Pointables.Add(t);
            }
            PalmPosition           = new Vector(hand.PalmPosition);
            PalmVelocity           = new Vector(hand.PalmVelocity);
            PalmNormal             = new Vector(hand.PalmNormal);
            SphereCenter           = new Vector(hand.SphereCenter);
            Direction              = new Vector(hand.Direction);
            SphereRadius           = hand.SphereRadius;
            StabilizedPalmPosition = new Vector(hand.StabilizedPalmPosition);
            TimeVisible            = hand.TimeVisible;
        }
Example #6
0
        public override HandRepresentation MakeHandRepresentation(Leap.Hand hand, ModelType modelType)
        {
            HandRepresentation handRep = null;

            for (int i = 0; i < ModelPool.Count; i++)
            {
                IHandModel model = ModelPool[i];

                bool isCorrectHandedness;
                if (model.Handedness == Chirality.Either)
                {
                    isCorrectHandedness = true;
                }
                else
                {
                    Chirality handChirality = hand.IsRight ? Chirality.Right : Chirality.Left;
                    isCorrectHandedness = model.Handedness == handChirality;
                }

                bool isCorrectModelType;
                isCorrectModelType = model.HandModelType == modelType;

                if (isCorrectHandedness && isCorrectModelType)
                {
                    ModelPool.RemoveAt(i);
                    handRep = new HandProxy(this, model, hand);
                    break;
                }
            }
            return(handRep);
        }
Example #7
0
        public override void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            if (Application.isPlaying)
            {
                base.OnDrawRuntimeGizmos(drawer);
            }
            else
            {
                var provider = leapProvider;
                if (provider == null)
                {
                    provider = Hands.Provider;
                }

                if (_testHand == null && provider != null)
                {
                    _testHand = TestHandFactory.MakeTestHand(0, 0, this.isLeft)
                                .TransformedCopy(UnityMatrixExtension.GetLeapMatrix(provider.transform));
                }

                // Hover Point
                _unwarpedHandData = _testHand; // hoverPoint is driven by this backing variable
                drawHoverPoint(drawer, hoverPoint);

                // Primary Hover Points
                for (int i = 0; i < NUM_FINGERS; i++)
                {
                    if (enabledPrimaryHoverFingertips[i])
                    {
                        drawPrimaryHoverPoint(drawer, _testHand.Fingers[i].TipPosition.ToVector3());
                    }
                }
            }
        }
Example #8
0
        public override void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            if (Application.isPlaying)
            {
                base.OnDrawRuntimeGizmos(drawer);
            }
            else
            {
                var provider = gestureProvider;

                if (_testHand == null && provider != null)
                {
                    _testHand = _hand;
                }

                // Hover Point
                _unwarpedHandData = _testHand; // hoverPoint is driven by this backing variable
                drawHoverPoint(drawer, hoverPoint);

                // Primary Hover Points
                for (int i = 0; i < NUM_FINGERS; i++)
                {
                    if (enabledPrimaryHoverFingertips[i])
                    {
                        drawPrimaryHoverPoint(drawer, _testHand.Fingers[i].TipPosition.ToVector3());
                    }
                }
            }
        }
Example #9
0
        static void FillHandBends(Leap.Hand f_hand, ref float[] f_bends)
        {
            foreach (var l_finger in f_hand.Fingers)
            {
                int l_startBoneID = ((l_finger.Type == Leap.Finger.FingerType.TYPE_THUMB) ? 1 : 0);
                UnityEngine.Vector3 l_prevDirection = new UnityEngine.Vector3(0f, 0f, 0f);

                for (int i = l_startBoneID; i < 4; i++)
                {
                    var l_bone = l_finger.Bone((Leap.Bone.BoneType)i);
                    if (l_bone != null)
                    {
                        var l_leapDir = l_bone.NextJoint - l_bone.PrevJoint;
                        var l_dir     = new UnityEngine.Vector3(l_leapDir.x, l_leapDir.y, l_leapDir.z);
                        l_dir.Normalize();
                        if (i > l_startBoneID)
                        {
                            f_bends[(int)l_finger.Type] += UnityEngine.Mathf.Acos(UnityEngine.Vector3.Dot(l_dir, l_prevDirection));
                        }
                        l_prevDirection = l_dir;
                    }
                }

                f_bends[(int)l_finger.Type] = NormalizeRange(f_bends[(int)l_finger.Type], (l_finger.Type == Leap.Finger.FingerType.TYPE_THUMB) ? 0f : (float)System.Math.PI * 0.125f, (l_finger.Type == Leap.Finger.FingerType.TYPE_THUMB) ? (float)System.Math.PI * 0.25f : (float)System.Math.PI);
            }
        }
Example #10
0
 public HandGestureInfo(int i = 0)
 {
     hand         = null;
     isPalmOpen   = false;
     isFist       = false;
     isThumbsUp   = false;
     isThumbsDown = false;
 }
        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));
            }
        }
Example #12
0
        private static bool handsTogether(Leap.Hand hand1, Leap.Hand hand2)
        {
            float xdiff = Math.Abs(hand1.PalmPosition.x - hand2.PalmPosition.x),
                  ydiff = Math.Abs(hand1.PalmPosition.y - hand2.PalmPosition.y),
                  zdiff = Math.Abs(hand1.PalmPosition.z - hand2.PalmPosition.z);

            if ((xdiff + ydiff + zdiff) < 400)
            {
                return(true);
            }

            return(false);
        }
Example #13
0
        static void FillHandSpreads(Leap.Hand f_hand, ref float[] f_bends, ref float[] f_spreads)
        {
            UnityEngine.Quaternion l_palmRotation = new UnityEngine.Quaternion(f_hand.Rotation.x, f_hand.Rotation.y, f_hand.Rotation.z, f_hand.Rotation.w);
            UnityEngine.Vector3    l_sideDir      = l_palmRotation * (f_hand.IsLeft ? gc_axisX : gc_axisXN);
            UnityEngine.Vector3    l_handPos      = new UnityEngine.Vector3(f_hand.PalmPosition.x, f_hand.PalmPosition.y, f_hand.PalmPosition.z);

            foreach (var l_finger in f_hand.Fingers)
            {
                var l_bone = l_finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL);
                if (l_bone != null)
                {
                    var l_leapDir = l_bone.NextJoint - l_bone.PrevJoint;
                    var l_dir     = new UnityEngine.Vector3(l_leapDir.x, l_leapDir.y, l_leapDir.z);
                    l_dir.Normalize();

                    if (l_finger.Type != Leap.Finger.FingerType.TYPE_THUMB)
                    {
                        f_spreads[(int)l_finger.Type] = UnityEngine.Vector3.Dot(l_dir, l_sideDir) * 2f;
                    }
                    else
                    {
                        UnityEngine.Vector3 l_boneNext = new UnityEngine.Vector3(l_bone.NextJoint.x, l_bone.NextJoint.y, l_bone.NextJoint.z);
                        f_spreads[(int)l_finger.Type] = 1f - NormalizeRange(UnityEngine.Vector3.Distance(l_boneNext, l_handPos), 40f, 70f);
                    }

                    switch (l_finger.Type)
                    {
                    case Leap.Finger.FingerType.TYPE_INDEX:
                        f_spreads[(int)l_finger.Type] += 0.25f;
                        break;

                    case Leap.Finger.FingerType.TYPE_MIDDLE:
                        f_spreads[(int)l_finger.Type] = f_spreads[(int)l_finger.Type] * 2.5f + 0.5f;
                        break;

                    case Leap.Finger.FingerType.TYPE_RING:
                        f_spreads[(int)l_finger.Type] = -f_spreads[(int)l_finger.Type] * 3f - 0.75f;
                        break;

                    case Leap.Finger.FingerType.TYPE_PINKY:
                        f_spreads[(int)l_finger.Type] = -f_spreads[(int)l_finger.Type] - 0.15f;
                        break;
                    }

                    if (f_bends[(int)l_finger.Type] > 0.5f)
                    {
                        f_spreads[(int)l_finger.Type] = UnityEngine.Mathf.Lerp(f_spreads[(int)l_finger.Type], 0f, (f_bends[(int)l_finger.Type] - 0.5f) * 2f);
                    }
                }
            }
        }
        public override bool IsHandPinched(Hand handId)
        {
#if VRTK_DEFINE_SDK_LEAP_MOTION
            Leap.Hand currentHand = GetLeapHand(handId);
            if (currentHand == null)
            {
                return(false);
            }

            return(currentHand.PinchStrength >= PINCH_STRENGTH_THRESHOLD);
#else
            throw new System.NotImplementedException();
#endif
        }
        public override bool IsHandDetected(Hand handId)
        {
#if VRTK_DEFINE_SDK_LEAP_MOTION
            Leap.Hand targetHand = GetLeapHand(handId);
            if (targetHand == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
#else
            return(false);
#endif
        }
        public override Vector3 GetHandNormal(Hand handId)
        {
#if VRTK_DEFINE_SDK_LEAP_MOTION
            Leap.Hand targetHand = GetLeapHand(handId);
            if (targetHand == null)
            {
                return(Vector3.zero);
            }
            else
            {
                return(LeapToUnityNormal(targetHand.PalmNormal));
            }
#else
            return(Vector3.zero);
#endif
        }
Example #17
0
        public void SetTransformUsingHand(Leap.Hand hand)
        {
            if (hand == null)
            {
                //Debug.LogError("Unable to set transform with a null hand.", this.gameObject);
                return;
            }

            Vector3    position = Vector3.zero;
            Quaternion rotation = Quaternion.identity;

            GetLeapHandPointData(hand, this.attachmentPoint, out position, out rotation);

            this.transform.position = position;
            this.transform.rotation = rotation;
        }
Example #18
0
        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();
        }
Example #19
0
 void MoveHands(Leap.Frame frame)
 {
     for (int i = 0; i < frame.Hands.Count; i++)
     {
         Leap.Hand hand = frame.Hands[i];
         if (i < hands.Length)
         {
             Point position = GetCanvasPosition(hand.PalmPosition);
             Canvas.SetLeft(hands[i], position.X);
             Canvas.SetTop(hands[i], position.Y);
             float scale       = Math.Abs((backMostZ - hand.PalmPosition.z) / (backMostZ - forwardMostZ));
             float newDiameter = 100 * scale + 40;
             hands[i].Width  = newDiameter;
             hands[i].Height = newDiameter;
         }
         //foreach (Leap.Finger finger in hand.Fingers)
         //{
         //	AnalyzeBounds(finger.TipPosition);
         //}
     }
 }
Example #20
0
        public bool isFist(Leap.Hand h)
        {
            if (h == null)
            {
                return(false);
            }
            int badfinger = 0;

            foreach (Leap.Finger fig in h.Fingers)
            {
                if (!fig.IsExtended)
                {
                    badfinger++;
                }
            }
            if (badfinger > 1)
            {
                return(true);
            }
            return(false);
        }
Example #21
0
        private void OnUpdateFrame(Leap.Frame frame)
        {
            if (frame == null)
            {
                return;
            }

            humanoid.leftHandTarget.leap.SetHand(null);
            humanoid.rightHandTarget.leap.SetHand(null);

            for (int i = 0; i < frame.Hands.Count; i++)
            {
                Leap.Hand curHand = frame.Hands[i];
                if (curHand.IsLeft)
                {
                    humanoid.leftHandTarget.leap.SetHand(curHand);
                }
                if (curHand.IsRight)
                {
                    humanoid.rightHandTarget.leap.SetHand(curHand);
                }
            }
        }
Example #22
0
        protected override void UpdateHandStatus()
        {
            IsActive = m_leapRiggedHand.IsTracked;
            Leap.Hand hand = m_leapRiggedHand.GetLeapHand();

            if (!IsActive || hand == null)
            {
                return;
            }

            Vector3 indexTip  = hand.Fingers[1].TipPosition.ToVector3();
            Vector3 middleTip = hand.Fingers[2].TipPosition.ToVector3();

            if (Vector3.Distance(indexTip, middleTip) < 0.05f)
            {
                InteractionPointMode = InteractionPointModes.Palm;
                Position             = hand.PalmPosition.ToVector3();
            }
            else
            {
                InteractionPointMode = InteractionPointModes.Index;
                Position             = hand.Fingers[1].TipPosition.ToVector3();
            }
        }
Example #23
0
 public void connectToHands()
 {
     if (controller.Frame().Hands.Count == 1)
     {
         Leap.Hand temp = controller.Frame().Hands[0];
         if (temp.IsLeft)
         {
             lefthand  = temp;
             righthand = null;
         }
         else
         {
             righthand = temp;
             lefthand  = null;
         }
     }
     else if (controller.Frame().Hands.Count == 2)
     {
         Leap.Hand temp = controller.Frame().Hands[0];
         if (temp.IsLeft)
         {
             lefthand  = temp;
             righthand = controller.Frame().Hands[1];
         }
         else
         {
             righthand = temp;
             lefthand  = controller.Frame().Hands[1];
         }
     }
     else
     {
         lefthand  = null;
         righthand = null;
     }
 }
Example #24
0
        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();
            }
        }
Example #25
0
        public static void GetLeapHandPointData(Leap.Hand hand, AttachmentPointFlags singlePoint, out Vector3 position, out Quaternion rotation)
        {
            position = Vector3.zero;
            rotation = Quaternion.identity;

            if (singlePoint != AttachmentPointFlags.None && !singlePoint.IsSinglePoint())
            {
                Debug.LogError("Cannot get attachment point data for an AttachmentPointFlags argument consisting of more than one set flag.");
                return;
            }

            switch (singlePoint)
            {
            case AttachmentPointFlags.None:
                return;

            case AttachmentPointFlags.Wrist:
                position = hand.WristPosition.ToVector3();
                rotation = hand.Arm.Basis.rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.Palm:
                position = hand.PalmPosition.ToVector3();
                rotation = hand.Basis.rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.ThumbProximalJoint:
                position = hand.Fingers[0].bones[1].NextJoint.ToVector3();
                rotation = hand.Fingers[0].bones[2].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.ThumbDistalJoint:
                position = hand.Fingers[0].bones[2].NextJoint.ToVector3();
                rotation = hand.Fingers[0].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.ThumbTip:
                position = hand.Fingers[0].bones[3].NextJoint.ToVector3();
                rotation = hand.Fingers[0].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.IndexKnuckle:
                position = hand.Fingers[1].bones[0].NextJoint.ToVector3();
                rotation = hand.Fingers[1].bones[1].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.IndexMiddleJoint:
                position = hand.Fingers[1].bones[1].NextJoint.ToVector3();
                rotation = hand.Fingers[1].bones[2].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.IndexDistalJoint:
                position = hand.Fingers[1].bones[2].NextJoint.ToVector3();
                rotation = hand.Fingers[1].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.IndexTip:
                position = hand.Fingers[1].bones[3].NextJoint.ToVector3();
                rotation = hand.Fingers[1].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.MiddleKnuckle:
                position = hand.Fingers[2].bones[0].NextJoint.ToVector3();
                rotation = hand.Fingers[2].bones[1].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.MiddleMiddleJoint:
                position = hand.Fingers[2].bones[1].NextJoint.ToVector3();
                rotation = hand.Fingers[2].bones[2].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.MiddleDistalJoint:
                position = hand.Fingers[2].bones[2].NextJoint.ToVector3();
                rotation = hand.Fingers[2].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.MiddleTip:
                position = hand.Fingers[2].bones[3].NextJoint.ToVector3();
                rotation = hand.Fingers[2].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.RingKnuckle:
                position = hand.Fingers[3].bones[0].NextJoint.ToVector3();
                rotation = hand.Fingers[3].bones[1].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.RingMiddleJoint:
                position = hand.Fingers[3].bones[1].NextJoint.ToVector3();
                rotation = hand.Fingers[3].bones[2].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.RingDistalJoint:
                position = hand.Fingers[3].bones[2].NextJoint.ToVector3();
                rotation = hand.Fingers[3].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.RingTip:
                position = hand.Fingers[3].bones[3].NextJoint.ToVector3();
                rotation = hand.Fingers[3].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.PinkyKnuckle:
                position = hand.Fingers[4].bones[0].NextJoint.ToVector3();
                rotation = hand.Fingers[4].bones[1].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.PinkyMiddleJoint:
                position = hand.Fingers[4].bones[1].NextJoint.ToVector3();
                rotation = hand.Fingers[4].bones[2].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.PinkyDistalJoint:
                position = hand.Fingers[4].bones[2].NextJoint.ToVector3();
                rotation = hand.Fingers[4].bones[3].Rotation.ToQuaternion();
                break;

            case AttachmentPointFlags.PinkyTip:
                position = hand.Fingers[4].bones[3].NextJoint.ToVector3();
                rotation = hand.Fingers[4].bones[3].Rotation.ToQuaternion();
                break;
            }
        }
Example #26
0
 static void FillHandPosition(Leap.Hand f_hand, ref UnityEngine.Vector3 f_pos)
 {
     f_pos.x = f_hand.PalmPosition.x;
     f_pos.y = f_hand.PalmPosition.y;
     f_pos.z = f_hand.PalmPosition.z;
 }
Example #27
0
 // Improved values.
 public static EulerAngles GetEulerAngles(this Leap.Hand h) =>
 Rotation3DHelper.ToEulerAngles(-h.Direction.ToVector3D(), -h.PalmNormal.ToVector3D());
Example #28
0
        //-------------------------------------------------
        void Update()
        {
            // check finger state
            foreach (RiggedHand h in hands)
            {
                Leap.Hand leapHand = h.GetLeapHand();
                if (leapHand == null)
                {
                    continue;
                }
                Leap.Finger index = leapHand.GetIndex();
                Leap.Finger thumb = leapHand.GetThumb();
                if (index.TipPosition.DistanceTo(thumb.TipPosition) < 0.03)
                {
                    if (fingerState == FingerState.PRESSED)
                    {
                        fingerState = FingerState.DOWN;
                    }
                    else if (fingerState != FingerState.DOWN)
                    {
                        fingerState = FingerState.PRESSED;
                    }
                }
                else
                {
                    if (fingerState == FingerState.RELEASED)
                    {
                        fingerState = FingerState.NONE;
                    }
                    else if (fingerState != FingerState.NONE)
                    {
                        fingerState = FingerState.RELEASED;
                    }
                }
            }

            //
            Hand oldPointerHand = pointerHand;
            Hand newPointerHand = null;

            foreach (Hand hand in player.hands)
            {
                if (visible)
                {
                    if (WasTeleportButtonReleased(hand))
                    {
                        if (pointerHand == hand)                           //This is the pointer hand
                        {
                            TryTeleportPlayer();
                        }
                    }
                }

                if (WasTeleportButtonPressed(hand))
                {
                    newPointerHand = hand;
                }
            }

            //If something is attached to the hand that is preventing teleport
            if (allowTeleportWhileAttached && !allowTeleportWhileAttached.teleportAllowed)
            {
                HidePointer();
            }
            else
            {
                if (!visible && newPointerHand != null)
                {
                    //Begin showing the pointer
                    ShowPointer(newPointerHand, oldPointerHand);
                }
                else if (visible)
                {
                    if (newPointerHand == null && !IsTeleportButtonDown(pointerHand))
                    {
                        //Hide the pointer
                        HidePointer();
                    }
                    else if (newPointerHand != null)
                    {
                        //Move the pointer to a new hand
                        ShowPointer(newPointerHand, oldPointerHand);
                    }
                }
            }

            if (visible)
            {
                UpdatePointer();

                if (meshFading)
                {
                    UpdateTeleportColors();
                }

                if (onActivateObjectTransform.gameObject.activeSelf && Time.time - pointerShowStartTime > activateObjectTime)
                {
                    onActivateObjectTransform.gameObject.SetActive(false);
                }
            }
            else
            {
                if (onDeactivateObjectTransform.gameObject.activeSelf && Time.time - pointerHideStartTime > deactivateObjectTime)
                {
                    onDeactivateObjectTransform.gameObject.SetActive(false);
                }
            }
        }
Example #29
0
 public override void UpdateRepresentation(Leap.Hand hand, ModelType modelType)
 {
     handModel.SetLeapHand(hand);
     handModel.UpdateHand();
 }
 /// <summary>
 /// Notifies the representation that a hand information update is available
 /// </summary>
 /// <param name="hand">The current Leap.Hand</param>
 public abstract void UpdateRepresentation(Leap.Hand hand, ModelType modelType);