private void setFingerBasePositions_Relative(Hand hand)
        {
            Leap.Finger index  = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_INDEX).FirstOrDefault();
            Leap.Finger middle = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_MIDDLE).FirstOrDefault();
            Leap.Finger ring   = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_RING).FirstOrDefault();
            Leap.Finger pinky  = hand.Fingers.Where(f => f.Type == Finger.FingerType.TYPE_PINKY).FirstOrDefault();

            IndexBasePos_Relative  = new Vec3(HandTransform.TransformPoint(index.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_INDEX];
            MiddleBasePos_Relative = new Vec3(HandTransform.TransformPoint(middle.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_MIDDLE];
            RingBasePos_Relative   = new Vec3(HandTransform.TransformPoint(ring.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_RING];
            PinkyBasePos_Relative  = new Vec3(HandTransform.TransformPoint(pinky.Bone(Bone.BoneType.TYPE_METACARPAL).PrevJoint)) / FingerLengths[Finger.FingerType.TYPE_PINKY];
        }
 private void setFingerJointPositions_Relative(Hand hand)
 {
     FingerJointPositions_Relative = new Dictionary <Finger.FingerType, Dictionary <Finger.FingerJoint, Vec3> >();
     foreach (var finger in hand.Fingers)
     {
         FingerJointPositions_Relative.Add(finger.Type, new Dictionary <Finger.FingerJoint, Vec3>());
         foreach (var jointType in (Finger.FingerJoint[])System.Enum.GetValues(typeof(Finger.FingerJoint)))
         {
             Vec3 relativePoint = new Vec3(HandTransform.TransformPoint(finger.JointPosition(jointType))) / FingerLengths[finger.Type];
             FingerJointPositions_Relative[finger.Type].Add(jointType, relativePoint);
         }
     }
 }
        public SGInstanceSingleHand(Hand hand)
        {
            HandTransform = getHandTransform(hand);

            IsLeft        = hand.IsLeft;
            IsRight       = hand.IsRight;
            PalmPosition  = new Vec3(hand.PalmPosition);            // Do not HandTransform.TransformPoint()
            PalmNormal    = new Vec3(hand.PalmNormal);
            HandDirection = new Vec3(hand.Direction);
            ArmX          = new Vec3(hand.Arm.Basis.xBasis);
            ArmY          = new Vec3(hand.Arm.Basis.yBasis);
            ArmZ          = new Vec3(hand.Arm.Basis.zBasis);

            // Normalize these angle values. (They all range between -PI and PI).
            //Yaw = hand.PalmNormal.Yaw;
            //Pitch = hand.PalmNormal.Pitch;
            //Roll = hand.PalmNormal.Roll;
            Yaw   = hand.Direction.Yaw;
            Pitch = hand.Direction.Pitch;
            Roll  = hand.PalmNormal.Roll;

            // World coordinates
            WristPos_World      = new Vec3(hand.WristPosition);
            ElbowPos_World      = new Vec3(hand.Arm.ElbowPosition);
            ForearmCenter_World = new Vec3(hand.Arm.Center);
            setFingerJointPositions_World(hand);
            setFingerBasePositions_World(hand);

            // Relative coordinates
            WristPos_Relative      = new Vec3(hand.WristPosition);
            ElbowPos_Relative      = new Vec3(hand.Arm.ElbowPosition);
            ForearmCenter_Relative = new Vec3(hand.Arm.Center);

            // NOTE: FingerLengths and relative finger positions must be calculated after world coordinates.
            FingerLengths = GetFingerLengths();

            setFingerJointPositions_Relative(hand);
            setFingerBasePositions_Relative(hand);

            PalmSphereRadius = hand.SphereRadius / FingerLengths[Finger.FingerType.TYPE_MIDDLE];
            PalmSphereCenter = new Vec3(HandTransform.TransformPoint(hand.SphereCenter)) / FingerLengths[Finger.FingerType.TYPE_MIDDLE];

            buildFingerFeatures(hand);
        }