Exemple #1
0
 public static void GetBones(Leap.Finger finger, out Leap.Bone metacarpal, out Leap.Bone proximal, out Leap.Bone intermediate, out Leap.Bone distal)
 {
     metacarpal   = finger.Bone((Leap.Bone.BoneType)BoneType.Metacarpal);
     proximal     = finger.Bone((Leap.Bone.BoneType)BoneType.Proximal);
     intermediate = finger.Bone((Leap.Bone.BoneType)BoneType.Intermediate);
     distal       = finger.Bone((Leap.Bone.BoneType)BoneType.Distal);
 }
Exemple #2
0
        private ContactBone initContactBone(Leap.Bone bone, GameObject contactBoneObj, int boneArrayIndex, Collider boneCollider)
        {
            contactBoneObj.layer = _contactBoneParent.gameObject.layer;
            contactBoneObj.transform.localScale = Vector3.one;

            ContactBone contactBone = contactBoneObj.GetComponent <ContactBone>();

            contactBone.collider = boneCollider;
            contactBone.interactionController = this;
            contactBone.interactionHand       = this;
            _contactBones[boneArrayIndex]     = contactBone;

            Transform capsuleTransform = contactBoneObj.transform;

            capsuleTransform.SetParent(_contactBoneParent.transform, false);

            Rigidbody body = contactBoneObj.GetComponent <Rigidbody>();

            body.freezeRotation         = true;
            contactBone.rigidbody       = body;
            body.useGravity             = false;
            body.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; // TODO: Allow different collision detection modes as an optimization.

            body.mass     = 0.1f;
            body.position = bone != null?bone.Center.ToVector3()
                                : _unwarpedHandData.PalmPosition.ToVector3();

            body.rotation = bone != null?bone.Rotation.ToQuaternion()
                                : _unwarpedHandData.Rotation.ToQuaternion();

            contactBone.lastTargetPosition = bone != null?bone.Center.ToVector3()
                                                 : _unwarpedHandData.PalmPosition.ToVector3();

            return(contactBone);
        }
Exemple #3
0
        //public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm, Leap.Finger oFinger)
        //{
        //    double dInterval = this.GetVecterDistance(vecterFingerTip, vecterPalm);
        //    if (Max == 0)
        //    {
        //        Max = dInterval;
        //        return;
        //    }
        //    if (dInterval > Max)
        //    {
        //        Max = dInterval;
        //    }

        //    if (dInterval < Sensitive)
        //    {
        //        Sensitive = dInterval;
        //    }

        //    if (dInterval < Sensitive)
        //        dInterval = Sensitive;
        //    double dPercent = (dInterval - Sensitive) / (this.Max - Sensitive);

        //    double dScale = 1 - 0.5 * dPercent;
        //    this.ScaleX = dScale;
        //    this.ScaleY = dScale;
        //}

        public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm,
                                      Leap.Finger oFinger)
        {
            if (oFinger.Type != Leap.Finger.FingerType.TYPE_THUMB)
            {
                double angle = (180 - (oFinger.Hand.Direction.AngleTo(oFinger.Direction) / Math.PI) * 180);
                if (this.Max == 0)
                {
                    this.Max = angle;
                    return;
                }

                if (angle > this.Max)
                {
                    this.Max = angle;
                }

                if (angle < this.Min)
                {
                    this.Min = angle;
                }

                double dAngleDeviation = 30d * (1 - angle / 180d);
                double dPercent        = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min);
                double dScale          = 1 - 0.5 * dPercent;
                this.ScaleX = dScale;
                this.ScaleY = dScale;
            }
            else if (oFinger.Type == Leap.Finger.FingerType.TYPE_THUMB)
            {
                Leap.Bone bone1 = oFinger.Bone(Leap.Bone.BoneType.TYPE_DISTAL);
                Leap.Bone bone2 = oFinger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL);
                double    angle = (180 - (bone1.Direction.AngleTo(bone2.Direction) / Math.PI) * 180);
                if (this.Max == 0)
                {
                    this.Max = angle;
                    return;
                }

                if (angle > this.Max)
                {
                    this.Max = angle;
                }

                if (angle < this.Min)
                {
                    this.Min = angle;
                }

                double dAngleDeviation = (this.Max - this.Min) * (1 - angle / 180d);
                double dPercent        = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min);
                double dScale          = 1 - 0.5 * dPercent;
                this.ScaleX = dScale;
                this.ScaleY = dScale;
            }
        }
 public Bone(Leap.Bone bone)
 {
     SetType(bone.Type);
     //Center = new Vector(bone.Center);
     Direction = new Vector(bone.Direction);
     IsValid   = bone.IsValid;
     Length    = bone.Length;
     NextJoint = new Vector(bone.NextJoint);
     PrevJoint = new Vector(bone.PrevJoint);
     Width     = bone.Width;
 }
Exemple #5
0
        /// <summary>
        /// Draw some gizmos to help explain the rotation axis that leap uses
        /// </summary>
        /// <param name="bone"></param>
        /// <param name="size"></param>
        private void DrawLeapBoneBasis(Leap.Bone bone, float size)
        {
            Vector3 middle, y, x, z;

            middle = bone.PrevJoint.ToVector3();
            y      = bone.Basis.xBasis.ToVector3();
            x      = bone.Basis.yBasis.ToVector3();
            z      = bone.Basis.zBasis.ToVector3();

            Handles.color = Color.green;
            Handles.DrawLine(middle, middle + y.normalized * size);
            Handles.color = Color.red;
            Handles.DrawLine(middle, middle + x.normalized * size);
            Handles.color = Color.blue;
            Handles.DrawLine(middle, middle + z.normalized * size);
            Handles.color = leapHandDebugCol;
        }
Exemple #6
0
 public static BoneType GetBoneType(Leap.Bone bone)
 {
     return((BoneType)bone.Type);
 }