Exemple #1
0
        public SGInstance(Frame frame)
        {
            Hands = new List <SGInstanceSingleHand>();
            foreach (var leapHand in frame.Hands)
            {
                var hand = new SGInstanceSingleHand(leapHand);
                if (leapHand.IsLeft)
                {
                    LeftHand = hand;
                }
                else
                {
                    RightHand = hand;
                }
                Hands.Add(hand);
            }

            FeatureVector = buildFeatureVector();

            Features = new Dictionary <FeatureName, Feature>();
            foreach (var feature in FeatureVector)
            {
                Features.Add(feature.Name, feature);
            }

            HandConfiguration = getHandConfiguration(Hands);
        }
Exemple #2
0
        // Diagram of hand: https://blog.leapmotion.com/wp-content/uploads/2014/05/boneapi1.png
        public void DrawHand(SGInstanceSingleHand hand, bool showArms, float opacity = 1)
        {
            // Draw wrist position
            DrawSphere(hand.WristPos_World, Constants.WristSphereRadius, _boneColors[Constants.BoneNames.Wrist], opacity);
            // Draw palm position
            DrawSphere(hand.PalmPosition, Constants.PalmSphereRadius, _boneColors[Constants.BoneNames.Palm], opacity);

            foreach (var fjp in hand.FingerJointPositions_World)
            {
                var finger     = fjp.Value;
                var fingerType = fjp.Key;

                Vec3 mcp = finger[Finger.FingerJoint.JOINT_MCP];
                Vec3 pip = finger[Finger.FingerJoint.JOINT_PIP];
                Vec3 dip = finger[Finger.FingerJoint.JOINT_DIP];
                Vec3 tip = finger[Finger.FingerJoint.JOINT_TIP];

                DrawSphere(mcp, Constants.FingerTipRadius, Colors.White, opacity);
                DrawSphere(pip, Constants.FingerTipRadius, Colors.White, opacity);
                DrawSphere(dip, Constants.FingerTipRadius, Colors.White, opacity);
                DrawSphere(tip, Constants.FingerTipRadius, Colors.White, opacity);

                // Draw finger bones
                string boneColorKey = HelperMethods.GetBoneColorKey(fingerType, Bone.BoneType.TYPE_DISTAL);
                DrawCylinder(Constants.FingerTipRadius, tip, dip, _boneColors[boneColorKey], opacity);
                boneColorKey = HelperMethods.GetBoneColorKey(fingerType, Bone.BoneType.TYPE_INTERMEDIATE);
                DrawCylinder(Constants.FingerTipRadius, dip, pip, _boneColors[boneColorKey], opacity);
                boneColorKey = HelperMethods.GetBoneColorKey(fingerType, Bone.BoneType.TYPE_PROXIMAL);
                DrawCylinder(Constants.FingerTipRadius, pip, mcp, _boneColors[boneColorKey], opacity);
            }

            // Draw hand bones
            Vec3 indexMCP  = hand.FingerJointPositions_World[Leap.Finger.FingerType.TYPE_INDEX][Finger.FingerJoint.JOINT_MCP];
            Vec3 middleMCP = hand.FingerJointPositions_World[Leap.Finger.FingerType.TYPE_MIDDLE][Finger.FingerJoint.JOINT_MCP];
            Vec3 ringMCP   = hand.FingerJointPositions_World[Leap.Finger.FingerType.TYPE_RING][Finger.FingerJoint.JOINT_MCP];
            Vec3 pinkyMCP  = hand.FingerJointPositions_World[Leap.Finger.FingerType.TYPE_PINKY][Finger.FingerJoint.JOINT_MCP];

            DrawCylinder(Constants.FingerTipRadius, hand.IndexBasePos_World, indexMCP, _boneColors[Constants.BoneNames.Index_Metacarpal], opacity);
            DrawCylinder(Constants.FingerTipRadius, hand.MiddleBasePos_World, middleMCP, _boneColors[Constants.BoneNames.Middle_Metacarpal], opacity);
            DrawCylinder(Constants.FingerTipRadius, hand.RingBasePos_World, ringMCP, _boneColors[Constants.BoneNames.Ring_Metacarpal], opacity);
            DrawCylinder(Constants.FingerTipRadius, hand.PinkyBasePos_World, pinkyMCP, _boneColors[Constants.BoneNames.Pinky_Metacarpal], opacity);

            // Draw base of hand
            DrawCylinder(Constants.FingerTipRadius, hand.PinkyBasePos_World, hand.ThumbBasePos_World, _boneColors[Constants.BoneNames.BaseOfHand], opacity);

            if (showArms)
            {
                // Draw elbow
                DrawSphere(hand.ElbowPos_World, Constants.WristSphereRadius, _boneColors[Constants.BoneNames.Elbow], opacity);
                // Draw center of forearm
                DrawSphere(hand.ForearmCenter_World, Constants.WristSphereRadius, _boneColors[Constants.BoneNames.ForearmCenter], opacity);

                float forearmWidth = hand.PinkyBasePos_World.DistanceTo(hand.ThumbBasePos_World);

                // Draw two cylinders for arms (Ulna - pinky side, Radius - thumb side)
                Vec3 ulnaBase = hand.WristPos_World + ((forearmWidth / 2) * hand.ArmX);
                Vec3 ulnaTop  = hand.ElbowPos_World + ((forearmWidth / 2) * hand.ArmX);
                DrawSphere(ulnaBase, Constants.FingerTipRadius * 1.2, Colors.CadetBlue, opacity);
                DrawSphere(ulnaTop, Constants.FingerTipRadius * 1.2, Colors.CadetBlue, opacity);
                DrawCylinder(Constants.FingerTipRadius, ulnaBase, ulnaTop, _boneColors[Constants.BoneNames.Arm], opacity);

                Vec3 radiusBase = hand.WristPos_World - ((forearmWidth / 2) * hand.ArmX);
                Vec3 radiusTop  = hand.ElbowPos_World - ((forearmWidth / 2) * hand.ArmX);
                DrawSphere(radiusBase, Constants.FingerTipRadius * 1.2, Colors.CadetBlue, opacity);
                DrawSphere(radiusTop, Constants.FingerTipRadius * 1.2, Colors.CadetBlue, opacity);
                DrawCylinder(Constants.FingerTipRadius, radiusBase, radiusTop, _boneColors[Constants.BoneNames.Arm], opacity);

                // Connect the forearm bones at top and bottom
                DrawCylinder(Constants.FingerTipRadius, ulnaBase, radiusBase, _boneColors[Constants.BoneNames.Arm], opacity);
                DrawCylinder(Constants.FingerTipRadius, ulnaTop, radiusTop, _boneColors[Constants.BoneNames.Arm], opacity);
            }
        }