示例#1
0
        public void gameLogic(JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {
                if (joint.ID == JointID.HandRight || joint.ID == JointID.HandLeft)
                {
                    Vector2 jointPosition = getScreenPosition(joint);

                    // Check if user made any selections
                    Selection selection = checkSolutionIntersection(jointPosition);

                    if (selection == Selection.Correct)
                    {
                        correctChoice(jointPosition);
                    }
                    else if (selection == Selection.Wrong)
                    {
                        wrongChoice();
                    }

                    /*
                     * //task: why put !questionIsCorrect? as checking variable?
                     * if (!questionIsCorrect && checkSolutionIntersection(jointPosition)) // User selects the right choice
                     * {
                     *  correctChoice(jointPosition);
                     * }
                     * else if (checkSolutionIntersection(jointPosition)) // User selects wrong choice
                     * {
                     *  wrongChoice();
                     * }*/
                }
            }
        }
示例#2
0
        public void gameLogic(JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {
                //Debugger
                if (debuggerOn)
                {
                    if (joint.ID == JointID.HipCenter)
                    {
                        Vector2 jointPosition = getScreenPosition(joint);
                        shapeDebugger.setPosition((jointPosition));
                    }
                }


                if (IsActive) // Process game logic if the screen is active and infront .
                {
                    if (joint.ID == JointID.HandRight || joint.ID == JointID.HandLeft)
                    {
                        Vector2 jointPosition = getScreenPosition(joint);

                        if (!questionIsCorrect && checkSolutionIntersection(jointPosition))
                        {
                            correctChoice(jointPosition);
                        }
                        else
                        {
                            wrongChoice();
                        }
                    }
                }
            }
        }
        private static string calculatePercentage(JointsCollection joints)
        {
            double       percentage = 0;
            List <Joint> myJoints   = new List <Joint>();

            myJoints.Add(joints[JointID.HipCenter]);
            myJoints.Add(joints[JointID.HipLeft]);
            myJoints.Add(joints[JointID.HipRight]);
            myJoints.Add(joints[JointID.ElbowLeft]);
            myJoints.Add(joints[JointID.ElbowRight]);
            myJoints.Add(joints[JointID.ShoulderCenter]);
            myJoints.Add(joints[JointID.ShoulderRight]);
            myJoints.Add(joints[JointID.ShoulderLeft]);
            myJoints.Add(joints[JointID.Spine]);
            myJoints.Add(joints[JointID.Head]);

            for (int i = 0; i < myJoints.Count; i++)
            {
                if (myJoints[i].Position.Y < -0.5)
                {
                    percentage += ((double)100) / myJoints.Count;
                }
            }
            // MICHI: We need to add weights above (the head is not supposed to be in the floor but the hips may be)
            //and 2 levels of high.

            string result = "Falling probability = " + percentage.ToString() + "%.";

            return(result);
        }
示例#4
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            //get the first tracked skeleton
            SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();

            currentJoints = skeleton.Joints;
            SetEllipsePosition(RHand, skeleton.Joints[JointID.HandRight]);

            if (RightHandX > 640.0 * 5 / 6 && RightHandY < 480.0 * 1 / 6)
            {
                currentAshX = 3;
                currentAshY = 3;
            }
            else if (RightHandX > 640.0 * 5 / 6)
            {
                int newAshX = currentAshX + 1;
                int newAshY = currentAshY;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandX < 640.0 * 1 / 6)
            {
                int newAshX = currentAshX - 1;
                int newAshY = currentAshY;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandY > 480.0 * 5 / 6)
            {
                int newAshX = currentAshX;
                int newAshY = currentAshY + 1;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandY < 480.0 * 1 / 6)
            {
                int newAshX = currentAshX;
                int newAshY = currentAshY - 1;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            GetAshHouse(currentAshX, currentAshY);
        }
示例#5
0
 public static Vector3D vectorFromJoint(JointID id, JointsCollection kinectJoints)
 {
     Vector3D v = new Vector3D();
     v.X = kinectJoints[id].Position.X;
     v.Y = kinectJoints[id].Position.Y;
     v.Z = kinectJoints[id].Position.Z;
     return v;
 }
示例#6
0
        // place this in the main game loop
        public void gameLogic(JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {
                //DEBUGGING STUFF
                if (joint.ID == JointID.HipCenter)
                {
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, 640, 480);
                    this.shapeDebugger.setPosition((jointPosition + kinectFrameOffset));
                }

                if (joint.ID == JointID.HandRight)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, 640, 480);
                    //solutionObjectReplica.Position = jointPosition;
                    if (kennyDebug)
                    {
                        if (kennyDebug)
                        {
                            updateHands("right", (jointPosition + kinectFrameOffset));
                        }
                    }

                    if (!questionIsCorrect && checkSolutionIntersection((jointPosition + kinectFrameOffset)))
                    {
                        correctChoice((jointPosition + kinectFrameOffset));
                    }
                    else
                    {
                        wrongChoice();
                    }
                }

                if (joint.ID == JointID.HandLeft)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, 640, 480);

                    //solutionObjectReplica.Position = jointPosition;

                    if (kennyDebug)
                    {
                        updateHands("left", (jointPosition + kinectFrameOffset));
                    }

                    if (!questionIsCorrect && checkSolutionIntersection((jointPosition + kinectFrameOffset)))
                    {
                        particleEffect.Trigger(jointPosition); //To-do:Victor Please help to confirm if this can be remove as particleEffect.Trigger is already called in correctChoice
                        correctChoice((jointPosition + kinectFrameOffset));
                    }
                    else
                    {
                        wrongChoice();
                    }
                }
            }
        }
示例#7
0
 public void debuggerSkeleton(JointsCollection joints)
 {
     foreach (Joint joint in joints)
     {
         if (joint.ID == JointID.HipCenter)
         {
             Vector2 jointPosition = getScreenPosition(joint);
             shapeDebugger.setPosition((jointPosition));
         }
     }
 }
示例#8
0
        public static Polyline GetBodySegment(Runtime nui, JointsCollection joints, Brush brush,
                                              IEnumerable<JointID> jointIds, int width, int height)
        {
            var points = new PointCollection();

            foreach (var id in jointIds)
            {
                points.Add(GetDisplayPosition(nui, joints[id], width, height));
            }

            var polyline = new Polyline {Points = points, Stroke = brush, StrokeThickness = 5};
            return polyline;
        }
示例#9
0
        //--------------------------------
        // 各ユーザのジョイント情報を取得
        //--------------------------------
        void GetJoints(int playerIndex, JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {
                GetJoint(playerIndex, joint);
            }

            /*
             * foreach (Joint joint in joints)
             * {
             *  Trace.WriteLine(string.Format("{0} {1} {2}", joint.ID, joints2D[playerIndex][joint.ID].X, joints2D[playerIndex][joint.ID].Y));
             * }
             */
        }
        Polyline getBodySegment(JointsCollection joints, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);
            for (int i = 0; i < ids.Length; ++i)
            {
                points.Add(getDisplayPosition(joints[ids[i]]));
            }

            Polyline polyline = new Polyline();
            polyline.Points = points;
            polyline.Stroke = new SolidColorBrush(Color.FromRgb(51, 255, 51));
            polyline.StrokeThickness = 10;
            return polyline;
        }
示例#11
0
        /// <summary>
        /// Works out how to draw a line ('bone') for sent Joints
        /// </summary>
        /// <param name="joints">Kinect NUI Joints</param>`
        /// <param name="brush">The brush we'll use to colour the joints</param>
        /// <param name="ids">The JointsIDs we're interested in</param>
        /// <returns>A line or lines</returns>
        private Polyline GetBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            var points = new PointCollection(ids.Length);
            foreach (JointID t in ids)
            {
                points.Add(GetDisplayPosition(joints[t]));
            }

            var polyline = new Polyline();
            polyline.Points = points;
            polyline.Stroke = brush;
            polyline.StrokeThickness = 5;
            return polyline;
        }
示例#12
0
        Polyline GetBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);

            foreach (JointID t in ids)
            {
                points.Add(GetDisplayPosition(joints[t]));
            }

            Polyline polyline = new Polyline {
                Points = points, Stroke = brush, StrokeThickness = 5
            };

            return(polyline);
        }
示例#13
0
        Polyline getBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);

            for (int i = 0; i < ids.Length; ++i)
            {
                points.Add(getDisplayPosition(joints[ids[i]]));
            }

            Polyline polyline = new Polyline();

            polyline.Points          = points;
            polyline.Stroke          = brush;
            polyline.StrokeThickness = 5;
            return(polyline);
        }
        /// <summary>
        /// Works out how to draw a line ('bone') for sent Joints
        /// </summary>
        /// <param name="joints">Kinect NUI Joints</param>
        /// <param name="brush">The brush we'll use to colour the joints</param>
        /// <param name="ids">The JointsIDs we're interested in</param>
        /// <returns>A line or lines</returns>
        private Polyline GetBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            var points = new PointCollection(ids.Length);

            foreach (JointID t in ids)
            {
                points.Add(GetDisplayPosition(joints[t]));
            }

            var polyline = new Polyline();

            polyline.Points          = points;
            polyline.Stroke          = brush;
            polyline.StrokeThickness = 5;
            return(polyline);
        }
        bool ProcessFrame(SkeletonFrame frame)
        {
            bool tracking = false;

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton == null)
                {
                    continue;
                }

                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                tracking = true;

                JointsCollection joints = skeleton.Joints;

                Joint rightHand = joints[JointID.HandRight];
                Joint leftHand  = joints[JointID.HandLeft];

                var joinCursorHand = (rightHand.Position.Y > leftHand.Position.Y) ? rightHand : leftHand;

                float posX = joinCursorHand.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight).Position.X;
                float posY = joinCursorHand.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight).Position.Y;

                var kinect = Runtime.Kinects.FirstOrDefault();
                swipeGestureRecognizer.Add(joinCursorHand.Position, kinect.SkeletonEngine);

                var scaledCursorJoint = new Joint
                {
                    TrackingState = JointTrackingState.Tracked,
                    Position      = new Microsoft.Research.Kinect.Nui.Vector
                    {
                        X = posX,
                        Y = posY,
                        Z = joinCursorHand.Position.Z
                    }
                };

                OnButtonLocationChanged(kinectButton, (int)scaledCursorJoint.Position.X, (int)scaledCursorJoint.Position.Y);
            }

            return(tracking);
        }
        void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            if (e.SkeletonFrame.Skeletons.Count() == 0)
            {
                return;
            }

            SkeletonFrame skeletonSet = e.SkeletonFrame;

            SkeletonData firstPerson = (from s in skeletonSet.Skeletons
                                        where s.TrackingState == SkeletonTrackingState.Tracked
                                        orderby s.UserIndex descending
                                        select s).FirstOrDefault();

            if (firstPerson == null)
            {
                return;
            }

            JointsCollection joints = firstPerson.Joints;

            Joint rightHand = joints[JointID.HandRight];
            Joint leftHand  = joints[JointID.HandLeft];

            //find which hand is being used for cursor - is the user right handed or left handed?
            var joinCursorHand = (rightHand.Position.Y > leftHand.Position.Y)
                                                        ? rightHand
                                                        : leftHand;

            float posX = joinCursorHand.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY).Position.X;
            float posY = joinCursorHand.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY).Position.Y;

            Joint scaledCursorJoint = new Joint
            {
                TrackingState = JointTrackingState.Tracked,
                Position      = new Microsoft.Research.Kinect.Nui.Vector
                {
                    X = posX,
                    Y = posY,
                    Z = joinCursorHand.Position.Z
                }
            };

            OnButtonLocationChanged(kinectButton, buttons, gestureButtons, gestureCombos, (int)scaledCursorJoint.Position.X, (int)scaledCursorJoint.Position.Y);
        }
示例#17
0
        // place this in the main game loop
        public void gameLogic(JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {
                if (joint.ID == JointID.HandRight)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                    //solutionObjectReplica.Position = jointPosition;

                    if (checkSolutionIntersection(jointPosition))
                    {
                        correctChoice(jointPosition);
                    }
                    else
                    {
                        wrongChoice();
                    }
                }

                if (joint.ID == JointID.HandLeft)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                    //solutionObjectReplica.Position = jointPosition;

                    if (checkSolutionIntersection(jointPosition))
                    {
                        particleEffect.Trigger(jointPosition); //To-do:Victor Please help to confirm if this can be remove as particleEffect.Trigger is already called in correctChoice
                        correctChoice(jointPosition);
                    }
                    else
                    {
                        wrongChoice();
                    }
                }
            }
        }
示例#18
0
        // Initialize a new HumanSkeleton model with the given observed joints
        public HumanSkeleton(JointsCollection kinectJoints)
        {
            this.kinectJoints = kinectJoints;
            Joint shoulderCenter = kinectJoints[JointID.ShoulderCenter];
            Joint spine = kinectJoints[JointID.Spine];
            leftShoulder = new HumanShoulder(shoulderCenter, spine,
                kinectJoints[JointID.ShoulderLeft],
                kinectJoints[JointID.ElbowLeft],
                kinectJoints[JointID.WristLeft], true);

            LeftShoulderPitch = leftShoulder.Pitch;
            LeftShoulderYaw = leftShoulder.Yaw;
            LeftShoulderRoll = leftShoulder.Roll;

            rightShoulder = new HumanShoulder(shoulderCenter, spine,
                kinectJoints[JointID.ShoulderRight],
                kinectJoints[JointID.ElbowRight],
                kinectJoints[JointID.WristRight], false);

            RightShoulderPitch = rightShoulder.Pitch;
            RightShoulderYaw = rightShoulder.Yaw;
            RightShoulderRoll = rightShoulder.Roll;

            leftElbow = new HumanElbow(
                kinectJoints[JointID.ShoulderLeft],
                kinectJoints[JointID.ElbowLeft],
                kinectJoints[JointID.WristLeft]);

            LeftElbowYaw = leftElbow.Yaw;

            rightElbow = new HumanElbow(
                kinectJoints[JointID.ShoulderRight],
                kinectJoints[JointID.ElbowRight],
                kinectJoints[JointID.WristRight]);

            RightElbowYaw = rightElbow.Yaw;
        }
 public KinectRawFeatureSet(JointsCollection joints)
 {
     SkeletonJoints = joints.OfType<Joint>();
 }
示例#20
0
        Polyline GetBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            var points = new PointCollection(ids.Length);
            for (int i = 0; i < ids.Length; ++i)
            {
                points.Add(GetDisplayPosition(joints[ids[i]]));
            }

            var polyline = new Polyline();
            polyline.Points = points;
            polyline.Stroke = brush;
            polyline.StrokeThickness = 5;
            return polyline;
        }
 public void Iteration(JointsCollection Joints)
 {
     #region Swype
     if (Mode == RecognitionMode.SWYPE)
     {
         RActive = RightHand.IsActive(Joints[JointID.HandRight].Position, Joints[JointID.ShoulderCenter].Position.Z);
         LActive = LeftHand.IsActive(Joints[JointID.HandLeft].Position, Joints[JointID.ShoulderCenter].Position.Z);
         if (RActive && LActive)
         {
             if (InDoubleGesture)
             {
                 ProceedDoubleGesture(Joints[JointID.HandRight].Position, Joints[JointID.HandLeft].Position);
             }
             else
             {
                 RightHand.CompleteGesture();
                 LeftHand.CompleteGesture();
                 InDoubleGesture = true;
                 InitDoubleGesture(Joints[JointID.HandRight].Position, Joints[JointID.HandLeft].Position);
             }
             return;
         }
         if (RActive && !LActive)
         {
             RightHand.ProceedGesture();
             return;
         }
         if (!RActive && LActive)
         {
             LeftHand.ProceedGesture();
             return;
         }
     }
     #endregion
     #region Cursor
     if (Mode == RecognitionMode.CURSOR)
     {
         if ((RightHand.NearEnd < (Joints[JointID.ShoulderCenter].Position.Z - Joints[JointID.HandRight].Position.Z)) && ((Joints[JointID.ShoulderCenter].Position.Z - Joints[JointID.HandRight].Position.Z) < RightHand.FarEnd))
         {
             var scaledJoint = Joints[JointID.HandRight].ScaleTo(PrimaryScreenWidth, PrimaryScreenHeight, .3f, .2f);
             MouseCoords(this, new PointEventArgs(new Point(scaledJoint.Position.X, scaledJoint.Position.Y)));
             return;
         }
         if ((LeftHand.NearEnd < (Joints[JointID.ShoulderCenter].Position.Z - Joints[JointID.HandLeft].Position.Z)) && ((Joints[JointID.ShoulderCenter].Position.Z - Joints[JointID.HandLeft].Position.Z) < LeftHand.FarEnd))
         {
             var scaledJoint = Joints[JointID.HandLeft].ScaleTo(PrimaryScreenWidth, PrimaryScreenHeight, .3f, .2f);
             MouseCoords(this, new PointEventArgs(new Point(scaledJoint.Position.X, scaledJoint.Position.Y)));
             return;
         }
     }
     #endregion
     #region Joystick
     if (Mode == RecognitionMode.JOYSTICK)
     {
     }
     #endregion
 }
        private Polyline getBodySegment(JointsCollection joints, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);
            for (int i = 0; i < ids.Length; ++i)
            {
                points.Add(getDisplayPosition(joints[ids[i]]));
            }

            Polyline polyline = new Polyline();
            polyline.Points = points;

            if (gestureDetected)
            {
                if (isJoystickLeftSet || isJoystickRightSet || isLeverSet)
                {
                    polyline.Stroke = new SolidColorBrush(Colors.Goldenrod);
                    lblGestureInfo.Foreground = new SolidColorBrush(Colors.Goldenrod);
                }
                else if (!isJoystickLeftSet || !isJoystickRightSet || !isLeverSet)
                {
                    polyline.Stroke = new SolidColorBrush(Colors.Goldenrod);
                    lblGestureInfo.Foreground = new SolidColorBrush(Colors.Goldenrod);
                }
            }
            else if (!gestureDetected)
            {
                if (isJoystickRightSet || isJoystickLeftSet || isLeverSet)
                {
                    polyline.Stroke = new SolidColorBrush(Colors.DodgerBlue);
                    lblGestureInfo.Foreground = new SolidColorBrush(Colors.DodgerBlue);
                }
                else
                {
                    polyline.Stroke = new SolidColorBrush(Colors.Fuchsia);
                    lblGestureInfo.Foreground = new SolidColorBrush(Colors.Fuchsia);
                }
            }

            polyline.StrokeThickness = cvsSkeleton.Height / 50;
            return polyline;
        }
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            //get the first tracked skeleton
            SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();

            currentJoints = skeleton.Joints;
            SetEllipsePosition(RHand, skeleton.Joints[JointID.HandRight]);

            if (RightHandX > 640.0 * 5 / 6 && RightHandY < 480.0 * 1 / 6)
            {
                currentAshX = 3;
                currentAshY = 3;
            }
            else if (RightHandX > 640.0 * 5 / 6)
            {
                int newAshX = currentAshX + 1;
                int newAshY = currentAshY;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandX < 640.0 * 1 / 6)
            {
                int newAshX = currentAshX - 1;
                int newAshY = currentAshY;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandY > 480.0 * 5 / 6)
            {
                int newAshX = currentAshX;
                int newAshY = currentAshY + 1;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            else if (RightHandY < 480.0 * 1 / 6)
            {
                int newAshX = currentAshX;
                int newAshY = currentAshY - 1;
                if (worksInAshHouseUpstairs(newAshX, newAshX))
                {
                    currentAshX = newAshX;
                    currentAshY = newAshY;
                }
            }
            GetAshHouse(currentAshX, currentAshY);
        }
示例#24
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {


            debugMsg.Write("nui_SkeletonFrameReady()...", DebugMsg.nui_SkeletonFrameReady);

            
            foreach (var skeleton in e.SkeletonFrame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    isKinectTracking = false;
                    continue;
                }

                isKinectTracking = true;
                //in tracked state
                Joints = skeleton.Joints;
                foreach (Joint joint in Joints)
                {
                    //loosely checked
                    if ( (joint.Position.W < 0.8f) && (joint.TrackingState != JointTrackingState.NotTracked) )
                    {
                        //no enough tracked quality
                        isKinectTracking = false;
                        UnsetJointTracked(joint.ID);
                        continue;
                    }

                    //tracked!!!
                    SetJointTracked(joint.ID);

                    //translated to Screen XYZ
                    if (joint.Position.Z >= minDistance && joint.Position.Z <= maxDistance)
                    {

                        //record 3D position
                        JointPosition3[(int)joint.ID] = joint.Position;

                        //translate into real 2D screen
                        JointPosition2[(int)joint.ID] = getDisplayPosition(joint);

                        isKinectTracking = true;

                        //call handler
                        if (handlerClientPositionChanged[(int)joint.ID] != null)
                            OnPositionChanged(joint.ID);
                        
                    }
                }
            }

            debugMsg.WriteLine("OKOK!", DebugMsg.nui_SkeletonFrameReady);

        }        
示例#25
0
        // place this in the main game loop
        public void gameLogic(JointsCollection joints)
        {
            foreach (Joint joint in joints)
            {

                if (joint.ID == JointID.HandRight)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                    //solutionObjectReplica.Position = jointPosition;

                    if (checkSolutionIntersection(jointPosition))
                    {
                        correctChoice(jointPosition);
                    }
                    else
                    {
                        wrongChoice();
                    }

                }

                if (joint.ID == JointID.HandLeft)
                {
                    // Place solution object replica on the person's hand
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                    //solutionObjectReplica.Position = jointPosition;

                    if (checkSolutionIntersection(jointPosition))
                    {
                        particleEffect.Trigger(jointPosition);
                        correctChoice(jointPosition);
                    }
                    else
                    {
                        wrongChoice();
                    }

                }

            }
        }
        private string getUdpMessageString(JointsCollection joints)
        {
            foreach (Joint j in joints)
            {
                switch (j.ID)
                {
                    case JointID.HandLeft:
                        lh = j;
                        break;
                    case JointID.HandRight:
                        rh = j;
                        break;
                    case JointID.ElbowLeft:
                        le = j;
                        break;
                    case JointID.ElbowRight:
                        re = j;
                        break;
                    case JointID.ShoulderLeft:
                        ls = j;
                        break;
                    case JointID.ShoulderRight:
                        rs = j;
                        break;
                    case JointID.Spine:
                        tt = j;
                        break;
                    case JointID.HipLeft:
                        li = j;
                        break;
                    case JointID.HipRight:
                        ri = j;
                        break;
                    case JointID.KneeLeft:
                        lk = j;
                        break;
                    case JointID.KneeRight:
                        rk = j;
                        break;
                    case JointID.FootLeft:
                        lf = j;
                        break;
                    case JointID.FootRight:
                        rf = j;
                        break;
                    case JointID.Head:
                        hh = j;
                        break;
                }
            }

            StringBuilder sb = new StringBuilder();
            sb.Append(lh, "lh")
              .Append(rh, "rh")
              .Append(le, "le")
              .Append(re, "re")
              .Append(ls, "ls")
              .Append(rs, "rs")
              .Append(tt, "tt")
              .Append(li, "li")
              .Append(ri, "ri")
              .Append(lk, "lk")
              .Append(rk, "rk")
              .Append(lf, "lf")
              .Append(rf, "rf")
              .Append(hh, "hh");

            return sb.ToString();
        }
示例#27
0
 public void UpdateJointPosition(JointsCollection joints, JointID j)
 {
     var seg = new PlayerUtils.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 UpdateOrCreateJoints(JointsCollection joints)
 {
     if (joints != null)
         foreach (Joint joint in joints)
             UpdateOrCreateJoint(joint);
 }
示例#29
0
        Polyline GetBodySegment(JointsCollection joints, Brush brush, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);
            foreach (JointID t in ids)
            {
                points.Add(GetDisplayPosition(joints[t]));
            }

            Polyline polyline = new Polyline { Points = points, Stroke = brush, StrokeThickness = 5 };
            return polyline;
        }
示例#30
0
        private Point[] GetBodySegment(JointsCollection joints, params JointID[] ids)
        {
            var points = new Point[ids.Length];
            var ix = 0;
            foreach (JointID t in ids)
            {
                points[ix] = GetDisplayPosition(joints[t]);
                ix++;
            }

            return points;
        }
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame skeletonFrame = e.SkeletonFrame;
            int           iSkeleton     = 0;

            Brush[] brushes = new Brush[6];
            brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0));
            brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255));
            brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64));
            brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255));
            brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255));

            skeleton.Children.Clear();
            foreach (SkeletonData data in skeletonFrame.Skeletons)
            {
                if (SkeletonTrackingState.Tracked == data.TrackingState)
                {
                    // Draw bones
                    Brush brush = brushes[iSkeleton % brushes.Length];
                    skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.Spine, JointID.ShoulderCenter, JointID.Head));
                    skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderLeft, JointID.ElbowLeft, JointID.WristLeft, JointID.HandLeft));
                    skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderRight, JointID.ElbowRight, JointID.WristRight, JointID.HandRight));
                    skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipLeft, JointID.KneeLeft, JointID.AnkleLeft, JointID.FootLeft));
                    skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipRight, JointID.KneeRight, JointID.AnkleRight, JointID.FootRight));

                    JointsCollection jc = data.Joints;

                    StringBuilder sb = new StringBuilder();
                    StringBuilder up = new StringBuilder();
                    StringBuilder lo = new StringBuilder();
                    int           k  = 0;
                    foreach (JointID jid in Enum.GetValues(typeof(JointID)))
                    {
                        if (jid != JointID.Count)
                        {
                            k++;
                            Microsoft.Research.Kinect.Nui.Vector v = jc[jid].Position;
                            if (k <= 4)
                            {
                                sb.Append(string.Format("{0} = {1}, {2}, {3}\n", jid, v.X, v.Y, v.Z));
                            }
                            else if (k <= 12)
                            {
                                up.Append(string.Format("{0} = {1}, {2}, {3}\n", jid, v.X, v.Y, v.Z));

                                if (k == 8)//HandLeft
                                {
                                    HandLY = v.Y;
                                    up.Append(string.Format("\n"));
                                }
                                if (k == 9)//ShoulderRight
                                {
                                    ShouRX = v.X;
                                    ShouRY = v.Y;
                                    ShouRZ = v.Z;
                                }
                                if (k == 10)//ElbowRight
                                {
                                    ElRX = v.X;
                                    ElRY = v.Y;
                                    ElRZ = v.Z;
                                }
                                if (k == 11)//WristRight
                                {
                                    WrRX = v.X;
                                    WrRY = v.Y;
                                    WrRZ = v.Z;
                                }
                                if (k == 12)//HandRight
                                {
                                    HandRX = v.X;
                                    HandRY = v.Y;
                                    HandRZ = v.Z;
                                }
                            }
                            else if (k <= 20)
                            {
                                lo.Append(string.Format("{0} = {1}, {2}, {3}\n", jid, v.X, v.Y, v.Z));
                                if (k == 13)//HipLeft
                                {
                                    HipLY = v.Y;
                                }
                                if (k == 16)
                                {
                                    lo.Append(string.Format("\n"));
                                }
                            }
                        }
                    }

                    middle.Text = sb.ToString();
                    upper.Text  = up.ToString();
                    lower.Text  = lo.ToString();

                    //Arduino Control 1st Rotation Angle
                    double angROT1 = Math.Atan((HandRX - ShouRX) / (HandRY - ShouRY));
                    if (angROT1 < 0)
                    {
                        angROT1 = 0.5 * Math.PI - angROT1;
                    }
                    arduino.analogWrite(3, Convert.ToInt32(Math.Floor(angROT1 * 180 / Math.PI)));

                    //Arduino Control 2nd Rotation Angle (Shoulder)
                    double angROT2 = Math.Atan((ShouRZ - ElRZ) / Math.Sqrt(Math.Pow((ElRY - ShouRY), 2) + Math.Pow((ElRX - ShouRX), 2)));
                    if (angROT2 < 0)
                    {
                        angROT2 += Math.PI;
                    }
                    if (ElRX < ShouRX)
                    {
                        angROT2 = Math.PI - angROT2;
                    }
                    int degRot2 = Convert.ToInt32(Math.Floor(angROT2 * 180 / Math.PI));
                    //Constrained by mechanism
                    if (degRot2 < 25)
                    {
                        degRot2 = 25;
                    }
                    else if (degRot2 > 155)
                    {
                        degRot2 = 155;
                    }
                    arduino.analogWrite(5, degRot2);

                    //Arduino Control 3rd Rotation Angle (Elbo)
                    double ax      = HandRX - ElRX;
                    double ay      = HandRY - ElRY;
                    double az      = HandRZ - ElRZ;
                    double bx      = ElRX - ShouRX;
                    double by      = ElRY - ShouRY;
                    double bz      = ElRZ - ShouRZ;
                    double angROT3 = Math.Acos((ax * bx + ay * by + az * bz) / Math.Sqrt(ax * ax + ay * ay + az * az) / Math.Sqrt(bx * bx + by * by + bz * bz));
                    arduino.analogWrite(10, Convert.ToInt32(Math.Floor(angROT3 * 180 / Math.PI)));

                    //Arduino Control 4th Rotation Angle (Grab)
                    if (HandLY > HipLY)
                    {
                        arduino.analogWrite(9, 30);
                    }
                    else
                    {
                        arduino.analogWrite(9, 110);
                    }

                    // Draw joints
                    foreach (Joint joint in data.Joints)
                    {
                        Point jointPos  = getDisplayPosition(joint);
                        Line  jointLine = new Line();
                        jointLine.X1              = jointPos.X - 3;
                        jointLine.X2              = jointLine.X1 + 6;
                        jointLine.Y1              = jointLine.Y2 = jointPos.Y;
                        jointLine.Stroke          = jointColors[joint.ID];
                        jointLine.StrokeThickness = 6;
                        skeleton.Children.Add(jointLine);
                    }
                }
                iSkeleton++;
            } // for each skeleton
        }