void UpdateAngle(Joint rShoulder, Joint rElbow, Joint rWrist) { if(rShoulder.TrackingState == TrackingState.NotTracked || rElbow.TrackingState == TrackingState.NotTracked || rWrist.TrackingState == TrackingState.NotTracked) { return; } var shoulderPoint = coordinateMapper.MapCameraPointToColorSpace(rShoulder.Position); var elbowPoint = coordinateMapper.MapCameraPointToColorSpace(rElbow.Position); var wristPoint = coordinateMapper.MapCameraPointToColorSpace(rWrist.Position); // Negate the Y component since the screen space starts at the top var v1 = new Vec2f(shoulderPoint.X - elbowPoint.X, -(shoulderPoint.Y - elbowPoint.Y)); var v2 = new Vec2f(wristPoint.X - elbowPoint.X, -(wristPoint.Y - elbowPoint.Y)); v1.Normalize(); v2.Normalize(); int angle = (int)Math.Round(Math.Acos(v1.Dot(v2)) * (180 / Math.PI)); angle -= 180; angle = -angle; AngleTextBlock.Text = angle.ToString(); }
public float Dot(Vec2f cVector) { return _x * cVector._x + _y * cVector._y; }