private void DrawBones(ZigInputJoint[] userSkeleton) { for (int t = 0; t < userSkeleton.Length; t++) { ZigJointId parentId = CinemaMocapHelper.ParentBoneJoint(userSkeleton[t].Id); ZigInputJoint parentJoint = null; for (int s = 0; s < userSkeleton.Length; s++) { if (userSkeleton[s].Id == parentId)// find parent and leave loop. { parentJoint = userSkeleton[s]; break; } } if (parentJoint != null && parentJoint.Id != ZigJointId.None && userSkeleton[t].GoodPosition && parentJoint.GoodPosition) { // parent and child joint coordinates int childX = textureSize.Width / 2 - (int)(userSkeleton[t].Position.x * 300 / userSkeleton[t].Position.z); int childY = textureSize.Height / 2 - (int)(userSkeleton[t].Position.y * 300 / userSkeleton[t].Position.z); int parentX = textureSize.Width / 2 - (int)(parentJoint.Position.x * 300 / parentJoint.Position.z); int parentY = textureSize.Height / 2 - (int)(parentJoint.Position.y * 300 / parentJoint.Position.z); // draw lines between joints Color color = (!userSkeleton[t].Inferred) ? Color.cyan : Color.red; CinemaMocapHelper.drawFastLine(outputPixels, textureSize.Width, textureSize.Height, childX, childY, parentX, parentY, color); } } }
private void DrawBones(Rect areaContent) { GUILayout.BeginArea(areaContent); Color origHandles = Handles.color; foreach (Dictionary <JointType, Windows.Kinect.Joint> jointDictionary in trackedBodyJoints) { foreach (Windows.Kinect.Joint joint in jointDictionary.Values) { // find parent joint JointType parentJointType = CinemaMocapHelper.ParentBoneJoint(joint.JointType); Windows.Kinect.Joint parentJoint; jointDictionary.TryGetValue(parentJointType, out parentJoint); // get position of each joint ColorSpacePoint childPos = coordinateMapper.MapCameraPointToColorSpace(joint.Position); ColorSpacePoint parentPos = coordinateMapper.MapCameraPointToColorSpace(parentJoint.Position); // set color depending on child joint tracking state if (joint.TrackingState == Windows.Kinect.TrackingState.Tracked) { Handles.color = Color.green; } else if (joint.TrackingState == Windows.Kinect.TrackingState.Inferred) { Handles.color = Color.red; } // draw bone/line between joints using CinemaMocapHelper Handles.DrawLine(new Vector3((childPos.X / ColorWidth) * areaContent.width, (childPos.Y / ColorHeight) * areaContent.height, 0), new Vector3((parentPos.X / ColorWidth) * areaContent.width, (parentPos.Y / ColorHeight) * areaContent.height, 0)); } } Handles.color = origHandles; GUILayout.EndArea(); }