コード例 #1
0
        /// <summary>
        /// Updates the current gesture.
        /// </summary>
        /// <param name="spaceBody">The spaceBody.</param>
        /// <returns>A GesturePartResult based on whether the gesture part has been completed.</returns>
        public GesturePartResult Update(SpaceBody spaceBody)
        {
            // Console.WriteLine("X: {0}, Y: {1}, Z: {2}, W: {3}", spaceBody.floorPlane.X, spaceBody.floorPlane.Y, spaceBody.floorPlane.Z, spaceBody.floorPlane.W);

            //if (spaceBody.floorPlane.W != 0)
            //{
            //    return GesturePartResult.Undetermined;
            //}

            Body body = spaceBody.body;

            if ((body.Joints[JointType.FootRight].TrackingState != TrackingState.Tracked && body.Joints[JointType.KneeRight].TrackingState != TrackingState.Tracked)
                || (body.Joints[JointType.FootLeft].TrackingState != TrackingState.Tracked && body.Joints[JointType.KneeLeft].TrackingState == TrackingState.Tracked))
            {
                return GesturePartResult.Failed;
            }

            CameraSpacePoint shoulderPosition = body.Joints[JointType.SpineShoulder].Position;
            CameraSpacePoint corePosition = body.Joints[JointType.SpineBase].Position;
            CameraSpacePoint footerPosition;
            CameraSpacePoint kneePosition;

            if (body.Joints[JointType.FootRight].TrackingState == TrackingState.Tracked && body.Joints[JointType.FootRight].Position.Y < body.Joints[JointType.KneeRight].Position.Y)
            {
                footerPosition = body.Joints[JointType.FootRight].Position;
            }
            else
            {
                footerPosition = body.Joints[JointType.FootLeft].Position;
            }

            if (body.Joints[JointType.KneeLeft].TrackingState == TrackingState.Tracked && body.Joints[JointType.FootLeft].Position.Y < body.Joints[JointType.KneeLeft].Position.Y)
            {
                kneePosition = body.Joints[JointType.KneeLeft].Position;
            }
            else
            {
                kneePosition = body.Joints[JointType.KneeRight].Position;
            }

            double bodyHeight = shoulderPosition.lengthTo(footerPosition);
            double bodyAngle = corePosition.Angle(shoulderPosition, footerPosition);

            if (bodyAngle > 145 && (shoulderPosition.Y - footerPosition.Y) > 0.8 * bodyHeight)
            {
                originBodyLength = bodyHeight;
                originKneeHeight = kneePosition.Y;
                originFooterHeight = footerPosition.Y;
                lyingMaxBodyHeight = (0.9 * originKneeHeight + originFooterHeight * 0.1);
                return GesturePartResult.Succeeded;
            }
            return GesturePartResult.Failed;
        }
コード例 #2
0
ファイル: SpaceGesture.cs プロジェクト: reeonce/Vitruvius
        /// <summary>
        /// Updates the current gesture.
        /// </summary>
        /// <param name="body">The body data.</param>
        public void Update(SpaceBody body)
        {
            if (_isPaused)
            {
                if (_frameCount == _pausedFrameCount)
                {
                    _isPaused = false;
                }

                _frameCount++;
            }

            GesturePartResult result = Segments[_currentSegment].Update(body);

            if (result == GesturePartResult.Succeeded)
            {
                if (_currentSegment + 1 < Segments.Length)
                {
                    _currentSegment++;
                    _frameCount = 0;
                    _pausedFrameCount = MAX_PAUSE_COUNT;
                    _isPaused = true;
                }
                else
                {
                    if (GestureRecognized != null)
                    {
                        GestureRecognized(this, new SpaceGestureEventArgs(GestureType, body.body.TrackingId));
                        Reset();
                    }
                }
            }
            else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE)
            {
                Reset();
            }
            else
            {
                _frameCount++;
                _pausedFrameCount = MAX_PAUSE_COUNT / 2;
                _isPaused = true;
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates the current gesture.
        /// </summary>
        /// <param name="spaceBody">The spaceBody.</param>
        /// <returns>A GesturePartResult based on whether the gesture part has been completed.</returns>
        public GesturePartResult Update(SpaceBody spaceBody)
        {
            Body body = spaceBody.body;

            CameraSpacePoint shoulderPosition = body.Joints[JointType.SpineShoulder].Position;
            CameraSpacePoint corePosition = body.Joints[JointType.SpineBase].Position;

            if (body.Joints[JointType.SpineShoulder].TrackingState != TrackingState.Tracked || body.Joints[JointType.SpineBase].TrackingState != TrackingState.Tracked)
            {
                return GesturePartResult.Undetermined;
            }

            if ((shoulderPosition.Y - FallDownOnFloorSegment1.originFooterHeight) < 0.6 * FallDownOnFloorSegment1.originBodyLength && shoulderPosition.Y > FallDownOnFloorSegment1.originKneeHeight)
            {
                return GesturePartResult.Succeeded;
            }
            else if ((shoulderPosition.Y - FallDownOnFloorSegment1.originFooterHeight) >= 0.6 * FallDownOnFloorSegment1.originBodyLength)
            {
                return GesturePartResult.Undetermined;
            }
            return GesturePartResult.Failed;
        }
コード例 #4
0
        /// <summary>
        /// Updates the current gesture.
        /// </summary>
        /// <param name="spaceBody">The spaceBody.</param>
        /// <returns>A GesturePartResult based on whether the gesture part has been completed.</returns>
        public GesturePartResult Update(SpaceBody spaceBody)
        {
            Body body = spaceBody.body;

            LyingOnFloorSegment previousSegment = null;

            if (previousSegments.Keys.Contains(body.TrackingId))
            {
                previousSegment = previousSegments[body.TrackingId];
            }

            if (previousSegment != null)
            {
                if ((DateTime.Now - previousSegment.updateTime).TotalSeconds > 30)
                {
                    previousSegments[body.TrackingId] = null;
                }
                else
                {
                    totalLength = previousSegment.totalLength;
                    lengthCount = previousSegment.lengthCount;
                }
            }

            if (body.Joints[JointType.ShoulderLeft].TrackingState == TrackingState.Tracked && body.Joints[JointType.ShoulderRight].TrackingState == TrackingState.Tracked)
            {
                double shoulderWidth = body.Joints[JointType.ShoulderLeft].Position.Length(body.Joints[JointType.ShoulderRight].Position);
                totalLength += shoulderWidth * 0.7;
                lengthCount++;
            }

            if (body.Joints[JointType.AnkleLeft].TrackingState == TrackingState.Tracked && body.Joints[JointType.KneeLeft].TrackingState == TrackingState.Tracked)
            {
                double leftLegLength = body.Joints[JointType.AnkleLeft].Position.Length(body.Joints[JointType.KneeLeft].Position);
                totalLength += leftLegLength * 0.7;
                lengthCount++;
            }

            if (body.Joints[JointType.AnkleRight].TrackingState == TrackingState.Tracked && body.Joints[JointType.KneeRight].TrackingState == TrackingState.Tracked)
            {
                double rightLegLength = body.Joints[JointType.AnkleRight].Position.Length(body.Joints[JointType.KneeRight].Position);
                totalLength += rightLegLength * 0.7;
                lengthCount++;
            }

            if (body.Joints[JointType.WristLeft].TrackingState == TrackingState.Tracked && body.Joints[JointType.ElbowLeft].TrackingState == TrackingState.Tracked)
            {
                double leftHandLength = body.Joints[JointType.WristLeft].Position.Length(body.Joints[JointType.ElbowLeft].Position);
                totalLength += leftHandLength;
                lengthCount++;
            }

            if (body.Joints[JointType.WristRight].TrackingState == TrackingState.Tracked && body.Joints[JointType.ElbowRight].TrackingState == TrackingState.Tracked)
            {
                double rightHandLength = body.Joints[JointType.WristRight].Position.Length(body.Joints[JointType.ElbowRight].Position);
                totalLength += rightHandLength;
                lengthCount++;
            }

            updateTime = DateTime.Now;

            double maxBodyHeight = 0;
            if (lengthCount > 0)
            {
                maxBodyHeight = totalLength / lengthCount;
            }

            if (body.Joints[JointType.SpineShoulder].TrackingState != TrackingState.Tracked || body.Joints[JointType.SpineBase].TrackingState != TrackingState.Tracked)
            {
                return GesturePartResult.Undetermined;
            }

            CameraSpacePoint shoulderPosition = body.Joints[JointType.SpineShoulder].Position;
            CameraSpacePoint corePosition = body.Joints[JointType.SpineBase].Position;

            if (spaceBody.floorPlane.X == 0 && spaceBody.floorPlane.Y == 0 && spaceBody.floorPlane.Z == 0)
            {
                return GesturePartResult.Undetermined;
            }

            double coreHeight = spaceBody.floorPlane.Length(corePosition);
            double shoulderHeight = spaceBody.floorPlane.Length(shoulderPosition);

            if (coreHeight < maxBodyHeight && shoulderHeight < maxBodyHeight && coreHeight > -maxBodyHeight * 0.2 && shoulderHeight > -maxBodyHeight * 0.2)
            {
                previousSegments[body.TrackingId] = this;
                return GesturePartResult.Succeeded;
            }
            else if (coreHeight < maxBodyHeight * 1.5 && shoulderHeight < maxBodyHeight * 1.5)
            {
                return GesturePartResult.Undetermined;
            }

            return GesturePartResult.Failed;
        }