public void update(Player pLeft, Player pRight)
        {
            updateBall(pLeft, leftBall);
            updateBall(pRight, rightBall);

            leftHoop.isBallScored(rightBall);
            rightHoop.isBallScored(leftBall);
        }
        private void updateBall(Player p, HandleObject b)
        {
            Point leftPoint = p.jointPoints[JointType.HandLeft];
            HandState leftHand = p.body.HandLeftState;
            float leftDepth = p.jointPointDepths[JointType.HandLeft];

            Point rightPoint = p.jointPoints[JointType.HandRight];
            HandState rightHand = p.body.HandRightState;
            float rightDepth = p.jointPointDepths[JointType.HandRight];

            if (ballsCollide(leftBall, rightBall))
            {
                if (!(leftBall.isBoundToHand || rightBall.isBoundToHand))
                {
                    Point leftVel = leftBall.getVelocity();
                    Point rightVel = rightBall.getVelocity();

                    leftBall.onCollide(rightVel.X, rightVel.Y);
                    rightBall.onCollide(leftVel.X, leftVel.Y);
                }
            }

            b.update(leftHand, rightHand, leftPoint, rightPoint, leftDepth, rightDepth);
        }
        private void processBodyFrame(BodyFrame bodyFrame, bool showSkeleton, bool showHandStates)
        {
            if (this.bodies == null)
            {
                this.bodies = new Body[bodyFrame.BodyCount];
            }

            // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
            // As long as those body objects are not disposed and not set to null in the array,
            // those body objects will be re-used.
            bodyFrame.GetAndRefreshBodyData(this.bodies);

            players[0] = null;
            players[1] = null;
            Body[] tempBodies = new Body[2];
            int playerCount = 0;
            foreach (Body body in this.bodies)
            {
                if (body.IsTracked && playerCount < 2)
                {
                    tempBodies[playerCount++] = body;
                }
            }

            if (playerCount == 2)
            {
                CameraSpacePoint player0Pos = tempBodies[0].Joints[JointType.SpineMid].Position;
                CameraSpacePoint player1Pos = tempBodies[1].Joints[JointType.SpineMid].Position;

                if (player0Pos.X < player1Pos.X)
                {
                    players[0] = new Player(tempBodies[0]);
                    players[1] = new Player(tempBodies[1]);
                }
                else
                {
                    players[1] = new Player(tempBodies[0]);
                    players[0] = new Player(tempBodies[1]);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                int penIndex = 0;
                foreach (Player player in players)
                {
                    if (player == null) continue;
                    Body body = player.body;

                    Pen drawPen = this.bodyColors[penIndex++];

                    if (body.IsTracked)
                    {
                        //this.DrawClippedEdges(body, dc);

                        IReadOnlyDictionary<JointType, Joint> joints = body.Joints;

                        // convert the joint points to depth (display) space
                        Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();
                        Dictionary<JointType, float> jointPointDepths = new Dictionary<JointType, float>();

                        foreach (JointType jointType in joints.Keys)
                        {
                            // sometimes the depth(Z) of an inferred joint may show as negative
                            // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                            CameraSpacePoint position = joints[jointType].Position;
                            if (position.Z < 0)
                            {
                                position.Z = InferredZPositionClamp;
                            }

                            ColorSpacePoint colorSpacePoint = this.coordinateMapper.MapCameraPointToColorSpace(position);
                            jointPoints[jointType] = new Point(colorSpacePoint.X, colorSpacePoint.Y);
                            jointPointDepths[jointType] = position.Z;
                        }

                        // Maps the actual joint points to the player
                        player.jointPoints = jointPoints;
                        player.jointPointDepths = jointPointDepths;

                        if (showSkeleton)
                        {
                            this.DrawBody(joints, jointPoints, dc, drawPen);
                        }

                        if (showHandStates)
                        {
                            this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                            this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
                        }

                        // THIS IS WHERE THE UPDATES GO. CAN'T MOVE IT BECAUSE OF THE GC OF DRAWING CONTEXT
                        /*
                        this.targetCircleL.update(
                            body.HandLeftState,
                            body.HandRightState,
                            jointPoints[JointType.HandLeft],
                            jointPoints[JointType.HandRight],
                            jointPointDepths[JointType.HandLeft],
                            jointPointDepths[JointType.HandLeft]
                        );
                        this.targetCircleL.draw(dc);
                         */
                        //basketballManager.update(player[0], player[1]);
                        //basketballManager.draw(dc);
                        //processBasketballManager(players[0], players[1], dc);
                    }
                }
                if (players[0] != null && players[1] != null)
                    processBasketballManager(players[0], players[1], dc);

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
            }

            bodyFrame.Dispose();
        }
 private void processBasketballManager(Player playerL, Player playerR, DrawingContext dc)
 {
     basketballManager.update(playerL, playerR);
     basketballManager.draw(dc);
 }