/// <summary> /// Initializes the <see cref="BoneTypeEx"/> class. /// </summary> static CustomBoneType() { HipLeft = new CustomBoneType() { Name = "HipLeft", DisplayName = "Left Hip", StartJoint = CustomJointType.SpineBase, EndJoint = CustomJointType.HipLeft }; HipRight = new CustomBoneType() { Name = "HipRight", DisplayName = "Right Hip", StartJoint = CustomJointType.SpineBase, EndJoint = CustomJointType.HipRight }; LegUpperLeft = new CustomBoneType() { Name = "LegUpperLeft", DisplayName = "Upper Left Leg", StartJoint = CustomJointType.HipLeft, EndJoint = CustomJointType.KneeLeft }; LegUpperRight = new CustomBoneType() { Name = "LegUpperRight", DisplayName = "Upper Right Leg", StartJoint = CustomJointType.HipRight, EndJoint = CustomJointType.KneeRight }; LegLowerLeft = new CustomBoneType() { Name = "LegLowerLeft", DisplayName = "Lower Left Leg", StartJoint = CustomJointType.KneeLeft, EndJoint = CustomJointType.AnkleLeft }; LegLowerRight = new CustomBoneType() { Name = "LegLowerRight", DisplayName = "Lower Right Leg", StartJoint = CustomJointType.KneeRight, EndJoint = CustomJointType.AnkleRight }; FootLeft = new CustomBoneType() { Name = "FootLeft", DisplayName = "Left Foot", StartJoint = CustomJointType.AnkleLeft, EndJoint = CustomJointType.FootLeft }; FootRight = new CustomBoneType() { Name = "FootRight", DisplayName = "Right Foot", StartJoint = CustomJointType.AnkleRight, EndJoint = CustomJointType.FootRight }; SpineLower = new CustomBoneType() { Name = "SpineLower", DisplayName = "Lower Spine", StartJoint = CustomJointType.SpineBase, EndJoint = CustomJointType.SpineMid }; SpineUpper = new CustomBoneType() { Name = "SpineUpper", DisplayName = "Upper Spine", StartJoint = CustomJointType.SpineMid, EndJoint = CustomJointType.SpineShoulder }; ShoulderLeft = new CustomBoneType() { Name = "ShoulderLeft", DisplayName = "Left Shoulder", StartJoint = CustomJointType.SpineShoulder, EndJoint = CustomJointType.ShoulderLeft }; ShoulderRight = new CustomBoneType() { Name = "ShoulderRight", DisplayName = "Right Shoulder", StartJoint = CustomJointType.SpineShoulder, EndJoint = CustomJointType.ShoulderRight }; ArmUpperLeft = new CustomBoneType() { Name = "ArmUpperLeft", DisplayName = "Upper Left Arm", StartJoint = CustomJointType.ShoulderLeft, EndJoint = CustomJointType.ElbowLeft }; ArmUpperRight = new CustomBoneType() { Name = "ArmUpperRight", DisplayName = "Upper Right Arm", StartJoint = CustomJointType.ShoulderRight, EndJoint = CustomJointType.ElbowRight }; ArmLowerLeft = new CustomBoneType() { Name = "ArmLowerLeft", DisplayName = "Lower Left Arm", StartJoint = CustomJointType.ElbowLeft, EndJoint = CustomJointType.WristLeft }; ArmLowerRight = new CustomBoneType() { Name = "ArmLowerRight", DisplayName = "Lower Right Arm", StartJoint = CustomJointType.ElbowRight, EndJoint = CustomJointType.WristRight }; HandLeft = new CustomBoneType() { Name = "HandLeft", DisplayName = "Left Hand", StartJoint = CustomJointType.WristLeft, EndJoint = CustomJointType.HandLeft }; HandRight = new CustomBoneType() { Name = "HandRight", DisplayName = "Right Hand", StartJoint = CustomJointType.WristRight, EndJoint = CustomJointType.HandRight }; Head = new CustomBoneType() { Name = "Head", DisplayName = "Head", StartJoint = CustomJointType.SpineShoulder, EndJoint = CustomJointType.Head }; HipFull = new CustomBoneType() { Name = "HipFull", DisplayName = "Full Hip", StartJoint = CustomJointType.HipLeft, EndJoint = CustomJointType.HipRight }; ShoulderFull = new CustomBoneType() { Name = "ShoulderFull", DisplayName = "Full Shoulders", StartJoint = CustomJointType.ShoulderLeft, EndJoint = CustomJointType.ShoulderRight }; DrawnBones = new List<CustomBoneType>() { HipLeft, HipRight, LegUpperLeft, LegUpperRight, LegLowerLeft, LegLowerRight, FootLeft, FootRight, SpineLower, SpineUpper, ShoulderLeft, ShoulderRight, ArmUpperLeft, ArmUpperRight, ArmLowerLeft, ArmLowerRight, HandLeft, HandRight, Head }; AllBones = DrawnBones.ToList(); AllBones.Add(HipFull); AllBones.Add(ShoulderFull); MirroredBones = new Dictionary<CustomBoneType, CustomBoneType>(); MirroredBones.Add(HipLeft, HipRight); MirroredBones.Add(HipRight, HipLeft); MirroredBones.Add(LegUpperLeft, LegUpperRight); MirroredBones.Add(LegUpperRight, LegUpperLeft); MirroredBones.Add(LegLowerLeft, LegLowerRight); MirroredBones.Add(LegLowerRight, LegLowerLeft); MirroredBones.Add(FootLeft, FootRight); MirroredBones.Add(FootRight, FootLeft); MirroredBones.Add(SpineLower, SpineLower); MirroredBones.Add(SpineUpper, SpineUpper); MirroredBones.Add(ShoulderLeft, ShoulderRight); MirroredBones.Add(ShoulderRight, ShoulderLeft); MirroredBones.Add(ArmUpperLeft, ArmUpperRight); MirroredBones.Add(ArmUpperRight, ArmUpperLeft); MirroredBones.Add(ArmLowerLeft, ArmLowerRight); MirroredBones.Add(ArmLowerRight, ArmLowerLeft); MirroredBones.Add(HandLeft, HandRight); MirroredBones.Add(HandRight, HandLeft); MirroredBones.Add(Head, Head); MirroredBones.Add(HipFull, HipFull); MirroredBones.Add(ShoulderFull, ShoulderFull); ByName = new Dictionary<string, CustomBoneType>(); foreach (var bone in AllBones) { ByName.Add(bone.Name, bone); } }
private static void DrawBone(IBody body, BitmapContext context, CustomBoneType bone, Color color) { var startJoint = body.Joints[bone.StartJoint]; var endJoint = body.Joints[bone.EndJoint]; // If we can't find either of these joints, exit if (startJoint.TrackingState == TrackingState.NotTracked || endJoint.TrackingState == TrackingState.NotTracked) { return; } // Don't draw if both points are inferred if (startJoint.TrackingState == TrackingState.Inferred && endJoint.TrackingState == TrackingState.Inferred) { return; } // If either isn't tracked, it is "inferred" if (startJoint.TrackingState != TrackingState.Tracked || endJoint.TrackingState != TrackingState.Tracked) { color.A = 192; } var startPoint = GetDepthSpacePoint(startJoint, body.HasMappedDepthPositions); var endPoint = GetDepthSpacePoint(endJoint, body.HasMappedDepthPositions); context.WriteableBitmap.DrawLineAa( (int)startPoint.X, (int)startPoint.Y, (int)endPoint.X, (int)endPoint.Y, color); }