Example #1
0
        // 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)
        {
            this.lastSegment = this.segment;
            this.segment = s;

            DateTime cur = DateTime.Now;
            double fMs = cur.Subtract(this.timeLastUpdated).TotalMilliseconds;
            if (fMs < 10.0)
            {
                fMs = 10.0;
            }

            double fps = 1000.0 / fMs;
            this.timeLastUpdated = cur;

            if (this.segment.IsCircle())
            {
                this.xVelocity1 = (this.xVelocity1 * smoothing) + ((1.0 - smoothing) * (this.segment.x1 - this.lastSegment.x1) * fps);
                this.yVelocity1 = (this.yVelocity1 * smoothing) + ((1.0 - smoothing) * (this.segment.y1 - this.lastSegment.y1) * fps);
            }
            else
            {
                this.xVelocity1 = (this.xVelocity1 * smoothing) + ((1.0 - smoothing) * (this.segment.x1 - this.lastSegment.x1) * fps);
                this.yVelocity1 = (this.yVelocity1 * smoothing) + ((1.0 - smoothing) * (this.segment.y1 - this.lastSegment.y1) * fps);
                this.xVelocity2 = (this.xVelocity2 * smoothing) + ((1.0 - smoothing) * (this.segment.x2 - this.lastSegment.x2) * fps);
                this.yVelocity2 = (this.yVelocity2 * smoothing) + ((1.0 - smoothing) * (this.segment.y2 - this.lastSegment.y2) * fps);
            }
        }
Example #2
0
 public BoneData(Segment s)
 {
     this.segment = this.lastSegment = s;
     this.xVelocity1 = this.yVelocity1 = 0;
     this.xVelocity2 = this.yVelocity2 = 0;
     this.timeLastUpdated = DateTime.Now;
 }
Example #3
0
 public void UpdateJointPosition(Microsoft.Kinect.JointCollection joints, JointType j)
 {
     if (j == JointType.HandLeft)
     {
         leftHandPosition = new Point((joints[j].Position.X * this.playerScale) + this.playerCenter.X , (((joints[j].Position.Y * -1) * this.playerScale) + this.playerCenter.Y));
     }
     if (j == JointType.HandRight)
     {
         rightHandPosition = new Point((joints[j].Position.X * this.playerScale) + this.playerCenter.X, (((joints[j].Position.Y * -1) * this.playerScale) + this.playerCenter.Y));
     }
     var seg = new Segment(
         (joints[j].Position.X * this.playerScale) + this.playerCenter.X,
         this.playerCenter.Y - (joints[j].Position.Y * this.playerScale)) { radius = this.playerBounds.Height * ((j == JointType.Head) ? headSize : handSize) / 2 };
     this.UpdateSegmentPosition(j, j, seg);
 }
Example #4
0
 private void UpdateSegmentPosition(JointType j1, JointType j2, Segment seg)
 {
     var bone = new Bone(j1, j2);
     if (this.segments.ContainsKey(bone))
     {
         BoneData data = this.segments[bone];
         data.UpdateSegment(seg);
         this.segments[bone] = data;
     }
     else
     {
         this.segments.Add(bone, new BoneData(seg));
     }
 }
Example #5
0
 public void UpdateBonePosition(Microsoft.Kinect.JointCollection joints, JointType j1, JointType j2)
 {
     var seg = new Segment(
         (joints[j1].Position.X * this.playerScale) + this.playerCenter.X,
         this.playerCenter.Y - (joints[j1].Position.Y * this.playerScale),
         (joints[j2].Position.X * this.playerScale) + this.playerCenter.X,
         this.playerCenter.Y - (joints[j2].Position.Y * this.playerScale)) { radius = Math.Max(3.0, this.playerBounds.Height * boneSize) / 2 };
     this.UpdateSegmentPosition(j1, j2, seg);
 }