public void OnFrame(object sender, FrameEventArgs args) { // Get the most recent frame and report some basic information Frame frame = args.frame; if (frame.Hands.Count == 2) { Console.WriteLine("Two Hands in frame, move one out of the way."); } else if (frame.Hands.Count == 0) { Console.WriteLine("No Hands in Frame, move one into the frame."); } else { float[] WristPos = frame.Hands[0].WristPosition.ToFloatArray(); float pitch = frame.Hands[0].Direction.Pitch * 180.0f / (float)Math.PI; if (pitch <= -90) { pitch = -90; } else if (pitch >= 90) { pitch = 90; } float roll = frame.Hands[0].PalmNormal.Roll * 180.0f / (float)Math.PI; if (roll >= 90) { roll = 90; } else if (roll <= -90) { roll = -90; } float gripdist = frame.Hands[0].PinchDistance; data.setData((int)WristPos[0], (int)WristPos[1] - 254, (int)WristPos[2] - 350, roll + 90, pitch + 90, gripdist); } /** * Console.WriteLine( * "Frame id: {0}, timestamp: {1}, hands: {2}", * frame.Id, frame.Timestamp, frame.Hands.Count * ); * * foreach (Hand hand in frame.Hands) * { * Console.WriteLine(" Hand id: {0}, palm position: {1}, fingers: {2}", * hand.Id, hand.PalmPosition, hand.Fingers.Count); * // Get the hand's normal vector and direction * Vector normal = hand.PalmNormal; * Vector direction = hand.Direction; * * // Calculate the hand's pitch, roll, and yaw angles * Console.WriteLine( * " Hand pitch: {0} degrees, roll: {1} degrees, yaw: {2} degrees", * direction.Pitch * 180.0f / (float)Math.PI, * normal.Roll * 180.0f / (float)Math.PI, * direction.Yaw * 180.0f / (float)Math.PI * ); * * // Get the Arm bone * Arm arm = hand.Arm; * Console.WriteLine( * " Arm direction: {0}, wrist position: {1}, elbow position: {2}", * arm.Direction, arm.WristPosition, arm.ElbowPosition * ); * * // Get fingers * foreach (Finger finger in * * .Fingers) * { * Console.WriteLine( * " Finger id: {0}, {1}, length: {2}mm, width: {3}mm", * finger.Id, * finger.Type.ToString(), * finger.Length, * finger.Width * ); * * // Get finger bones * Bone bone; * for (int b = 0; b < 4; b++) * { * bone = finger.Bone ((Bone.BoneType)b); * Console.WriteLine ( * " Bone: {0}, start: {1}, end: {2}, direction: {3}", * bone.Type, bone.PrevJoint, bone.NextJoint, bone.Direction * ); * } * } * } * * if (frame.Hands.Count != 0) * { * Console.WriteLine(""); * } */ }