Exemplo n.º 1
0
 public BoneData(Segment s)
 {
     seg = segLast = s;
     xVel = yVel = 0;
     xVel2 = yVel2 = 0;
     timeLastUpdated = DateTime.Now;
 }
 public BoneData(Segment s)
 {
     this.Segment = this.LastSegment = s;
     this.XVelocity = this.YVelocity = 0;
     this.XVelocity2 = this.YVelocity2 = 0;
     this.TimeLastUpdated = DateTime.Now;
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
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.XVelocity = (this.XVelocity * Smoothing) + ((1.0 - Smoothing) * (this.Segment.X1 - this.LastSegment.X1) * fps);
                this.YVelocity = (this.YVelocity * Smoothing) + ((1.0 - Smoothing) * (this.Segment.Y1 - this.LastSegment.Y1) * fps);
            }
            else
            {
                this.XVelocity = (this.XVelocity * Smoothing) + ((1.0 - Smoothing) * (this.Segment.X1 - this.LastSegment.X1) * fps);
                this.YVelocity = (this.YVelocity * 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);
            }
        }
Exemplo n.º 6
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)
        {
            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;
            }
        }
Exemplo n.º 7
0
            // Hit testing between this thing and a single segment.  If hit, the center point on
            // the segment being hit is returned, along with the spot on the line from 0 to 1 if
            // a line segment was hit.

            public bool Hit(Segment seg, ref Point ptHitCenter, ref double lineHitLocation)
            {
                double minDxSquared = size + seg.radius;
                minDxSquared *= minDxSquared;

                // See if falling thing hit this body segment
                if (seg.IsCircle())
                {
                    if (SquaredDistance(center.X, center.Y, seg.x1, seg.y1) <= minDxSquared)
                    {
                        ptHitCenter.X = seg.x1;
                        ptHitCenter.Y = seg.y1;
                        lineHitLocation = 0;
                        return true;
                    }
                }
                else
                {
                    double sqrLineSize = SquaredDistance(seg.x1, seg.y1, seg.x2, seg.y2);
                    if (sqrLineSize < 0.5)  // if less than 1/2 pixel apart, just check dx to an endpoint
                    {
                        return (SquaredDistance(center.X, center.Y, seg.x1, seg.y1) < minDxSquared) ? true : false;
                    }
                    else
                    {   // Find dx from center to line
                        double u = ((center.X - seg.x1) * (seg.x2 - seg.x1) + (center.Y - seg.y1) * (seg.y2 - seg.y1)) / sqrLineSize;
                        if ((u >= 0) && (u <= 1.0))
                        {   // Tangent within line endpoints, see if we're close enough
                            double xIntersect = seg.x1 + (seg.x2 - seg.x1) * u;
                            double yIntersect = seg.y1 + (seg.y2 - seg.y1) * u;

                            if (SquaredDistance(center.X, center.Y,
                                xIntersect, yIntersect) < minDxSquared)
                            {
                                lineHitLocation = u;
                                ptHitCenter.X = xIntersect;
                                ptHitCenter.Y = yIntersect; ;
                                return true;
                            }
                        }
                        else
                        {
                            // See how close we are to an endpoint
                            if (u < 0)
                            {
                                if (SquaredDistance(center.X, center.Y, seg.x1, seg.y1) < minDxSquared)
                                {
                                    lineHitLocation = 0;
                                    ptHitCenter.X = seg.x1;
                                    ptHitCenter.Y = seg.y1;
                                    return true;
                                }
                            }
                            else
                            {
                                if (SquaredDistance(center.X, center.Y, seg.x2, seg.y2) < minDxSquared)
                                {
                                    lineHitLocation = 1;
                                    ptHitCenter.X = seg.x2;
                                    ptHitCenter.Y = seg.y2;
                                    return true;
                                }
                            }
                        }
                    }
                    return false;
                }
                return false;
            }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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);
 }
 //??? Whats this do?
 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));
     }
 }
 public void UpdateJointPosition(Microsoft.Kinect.JointCollection joints, JointType j)
 {
     //??? what this do?
     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);
 }
Exemplo n.º 12
0
            // Hit testing between this thing and a single segment.  If hit, the center point on
            // the segment being hit is returned, along with the spot on the line from 0 to 1 if
            // a line segment was hit.
            public bool Hit(Segment seg, ref System.Windows.Point hitCenter, ref double lineHitLocation)
            {
                double minDxSquared = this.Size + seg.Radius;
                minDxSquared *= minDxSquared;

                // See if falling thing hit this body segment
                if (seg.IsCircle())
                {
                    if (SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) <= minDxSquared)
                    {
                        hitCenter.X = seg.X1;
                        hitCenter.Y = seg.Y1;
                        lineHitLocation = 0;
                        return true;
                    }
                }
                else
                {
                    double sqrLineSize = SquaredDistance(seg.X1, seg.Y1, seg.X2, seg.Y2);
                    if (sqrLineSize < 0.5)
                    {
                        // if less than 1/2 pixel apart, just check dx to an endpoint
                        return SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) < minDxSquared;
                    }

                    // Find dx from center to line
                    double u = ((this.Center.X - seg.X1) * (seg.X2 - seg.X1)) + (((this.Center.Y - seg.Y1) * (seg.Y2 - seg.Y1)) / sqrLineSize);
                    if ((u >= 0) && (u <= 1.0))
                    {   // Tangent within line endpoints, see if we're close enough
                        double intersectX = seg.X1 + ((seg.X2 - seg.X1) * u);
                        double intersectY = seg.Y1 + ((seg.Y2 - seg.Y1) * u);

                        if (SquaredDistance(this.Center.X, this.Center.Y, intersectX, intersectY) < minDxSquared)
                        {
                            lineHitLocation = u;
                            hitCenter.X = intersectX;
                            hitCenter.Y = intersectY;
                            return true;
                        }
                    }
                    else
                    {
                        // See how close we are to an endpoint
                        if (u < 0)
                        {
                            if (SquaredDistance(this.Center.X, this.Center.Y, seg.X1, seg.Y1) < minDxSquared)
                            {
                                lineHitLocation = 0;
                                hitCenter.X = seg.X1;
                                hitCenter.Y = seg.Y1;
                                return true;
                            }
                        }
                        else
                        {
                            if (SquaredDistance(this.Center.X, this.Center.Y, seg.X2, seg.Y2) < minDxSquared)
                            {
                                lineHitLocation = 1;
                                hitCenter.X = seg.X2;
                                hitCenter.Y = seg.Y2;
                                return true;
                            }
                        }
                    }

                    return false;
                }

                return false;
            }