Answered by:
Need angle of user rotation?
Question

Answers

Try something like this:
double GetShoulderRotation(Skeleton skeleton) { Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft]; Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight]; if (leftShoulder.TrackingState == JointTrackingState.NotTracked  rightShoulder.TrackingState == JointTrackingState.NotTracked) { return Double.NaN; } else { return Math.Atan2( rightShoulder.Position.Z  leftShoulder.Position.Z, leftShoulder.Position.X  rightShoulder.Position.X) * 180.0 / Math.PI; } }
This will return NaN if either shoulder isn't tracked. Otherwise, it should return an angle in degrees. Zero means facing directly forward.
John
K4W Dev Proposed as answer by Michael Osthege Wednesday, February 29, 2012 11:23 AM
 Marked as answer by Carmine Si  MSFTMicrosoft employee Saturday, March 3, 2012 12:50 AM
All replies

Last time I tried, facing away from the Kinect gave bad data; it said I was facing the Kinect, with my arms behind my body. I'd expect a little less than 180 degrees of useful data.
For angle of rotation, either go for the two shoulder points, or two hip joints. (Or average them.) Use the X and Z coords, and form a right triangle. Use trigonometry to find the angles, then add/subtract 90 degrees to find the angle.


Try something like this:
double GetShoulderRotation(Skeleton skeleton) { Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft]; Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight]; if (leftShoulder.TrackingState == JointTrackingState.NotTracked  rightShoulder.TrackingState == JointTrackingState.NotTracked) { return Double.NaN; } else { return Math.Atan2( rightShoulder.Position.Z  leftShoulder.Position.Z, leftShoulder.Position.X  rightShoulder.Position.X) * 180.0 / Math.PI; } }
This will return NaN if either shoulder isn't tracked. Otherwise, it should return an angle in degrees. Zero means facing directly forward.
John
K4W Dev Proposed as answer by Michael Osthege Wednesday, February 29, 2012 11:23 AM
 Marked as answer by Carmine Si  MSFTMicrosoft employee Saturday, March 3, 2012 12:50 AM