Kinect.KinectManager.GetJointPosDepthOverlay C# (CSharp) Method

GetJointPosDepthOverlay() public method

Gets the 3d overlay position of the given joint over the depth-image.
public GetJointPosDepthOverlay ( Int64 userId, int joint, Camera camera, Rect imageRect ) : Vector3
userId Int64 User ID
joint int Joint index
camera UnityEngine.Camera Camera used to visualize the 3d overlay position
imageRect UnityEngine.Rect Depth image rectangle on the screen
return UnityEngine.Vector3
        public Vector3 GetJointPosDepthOverlay(Int64 userId, int joint, Camera camera, Rect imageRect)
        {
            if (dictUserIdToIndex.ContainsKey(userId) && camera != null)
            {
                int index = dictUserIdToIndex[userId];

                if (index >= 0 && index < sensorData.bodyCount &&
                   bodyFrame.bodyData[index].bIsTracked != 0)
                {
                    if (joint >= 0 && joint < sensorData.jointCount)
                    {
                        KinectInterop.JointData jointData = bodyFrame.bodyData[index].joint[joint];
                        Vector3 posJointRaw = jointData.kinectPos;

                        if (posJointRaw != Vector3.zero)
                        {
                            // 3d position to depth
                            Vector2 posDepth = MapSpacePointToDepthCoords(posJointRaw);

                            if (posDepth != Vector2.zero && sensorData != null)
                            {
                                if (!float.IsInfinity(posDepth.x) && !float.IsInfinity(posDepth.y))
                                {
                                    float xScaled = (float)posDepth.x * imageRect.width / sensorData.depthImageWidth;
                                    float yScaled = (float)posDepth.y * imageRect.height / sensorData.depthImageHeight;

                                    float xScreen = imageRect.x + xScaled;
                                    float yScreen = camera.pixelHeight - (imageRect.y + yScaled);

                                    Plane cameraPlane = new Plane(camera.transform.forward, camera.transform.position);
                                    float zDistance = cameraPlane.GetDistanceToPoint(posJointRaw);

                                    Vector3 vPosJoint = camera.ScreenToWorldPoint(new Vector3(xScreen, yScreen, zDistance));

                                    return vPosJoint;
                                }
                            }
                        }
                    }
                }
            }

            return Vector3.zero;
        }
KinectManager