public void TestConstructorRef() { ulong trackingId = 125; Dictionary<JointType, Vector3> data = new Dictionary<JointType, Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2, 4, 5)); data.Add(JointType.ElbowLeft, new Vector3(7, 4, 5)); data.Add(JointType.FootRight, new Vector3(-5, 4, 5)); KinectJointTable table = new KinectJointTable(trackingId, data); Assert.AreEqual(trackingId, table.TrackingId); Assert.AreEqual(table.Joints, data); }
public void TestConstructorRef() { ulong trackingId = 125; Dictionary <JointType, Vector3> data = new Dictionary <JointType, Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2, 4, 5)); data.Add(JointType.ElbowLeft, new Vector3(7, 4, 5)); data.Add(JointType.FootRight, new Vector3(-5, 4, 5)); KinectJointTable table = new KinectJointTable(trackingId, data); Assert.AreEqual(trackingId, table.TrackingId); Assert.AreEqual(table.Joints, data); }
public void TestConstructorData() { ulong trackingId = 125; Dictionary<JointType, Vector3> data = new Dictionary<JointType,Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2,4,5)); data.Add(JointType.ElbowLeft, new Vector3(7,4,5)); data.Add(JointType.FootRight, new Vector3(-5,4,5)); KinectJointTable table = new KinectJointTable(trackingId, data); Assert.AreEqual(trackingId, table.TrackingId); Assert.AreEqual(table.Joints.Count, data.Count); foreach (JointType jt in data.Keys) { Assert.AreEqual(data[jt], table.Joints[jt]); } }
public void TestConstructorData() { ulong trackingId = 125; Dictionary <JointType, Vector3> data = new Dictionary <JointType, Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2, 4, 5)); data.Add(JointType.ElbowLeft, new Vector3(7, 4, 5)); data.Add(JointType.FootRight, new Vector3(-5, 4, 5)); KinectJointTable table = new KinectJointTable(trackingId, data); Assert.AreEqual(trackingId, table.TrackingId); Assert.AreEqual(table.Joints.Count, data.Count); foreach (JointType jt in data.Keys) { Assert.AreEqual(data[jt], table.Joints[jt]); } }
public void TesTransform() { ulong trackingId = 125; Dictionary<JointType, Vector3> data = new Dictionary<JointType, Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2, 4, 5)); data.Add(JointType.ElbowLeft, new Vector3(7, 4, 5)); data.Add(JointType.FootRight, new Vector3(-5, 4, 5)); KinectJointTable table = new KinectJointTable(trackingId, data); Matrix m = Matrix.Translation(-4.0f, 5.0f, 6.0f); KinectJointTable transformed = table.Transform(m); foreach (JointType jt in data.Keys) { Assert.AreEqual(Vector3.TransformCoordinate(data[jt], m), transformed.Joints[jt]); } }
public void TesTransform() { ulong trackingId = 125; Dictionary <JointType, Vector3> data = new Dictionary <JointType, Vector3>(); data.Add(JointType.AnkleLeft, new Vector3(2, 4, 5)); data.Add(JointType.ElbowLeft, new Vector3(7, 4, 5)); data.Add(JointType.FootRight, new Vector3(-5, 4, 5)); KinectJointTable table = new KinectJointTable(trackingId, data); Matrix m = Matrix.Translation(-4.0f, 5.0f, 6.0f); KinectJointTable transformed = table.Transform(m); foreach (JointType jt in data.Keys) { Assert.AreEqual(Vector3.TransformCoordinate(data[jt], m), transformed.Joints[jt]); } }
/// <summary> /// Process joint table /// </summary> /// <param name="jointTable"></param> public void Process(KinectJointTable jointTable) { var leftHand = jointTable.Joints[JointType.HandLeft]; var rightHand = jointTable.Joints[JointType.HandRight]; var hipLeft = jointTable.Joints[JointType.HipLeft]; var hipRight = jointTable.Joints[JointType.HipRight]; var shoulderLeft = jointTable.Joints[JointType.ShoulderLeft]; var shoulderRight = jointTable.Joints[JointType.ShoulderRight]; var elbowLeft = jointTable.Joints[JointType.ElbowLeft]; var elbowRight = jointTable.Joints[JointType.ElbowRight]; //First compute elevation, we consider min y at hip and max y at shoulder float leftE = ((leftHand.Y - hipLeft.Y) / (shoulderLeft.Y - hipLeft.Y)) * 2.0f - 1.0f; float rightE = ((rightHand.Y - hipRight.Y) / (shoulderRight.Y - hipRight.Y)) * 2.0f - 1.0f; this.elevation = this.elevationCurve.Apply(MathUtil.Clamp((leftE + rightE) * 0.5f, -1.0f,1.0f)); float handDirX = leftHand.X - rightHand.X; float handDirY = leftHand.Y - rightHand.Y; float ang = Convert.ToSingle(Math.Atan2(handDirY, handDirX)); float pi = (float)Math.PI; float halfpi = (float)Math.PI * 0.5f; //remap left steer from -halpi to -pi if (ang < 0.0f) { ang = (1.0f - (ang + halfpi) / (-halfpi)) * -1.0f; } else { ang = (ang - pi) / (-halfpi); } this.steeringY = this.steeringCurve.Apply(MathUtil.Clamp(ang, -1.0f, 1.0f)); //Build z steering as per star wars game, hand angle in xz plane float handDirZ = leftHand.Z - rightHand.Z; float zang = Convert.ToSingle(Math.Atan2(handDirZ, handDirX)); if (zang < 0.0f) { zang = (1.0f - (zang + halfpi) / (-halfpi)) * -1.0f; } else { zang = (zang - pi) / (-halfpi); } this.steeringZ = zang; //Last computes push amount, here we say min push is Z next to shoulder and max push is shoulder + arm length float leftArmLength = Vector3.Distance(shoulderLeft, elbowLeft) + Vector3.Distance(elbowLeft, leftHand); float rightArmLength = Vector3.Distance(shoulderRight, elbowRight) + Vector3.Distance(elbowRight, rightHand); float leftP = ((shoulderLeft.Z - leftHand.Z) / (leftArmLength)) * 2.0f - 1.0f; float rightP = ((shoulderRight.Z -rightHand.Z) / (rightArmLength)) * 2.0f - 1.0f; this.push = this.pushCurve.Apply(MathUtil.Clamp((leftP + rightP) * 0.5f, -1.0f, 1.0f)); }
public void TestNullData() { ulong trackingId = 125; KinectJointTable table = new KinectJointTable(trackingId, null); }
/// <summary> /// Process joint table /// </summary> /// <param name="jointTable"></param> public void Process(KinectJointTable jointTable) { var leftHand = jointTable.Joints[JointType.HandLeft]; var rightHand = jointTable.Joints[JointType.HandRight]; var hipLeft = jointTable.Joints[JointType.HipLeft]; var hipRight = jointTable.Joints[JointType.HipRight]; var shoulderLeft = jointTable.Joints[JointType.ShoulderLeft]; var shoulderRight = jointTable.Joints[JointType.ShoulderRight]; var elbowLeft = jointTable.Joints[JointType.ElbowLeft]; var elbowRight = jointTable.Joints[JointType.ElbowRight]; //First compute elevation, we consider min y at hip and max y at shoulder float leftE = ((leftHand.Y - hipLeft.Y) / (shoulderLeft.Y - hipLeft.Y)) * 2.0f - 1.0f; float rightE = ((rightHand.Y - hipRight.Y) / (shoulderRight.Y - hipRight.Y)) * 2.0f - 1.0f; this.elevation = this.elevationCurve.Apply(MathUtil.Clamp((leftE + rightE) * 0.5f, -1.0f, 1.0f)); float handDirX = leftHand.X - rightHand.X; float handDirY = leftHand.Y - rightHand.Y; float ang = Convert.ToSingle(Math.Atan2(handDirY, handDirX)); float pi = (float)Math.PI; float halfpi = (float)Math.PI * 0.5f; //remap left steer from -halpi to -pi if (ang < 0.0f) { ang = (1.0f - (ang + halfpi) / (-halfpi)) * -1.0f; } else { ang = (ang - pi) / (-halfpi); } this.steeringY = this.steeringCurve.Apply(MathUtil.Clamp(ang, -1.0f, 1.0f)); //Build z steering as per star wars game, hand angle in xz plane float handDirZ = leftHand.Z - rightHand.Z; float zang = Convert.ToSingle(Math.Atan2(handDirZ, handDirX)); if (zang < 0.0f) { zang = (1.0f - (zang + halfpi) / (-halfpi)) * -1.0f; } else { zang = (zang - pi) / (-halfpi); } this.steeringZ = zang; //Last computes push amount, here we say min push is Z next to shoulder and max push is shoulder + arm length float leftArmLength = Vector3.Distance(shoulderLeft, elbowLeft) + Vector3.Distance(elbowLeft, leftHand); float rightArmLength = Vector3.Distance(shoulderRight, elbowRight) + Vector3.Distance(elbowRight, rightHand); float leftP = ((shoulderLeft.Z - leftHand.Z) / (leftArmLength)) * 2.0f - 1.0f; float rightP = ((shoulderRight.Z - rightHand.Z) / (rightArmLength)) * 2.0f - 1.0f; this.push = this.pushCurve.Apply(MathUtil.Clamp((leftP + rightP) * 0.5f, -1.0f, 1.0f)); }