/// <summary> /// Get a <c>Vector3</c> (SharpDX / DirectX) object representing the vector /// between two given <c>JointTypeEx</c> values.. /// </summary> public static Vector3 GetVector(this IBody body, JointTypeEx jointTypeA, JointTypeEx jointTypeB) { var posA = body.Joints[jointTypeA].Position; var posB = body.Joints[jointTypeB].Position; return(new Vector3(posA.X - posB.X, posA.Y - posB.Y, posA.Z - posB.Z)); }
/// <summary> /// Returns the angle (in degrees) between the two bones that /// intersect at the specified <c>JointTypeEx</c> value. /// </summary> public static double GetAngleAt(this IBody body, JointTypeEx jointType) { if (_bonesAt.ContainsKey(jointType)) { return(body.GetAngleBetween(_bonesAt[jointType][0], _bonesAt[jointType][1], false, true)); } else { throw new KeyNotFoundException("Joint not found"); } }
/// <summary> /// Gets a list of the two <c>Bone</c> values that share the specified /// <c>JointTypeEx</c> value. /// </summary> public static List <Bone> GetBonesAt(this IBody body, JointTypeEx jointType) { if (_bonesAt.ContainsKey(jointType)) { return new List <Bone>() { body.GetBone(_bonesAt[jointType][0]), body.GetBone(_bonesAt[jointType][1]) } } ; else { return(null); } }
/// <summary> /// Initializes the <see cref="JointTypeEx"/> class. /// </summary> static JointTypeEx() { SpineBase = new JointTypeEx() { Name = "SpineBase", DisplayName = "Base of Spine", JointType = JointType.SpineBase }; SpineMid = new JointTypeEx() { Name = "SpineMid", DisplayName = "Middle of Spine", JointType = JointType.SpineMid }; Neck = new JointTypeEx() { Name = "Neck", DisplayName = "Neck", JointType = JointType.Neck }; Head = new JointTypeEx() { Name = "Head", DisplayName = "Head", JointType = JointType.Head }; ShoulderLeft = new JointTypeEx() { Name = "ShoulderLeft", DisplayName = "Left Shoulder", JointType = JointType.ShoulderLeft }; ElbowLeft = new JointTypeEx() { Name = "ElbowLeft", DisplayName = "Left Elbow", JointType = JointType.ElbowLeft }; WristLeft = new JointTypeEx() { Name = "WristLeft", DisplayName = "Left Wrist", JointType = JointType.WristLeft }; HandLeft = new JointTypeEx() { Name = "HandLeft", DisplayName = "Left Hand", JointType = JointType.HandLeft }; ShoulderRight = new JointTypeEx() { Name = "ShoulderRight", DisplayName = "Right Shoulder", JointType = JointType.ShoulderRight }; ElbowRight = new JointTypeEx() { Name = "ElbowRight", DisplayName = "Right Elbow", JointType = JointType.ElbowRight }; WristRight = new JointTypeEx() { Name = "WristRight", DisplayName = "Right Wrist", JointType = JointType.WristRight }; HandRight = new JointTypeEx() { Name = "HandRight", DisplayName = "Right Hand", JointType = JointType.HandRight }; HipLeft = new JointTypeEx() { Name = "HipLeft", DisplayName = "Left Hip", JointType = JointType.HipLeft }; KneeLeft = new JointTypeEx() { Name = "KneeLeft", DisplayName = "Left Knee", JointType = JointType.KneeLeft }; AnkleLeft = new JointTypeEx() { Name = "AnkleLeft", DisplayName = "Left Ankle", JointType = JointType.AnkleLeft }; FootLeft = new JointTypeEx() { Name = "FootLeft", DisplayName = "Left Foot", JointType = JointType.FootLeft }; HipRight = new JointTypeEx() { Name = "HipRight", DisplayName = "Right Hip", JointType = JointType.HipRight }; KneeRight = new JointTypeEx() { Name = "KneeRight", DisplayName = "Right Knee", JointType = JointType.KneeRight }; AnkleRight = new JointTypeEx() { Name = "AnkleRight", DisplayName = "Right Ankle", JointType = JointType.AnkleRight }; FootRight = new JointTypeEx() { Name = "FootRight", DisplayName = "Right Foot", JointType = JointType.FootRight }; SpineShoulder = new JointTypeEx() { Name = "SpineShoulder", DisplayName = "Spine at Shoulders", JointType = JointType.SpineShoulder }; HandTipLeft = new JointTypeEx() { Name = "HandTipLeft", DisplayName = "Left Hand Tip", JointType = JointType.HandTipLeft }; ThumbLeft = new JointTypeEx() { Name = "ThumbLeft", DisplayName = "Left Thumb", JointType = JointType.ThumbLeft }; HandTipRight = new JointTypeEx() { Name = "HandTipRight", DisplayName = "Right Hand Tip", JointType = JointType.HandTipRight }; ThumbRight = new JointTypeEx() { Name = "ThumbRight", DisplayName = "Right Thumb", JointType = JointType.ThumbRight }; AllJoints = new List<JointTypeEx>() { SpineBase, SpineMid, Head, Neck, ShoulderLeft, ElbowLeft, WristLeft, HandLeft, ShoulderRight, ElbowRight, WristRight, HandRight, HipLeft, KneeLeft, AnkleLeft, FootLeft, HipRight, KneeRight, AnkleRight, FootRight, SpineShoulder, HandTipLeft, ThumbLeft, HandTipRight, ThumbRight }; ByName = new Dictionary<string, JointTypeEx>(); foreach (var joint in AllJoints) { ByName.Add(joint.Name, joint); } MirroredJoints = new Dictionary<JointTypeEx, JointTypeEx>(); MirroredJoints.Add(SpineBase, SpineBase); MirroredJoints.Add(SpineMid, SpineMid); MirroredJoints.Add(Head, Head); MirroredJoints.Add(Neck, Neck); MirroredJoints.Add(ShoulderLeft, ShoulderRight); MirroredJoints.Add(ElbowLeft, ElbowRight); MirroredJoints.Add(WristLeft, WristRight); MirroredJoints.Add(HandLeft, HandRight); MirroredJoints.Add(ShoulderRight, ShoulderLeft); MirroredJoints.Add(ElbowRight, ElbowLeft); MirroredJoints.Add(WristRight, WristLeft); MirroredJoints.Add(HandRight, HandLeft); MirroredJoints.Add(HipLeft, HipRight); MirroredJoints.Add(KneeLeft, KneeRight); MirroredJoints.Add(AnkleLeft, AnkleRight); MirroredJoints.Add(FootLeft, FootRight); MirroredJoints.Add(HipRight, HipLeft); MirroredJoints.Add(KneeRight, KneeLeft); MirroredJoints.Add(AnkleRight, AnkleLeft); MirroredJoints.Add(FootRight, FootLeft); MirroredJoints.Add(SpineShoulder, SpineShoulder); MirroredJoints.Add(HandTipLeft, HandTipRight); MirroredJoints.Add(ThumbLeft, ThumbRight); MirroredJoints.Add(HandTipRight, HandTipLeft); MirroredJoints.Add(ThumbRight, ThumbLeft); ByJointType = new Dictionary<JointType, JointTypeEx>(); foreach (var joint in AllJoints) { ByJointType.Add(joint.JointType, joint); } }
/// <summary> /// Returns the distance (in meters) between the two specified joints. /// </summary> public static double GetDistanceBetween(this IBody body, JointTypeEx jointTypeA, JointTypeEx jointTypeB) { return(body.GetVector(jointTypeA, jointTypeB).Length()); }
/// <summary> /// Gets the <c>IJointOrientation</c> of the joint that mirrors the specified /// <c>JointTypeEx</c> (e.g., the left wrist mirrors the right wrist). /// </summary> public static IJointOrientation GetMirroredJointOrientation(this IBody body, JointTypeEx jointType) { return(body.JointOrientations[_mirroredJoints[jointType]]); }
/// <summary> /// Initializes the <see cref="JointTypeEx"/> class. /// </summary> static JointTypeEx() { SpineBase = new JointTypeEx() { Name = "SpineBase", DisplayName = "Base of Spine", JointType = JointType.SpineBase }; SpineMid = new JointTypeEx() { Name = "SpineMid", DisplayName = "Middle of Spine", JointType = JointType.SpineMid }; Neck = new JointTypeEx() { Name = "Neck", DisplayName = "Neck", JointType = JointType.Neck }; Head = new JointTypeEx() { Name = "Head", DisplayName = "Head", JointType = JointType.Head }; ShoulderLeft = new JointTypeEx() { Name = "ShoulderLeft", DisplayName = "Left Shoulder", JointType = JointType.ShoulderLeft }; ElbowLeft = new JointTypeEx() { Name = "ElbowLeft", DisplayName = "Left Elbow", JointType = JointType.ElbowLeft }; WristLeft = new JointTypeEx() { Name = "WristLeft", DisplayName = "Left Wrist", JointType = JointType.WristLeft }; HandLeft = new JointTypeEx() { Name = "HandLeft", DisplayName = "Left Hand", JointType = JointType.HandLeft }; ShoulderRight = new JointTypeEx() { Name = "ShoulderRight", DisplayName = "Right Shoulder", JointType = JointType.ShoulderRight }; ElbowRight = new JointTypeEx() { Name = "ElbowRight", DisplayName = "Right Elbow", JointType = JointType.ElbowRight }; WristRight = new JointTypeEx() { Name = "WristRight", DisplayName = "Right Wrist", JointType = JointType.WristRight }; HandRight = new JointTypeEx() { Name = "HandRight", DisplayName = "Right Hand", JointType = JointType.HandRight }; HipLeft = new JointTypeEx() { Name = "HipLeft", DisplayName = "Left Hip", JointType = JointType.HipLeft }; KneeLeft = new JointTypeEx() { Name = "KneeLeft", DisplayName = "Left Knee", JointType = JointType.KneeLeft }; AnkleLeft = new JointTypeEx() { Name = "AnkleLeft", DisplayName = "Left Ankle", JointType = JointType.AnkleLeft }; FootLeft = new JointTypeEx() { Name = "FootLeft", DisplayName = "Left Foot", JointType = JointType.FootLeft }; HipRight = new JointTypeEx() { Name = "HipRight", DisplayName = "Right Hip", JointType = JointType.HipRight }; KneeRight = new JointTypeEx() { Name = "KneeRight", DisplayName = "Right Knee", JointType = JointType.KneeRight }; AnkleRight = new JointTypeEx() { Name = "AnkleRight", DisplayName = "Right Ankle", JointType = JointType.AnkleRight }; FootRight = new JointTypeEx() { Name = "FootRight", DisplayName = "Right Foot", JointType = JointType.FootRight }; SpineShoulder = new JointTypeEx() { Name = "SpineShoulder", DisplayName = "Spine at Shoulders", JointType = JointType.SpineShoulder }; HandTipLeft = new JointTypeEx() { Name = "HandTipLeft", DisplayName = "Left Hand Tip", JointType = JointType.HandTipLeft }; ThumbLeft = new JointTypeEx() { Name = "ThumbLeft", DisplayName = "Left Thumb", JointType = JointType.ThumbLeft }; HandTipRight = new JointTypeEx() { Name = "HandTipRight", DisplayName = "Right Hand Tip", JointType = JointType.HandTipRight }; ThumbRight = new JointTypeEx() { Name = "ThumbRight", DisplayName = "Right Thumb", JointType = JointType.ThumbRight }; AllJoints = new List <JointTypeEx>() { SpineBase, SpineMid, Head, Neck, ShoulderLeft, ElbowLeft, WristLeft, HandLeft, ShoulderRight, ElbowRight, WristRight, HandRight, HipLeft, KneeLeft, AnkleLeft, FootLeft, HipRight, KneeRight, AnkleRight, FootRight, SpineShoulder, HandTipLeft, ThumbLeft, HandTipRight, ThumbRight }; ByName = new Dictionary <string, JointTypeEx>(); foreach (var joint in AllJoints) { ByName.Add(joint.Name, joint); } MirroredJoints = new Dictionary <JointTypeEx, JointTypeEx>(); MirroredJoints.Add(SpineBase, SpineBase); MirroredJoints.Add(SpineMid, SpineMid); MirroredJoints.Add(Head, Head); MirroredJoints.Add(Neck, Neck); MirroredJoints.Add(ShoulderLeft, ShoulderRight); MirroredJoints.Add(ElbowLeft, ElbowRight); MirroredJoints.Add(WristLeft, WristRight); MirroredJoints.Add(HandLeft, HandRight); MirroredJoints.Add(ShoulderRight, ShoulderLeft); MirroredJoints.Add(ElbowRight, ElbowLeft); MirroredJoints.Add(WristRight, WristLeft); MirroredJoints.Add(HandRight, HandLeft); MirroredJoints.Add(HipLeft, HipRight); MirroredJoints.Add(KneeLeft, KneeRight); MirroredJoints.Add(AnkleLeft, AnkleRight); MirroredJoints.Add(FootLeft, FootRight); MirroredJoints.Add(HipRight, HipLeft); MirroredJoints.Add(KneeRight, KneeLeft); MirroredJoints.Add(AnkleRight, AnkleLeft); MirroredJoints.Add(FootRight, FootLeft); MirroredJoints.Add(SpineShoulder, SpineShoulder); MirroredJoints.Add(HandTipLeft, HandTipRight); MirroredJoints.Add(ThumbLeft, ThumbRight); MirroredJoints.Add(HandTipRight, HandTipLeft); MirroredJoints.Add(ThumbRight, ThumbLeft); ByJointType = new Dictionary <JointType, JointTypeEx>(); foreach (var joint in AllJoints) { ByJointType.Add(joint.JointType, joint); } }