// Update the segment's position and compute a smoothed velocity for the circle or the
        // endpoints of the segment based on  the time it took it to move from the last position
        // to the current one.  The velocity is in pixels per second.

        public void UpdateSegment(Segment s)
        {
            segLast = seg;
            seg = s;

            DateTime cur = DateTime.Now;
            double fMs = cur.Subtract(timeLastUpdated).TotalMilliseconds;
            if (fMs < 10.0)
                fMs = 10.0;
            double fFPS = 1000.0 / fMs;
            timeLastUpdated = cur;

            if (seg.IsCircle())
            {
                xVel = xVel * smoothing + (1.0 - smoothing) * (seg.x1 - segLast.x1) * fFPS;
                yVel = yVel * smoothing + (1.0 - smoothing) * (seg.y1 - segLast.y1) * fFPS;
            }
            else
            {
                xVel = xVel * smoothing + (1.0 - smoothing) * (seg.x1 - segLast.x1) * fFPS;
                yVel = yVel * smoothing + (1.0 - smoothing) * (seg.y1 - segLast.y1) * fFPS;
                xVel2 = xVel2 * smoothing + (1.0 - smoothing) * (seg.x2 - segLast.x2) * fFPS;
                yVel2 = yVel2 * smoothing + (1.0 - smoothing) * (seg.y2 - segLast.y2) * fFPS;
            }
        }
 public BoneData(Segment s)
 {
     seg = segLast = s;
     xVel = yVel = 0;
     xVel2 = yVel2 = 0;
     timeLastUpdated = DateTime.Now;
 }
 void UpdateSegmentPosition(JointID j1, JointID j2, Segment seg)
 {
     var bone = new Bone(j1, j2);
     if (segments.ContainsKey(bone))
     {
         BoneData data = segments[bone];
         data.UpdateSegment(seg);
         segments[bone] = data;
     }
     else
         segments.Add(bone, new BoneData(seg));
 }
 public void UpdateJointPosition(Microsoft.Research.Kinect.Nui.JointsCollection joints, JointID j)
 {
     var seg = new Segment(joints[j].Position.X * playerScale + playerCenter.X,
                           playerCenter.Y - joints[j].Position.Y * playerScale);
     seg.radius = playerBounds.Height * ((j == JointID.Head) ? HEAD_SIZE : HAND_SIZE) / 2;
     UpdateSegmentPosition(j, j, seg);
 }
 public void UpdateBonePosition(Microsoft.Research.Kinect.Nui.JointsCollection joints, JointID j1, JointID j2)
 {
     var seg = new Segment(joints[j1].Position.X * playerScale + playerCenter.X,
                           playerCenter.Y - joints[j1].Position.Y * playerScale,
                           joints[j2].Position.X * playerScale + playerCenter.X,
                           playerCenter.Y - joints[j2].Position.Y * playerScale);
     seg.radius = Math.Max(3.0, playerBounds.Height * BONE_SIZE) / 2;
     UpdateSegmentPosition(j1, j2, seg);
 }