private static void DrawBone(IBody body, BitmapContext context, BoneTypeEx 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); }
/// <summary> /// Returns the angle (in degrees) between the two specified /// <c>BoneTypeEx</c> values. Optionally allows for either or /// both bones to be inverted to achieve the desired orientation. /// </summary> public static double GetAngleBetween(this IBody body, BoneTypeEx boneTypeA, BoneTypeEx boneTypeB, bool invertBoneA = false, bool invertBoneB = false) { return(AngleBetween(body.GetVector(boneTypeA, invertBoneA), body.GetVector(boneTypeB, invertBoneB))); }
/// <summary> /// Returns the angle (in degrees) between the two specified /// <c>BoneTypeEx</c> values. Optionally allows for either or /// both bones to be inverted to achieve the desired orientation. /// </summary> public static double GetAngleBetween(this Body body, BoneTypeEx boneTypeA, BoneTypeEx boneTypeB, bool invertBoneA = false, bool invertBoneB = false) { return(((KinectBody)body).GetAngleBetween(boneTypeA, boneTypeB, invertBoneA, invertBoneB)); }
/// <summary> /// Get a <c>Vector3</c> (SharpDX / DirectX) object representing the vector /// between the joints of the specified <c>BoneTypeEx</c> value. Optionally /// allows for the bone to be inverted to achieve the desired orientation. /// </summary> public static Vector3 GetVector(this IBody body, BoneTypeEx boneType, bool invert = false) { if (invert) { return(body.GetVector(boneType.EndJoint, boneType.StartJoint)); } else { return(body.GetVector(boneType.StartJoint, boneType.EndJoint)); } }
/// <summary> /// Initializes the <see cref="BoneTypeEx"/> class. /// </summary> static BoneTypeEx() { HipLeft = new BoneTypeEx() { Name = "HipLeft", DisplayName = "Left Hip", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.HipLeft }; HipRight = new BoneTypeEx() { Name = "HipRight", DisplayName = "Right Hip", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.HipRight }; LegUpperLeft = new BoneTypeEx() { Name = "LegUpperLeft", DisplayName = "Upper Left Leg", StartJoint = JointTypeEx.HipLeft, EndJoint = JointTypeEx.KneeLeft }; LegUpperRight = new BoneTypeEx() { Name = "LegUpperRight", DisplayName = "Upper Right Leg", StartJoint = JointTypeEx.HipRight, EndJoint = JointTypeEx.KneeRight }; LegLowerLeft = new BoneTypeEx() { Name = "LegLowerLeft", DisplayName = "Lower Left Leg", StartJoint = JointTypeEx.KneeLeft, EndJoint = JointTypeEx.AnkleLeft }; LegLowerRight = new BoneTypeEx() { Name = "LegLowerRight", DisplayName = "Lower Right Leg", StartJoint = JointTypeEx.KneeRight, EndJoint = JointTypeEx.AnkleRight }; FootLeft = new BoneTypeEx() { Name = "FootLeft", DisplayName = "Left Foot", StartJoint = JointTypeEx.AnkleLeft, EndJoint = JointTypeEx.FootLeft }; FootRight = new BoneTypeEx() { Name = "FootRight", DisplayName = "Right Foot", StartJoint = JointTypeEx.AnkleRight, EndJoint = JointTypeEx.FootRight }; SpineLower = new BoneTypeEx() { Name = "SpineLower", DisplayName = "Lower Spine", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.SpineMid }; SpineUpper = new BoneTypeEx() { Name = "SpineUpper", DisplayName = "Upper Spine", StartJoint = JointTypeEx.SpineMid, EndJoint = JointTypeEx.SpineShoulder }; ShoulderLeft = new BoneTypeEx() { Name = "ShoulderLeft", DisplayName = "Left Shoulder", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.ShoulderLeft }; ShoulderRight = new BoneTypeEx() { Name = "ShoulderRight", DisplayName = "Right Shoulder", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.ShoulderRight }; ArmUpperLeft = new BoneTypeEx() { Name = "ArmUpperLeft", DisplayName = "Upper Left Arm", StartJoint = JointTypeEx.ShoulderLeft, EndJoint = JointTypeEx.ElbowLeft }; ArmUpperRight = new BoneTypeEx() { Name = "ArmUpperRight", DisplayName = "Upper Right Arm", StartJoint = JointTypeEx.ShoulderRight, EndJoint = JointTypeEx.ElbowRight }; ArmLowerLeft = new BoneTypeEx() { Name = "ArmLowerLeft", DisplayName = "Lower Left Arm", StartJoint = JointTypeEx.ElbowLeft, EndJoint = JointTypeEx.WristLeft }; ArmLowerRight = new BoneTypeEx() { Name = "ArmLowerRight", DisplayName = "Lower Right Arm", StartJoint = JointTypeEx.ElbowRight, EndJoint = JointTypeEx.WristRight }; HandLeft = new BoneTypeEx() { Name = "HandLeft", DisplayName = "Left Hand", StartJoint = JointTypeEx.WristLeft, EndJoint = JointTypeEx.HandLeft }; HandRight = new BoneTypeEx() { Name = "HandRight", DisplayName = "Right Hand", StartJoint = JointTypeEx.WristRight, EndJoint = JointTypeEx.HandRight }; Head = new BoneTypeEx() { Name = "Head", DisplayName = "Head", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.Head }; HipFull = new BoneTypeEx() { Name = "HipFull", DisplayName = "Full Hip", StartJoint = JointTypeEx.HipLeft, EndJoint = JointTypeEx.HipRight }; ShoulderFull = new BoneTypeEx() { Name = "ShoulderFull", DisplayName = "Full Shoulders", StartJoint = JointTypeEx.ShoulderLeft, EndJoint = JointTypeEx.ShoulderRight }; DrawnBones = new List <BoneTypeEx>() { 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 <BoneTypeEx, BoneTypeEx>(); 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, BoneTypeEx>(); foreach (var bone in AllBones) { ByName.Add(bone.Name, bone); } }
/// <summary> /// Gets a <c>Bone</c> structure containing the two <c>IJoint</c> values /// that constitute the start and end of the specified <c>BoneTypeEx</c>. /// </summary> public static Bone GetBone(this Body body, BoneTypeEx boneType) { return(((KinectBody)body).GetBone(boneType)); }
/// <summary> /// Get a <c>Vector3</c> (SharpDX / DirectX) object representing the vector /// between the joints of the specified <c>BoneTypeEx</c> value. Optionally /// allows for the bone to be inverted to achieve the desired orientation. /// </summary> public static Vector3 GetVector(this Body body, BoneTypeEx boneType, bool invert = false) { return(((KinectBody)body).GetVector(boneType, invert)); }
/// <summary> /// Gets a <c>Bone</c> structure containing the two <c>IJoint</c> values /// that constitute the start and end of the specified <c>BoneTypeEx</c>. /// </summary> public static Bone GetBone(this IBody body, BoneTypeEx boneType) { return(new Bone(boneType, body.Joints[boneType.StartJoint], body.Joints[boneType.EndJoint])); }
/// <summary> /// Initializes the <see cref="BoneTypeEx"/> class. /// </summary> static BoneTypeEx() { HipLeft = new BoneTypeEx() { Name = "HipLeft", DisplayName = "Left Hip", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.HipLeft }; HipRight = new BoneTypeEx() { Name = "HipRight", DisplayName = "Right Hip", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.HipRight }; LegUpperLeft = new BoneTypeEx() { Name = "LegUpperLeft", DisplayName = "Upper Left Leg", StartJoint = JointTypeEx.HipLeft, EndJoint = JointTypeEx.KneeLeft }; LegUpperRight = new BoneTypeEx() { Name = "LegUpperRight", DisplayName = "Upper Right Leg", StartJoint = JointTypeEx.HipRight, EndJoint = JointTypeEx.KneeRight }; LegLowerLeft = new BoneTypeEx() { Name = "LegLowerLeft", DisplayName = "Lower Left Leg", StartJoint = JointTypeEx.KneeLeft, EndJoint = JointTypeEx.AnkleLeft }; LegLowerRight = new BoneTypeEx() { Name = "LegLowerRight", DisplayName = "Lower Right Leg", StartJoint = JointTypeEx.KneeRight, EndJoint = JointTypeEx.AnkleRight }; FootLeft = new BoneTypeEx() { Name = "FootLeft", DisplayName = "Left Foot", StartJoint = JointTypeEx.AnkleLeft, EndJoint = JointTypeEx.FootLeft }; FootRight = new BoneTypeEx() { Name = "FootRight", DisplayName = "Right Foot", StartJoint = JointTypeEx.AnkleRight, EndJoint = JointTypeEx.FootRight }; SpineLower = new BoneTypeEx() { Name = "SpineLower", DisplayName = "Lower Spine", StartJoint = JointTypeEx.SpineBase, EndJoint = JointTypeEx.SpineMid }; SpineUpper = new BoneTypeEx() { Name = "SpineUpper", DisplayName = "Upper Spine", StartJoint = JointTypeEx.SpineMid, EndJoint = JointTypeEx.SpineShoulder }; ShoulderLeft = new BoneTypeEx() { Name = "ShoulderLeft", DisplayName = "Left Shoulder", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.ShoulderLeft }; ShoulderRight = new BoneTypeEx() { Name = "ShoulderRight", DisplayName = "Right Shoulder", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.ShoulderRight }; ArmUpperLeft = new BoneTypeEx() { Name = "ArmUpperLeft", DisplayName = "Upper Left Arm", StartJoint = JointTypeEx.ShoulderLeft, EndJoint = JointTypeEx.ElbowLeft }; ArmUpperRight = new BoneTypeEx() { Name = "ArmUpperRight", DisplayName = "Upper Right Arm", StartJoint = JointTypeEx.ShoulderRight, EndJoint = JointTypeEx.ElbowRight }; ArmLowerLeft = new BoneTypeEx() { Name = "ArmLowerLeft", DisplayName = "Lower Left Arm", StartJoint = JointTypeEx.ElbowLeft, EndJoint = JointTypeEx.WristLeft }; ArmLowerRight = new BoneTypeEx() { Name = "ArmLowerRight", DisplayName = "Lower Right Arm", StartJoint = JointTypeEx.ElbowRight, EndJoint = JointTypeEx.WristRight }; HandLeft = new BoneTypeEx() { Name = "HandLeft", DisplayName = "Left Hand", StartJoint = JointTypeEx.WristLeft, EndJoint = JointTypeEx.HandLeft }; HandRight = new BoneTypeEx() { Name = "HandRight", DisplayName = "Right Hand", StartJoint = JointTypeEx.WristRight, EndJoint = JointTypeEx.HandRight }; Head = new BoneTypeEx() { Name = "Head", DisplayName = "Head", StartJoint = JointTypeEx.SpineShoulder, EndJoint = JointTypeEx.Head }; HipFull = new BoneTypeEx() { Name = "HipFull", DisplayName = "Full Hip", StartJoint = JointTypeEx.HipLeft, EndJoint = JointTypeEx.HipRight }; ShoulderFull = new BoneTypeEx() { Name = "ShoulderFull", DisplayName = "Full Shoulders", StartJoint = JointTypeEx.ShoulderLeft, EndJoint = JointTypeEx.ShoulderRight }; DrawnBones = new List<BoneTypeEx>() { 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<BoneTypeEx, BoneTypeEx>(); 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, BoneTypeEx>(); foreach (var bone in AllBones) { ByName.Add(bone.Name, bone); } }