public bool fitness24(JointType point1, JointType point2)
        {
            bool p1 = (point1.Equals(JointType.ShoulderLeft) || (point1.Equals(JointType.ElbowLeft)) || (point1.Equals(JointType.WristLeft)) || (point1.Equals(JointType.HandLeft)));
            bool p2 = (point2.Equals(JointType.ShoulderLeft) || (point2.Equals(JointType.ElbowLeft)) || (point2.Equals(JointType.WristLeft)) || (point2.Equals(JointType.HandLeft)));

            return(p1 && p2);
        }
예제 #2
0
 public void addPoint(JointType type, Point point)
 {
     if (type.Equals(JointType.HandLeft))
     {
         leftHand.AddFirst(point);
     }
     else if (type.Equals(JointType.HandRight))
     {
         rightHand.AddFirst(point);
     }
     else
     {
         Console.WriteLine("Joint Type error!");
     }
     while (leftHand.Count > 5)
     {
         leftHand.RemoveLast();
     }
     while (rightHand.Count > 5)
     {
         rightHand.RemoveLast();
     }
 }
예제 #3
0
    // Apply the rotations tracked by kinect to the joints.
    void TransformBone(Int64 userId, JointType joint, int boneIndex, bool flip)
    {
        if (joint.Equals(JointType.Head))
        {
            // bones[boneIndex].localRotation = cart.localRotation;
            return;
        }
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0 || !kinectManager.IsJointTracked(userId, iJoint))
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (SmoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, SmoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
예제 #4
0
 public bool Equals(Joint obj)
 {
     return(JointType.Equals(obj.JointType) && Position.Equals(obj.Position) && TrackingState.Equals(obj.TrackingState));
 }
예제 #5
0
        // Draws a skeleton's bones and joints



        public void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            //  DrawBone(skeleton, drawingContext, JointType.Head, JointType.HipRight);
            // Render Torso

            /*
             *    DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
             *    DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
             *    DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
             *    DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
             *    DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
             *    DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
             *    DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);
             */


            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush     drawBrush = null;
                JointType jointType = joint.JointType;
                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = trackedJointBrush;
                    SkeletonPoint jointPosition = joint.Position;
                    if (joint.TrackingState == JointTrackingState.Tracked)
                    {
                        drawBrush = this.trackedJointBrush;


                        if (jointType.Equals(JointType.ShoulderRight))
                        {
                            pointShoulder = jointPosition;
                        }
                        else if (jointType.Equals(JointType.ElbowRight))
                        {
                            pointElbow = jointPosition;
                        }
                        else if (jointType.Equals(JointType.WristRight))
                        {
                            pointWrist = jointPosition;
                        }
                        else if (jointType.Equals(JointType.HandRight))
                        {
                            pointHand = jointPosition;
                        }
                        if (jointType.Equals(JointType.ShoulderLeft))
                        {
                            pointShoulder2 = jointPosition;
                        }
                        else if (jointType.Equals(JointType.ElbowLeft))
                        {
                            pointElbow2 = jointPosition;
                        }
                        else if (jointType.Equals(JointType.WristLeft))
                        {
                            pointWrist2 = jointPosition;
                        }
                        else if (jointType.Equals(JointType.HandLeft))
                        {
                            pointHand2 = jointPosition;
                        }

                        else if (jointType.Equals(JointType.HipCenter))
                        {
                            pointHipCenter = jointPosition;
                        }
                        else if (jointType.Equals(JointType.HipLeft))
                        {
                            pointHipLeft = jointPosition;
                        }
                        else if (jointType.Equals(JointType.HipRight))
                        {
                            pointHipRight = jointPosition;
                        }
                    }
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }
        }
예제 #6
0
 public bool Equals(JointOrientation obj)
 {
     return(JointType.Equals(obj.JointType) && Orientation.Equals(obj.Orientation));
 }
예제 #7
0
    // Apply the rotations tracked by kinect to the joints.
    void TransformBone(Int64 userId, JointType joint, int boneIndex, bool flip)
    {
        if (joint.Equals(JointType.Head))
        {
           // bones[boneIndex].localRotation = cart.localRotation;
            return;
        }
        Transform boneTransform = bones[boneIndex];
        if(boneTransform == null || kinectManager == null)
            return;

        int iJoint = (int)joint;
        if(iJoint < 0 || !kinectManager.IsJointTracked(userId, iJoint))
            return;

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);
        if(jointRotation == Quaternion.identity)
            return;

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if(SmoothFactor != 0f)
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, SmoothFactor * Time.deltaTime);
        else
            boneTransform.rotation = newRotation;
    }
예제 #8
0
        /// <summary>
        /// Draws a skeleton's bones and joints
        /// </summary>
        /// <param name="skeleton">skeleton to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);

            // Left Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);

            // Right Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);

            // Left Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);

            // Right Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);

            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush     drawBrush = null;
                JointType jointType = joint.JointType;

                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                    SkeletonPoint jointPosition = joint.Position;

                    if (jointType.Equals(JointType.ShoulderRight))
                    {
                        pointShoulder = jointPosition;
                    }
                    else if (jointType.Equals(JointType.ElbowRight))
                    {
                        pointElbow = jointPosition;
                    }
                    else if (jointType.Equals(JointType.WristRight))
                    {
                        pointWrist = jointPosition;
                    }
                    else if (jointType.Equals(JointType.HandRight))
                    {
                        pointHand = jointPosition;
                    }
                    if (jointType.Equals(JointType.ShoulderLeft))
                    {
                        pointShoulder2 = jointPosition;
                    }
                    else if (jointType.Equals(JointType.ElbowLeft))
                    {
                        pointElbow2 = jointPosition;
                    }
                    else if (jointType.Equals(JointType.WristLeft))
                    {
                        pointWrist2 = jointPosition;
                    }
                    else if (jointType.Equals(JointType.HandLeft))
                    {
                        pointHand2 = jointPosition;
                    }

                    else if (jointType.Equals(JointType.HipCenter))
                    {
                        pointHipCenter = jointPosition;
                    }
                    else if (jointType.Equals(JointType.HipLeft))
                    {
                        pointHipLeft = jointPosition;
                    }
                    else if (jointType.Equals(JointType.HipRight))
                    {
                        pointHipRight = jointPosition;
                    }
                    else if (jointType.Equals(JointType.KneeLeft))
                    {
                        pointKneeLeft = jointPosition;
                    }
                    else if (jointType.Equals(JointType.KneeRight))
                    {
                        pointKneeRight = jointPosition;
                    }
                    else if (jointType.Equals(JointType.AnkleLeft))
                    {
                        pointAnkleLeft = jointPosition;
                    }
                    else if (jointType.Equals(JointType.AnkleRight))
                    {
                        pointAnkleRight = jointPosition;
                    }
                    else if (jointType.Equals(JointType.FootLeft))
                    {
                        pointFootLeft = jointPosition;
                    }
                    else if (jointType.Equals(JointType.FootRight))
                    {
                        pointFootRight = jointPosition;
                    }
                }

                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }

            ///Defining Gait parameters
            double pelvis_obliquity = 180 / Math.PI * Math.Atan((pointHipLeft.Y - pointHipRight.Y) / Math.Sqrt(Math.Pow(pointHipLeft.X - pointHipRight.X, 2) + Math.Pow(pointHipLeft.Z - pointHipRight.Z, 2)));
            double pelvic_rotation  = 180 / Math.PI * Math.Atan((pointHipLeft.Z - pointHipRight.Z) / Math.Sqrt(Math.Pow(pointHipLeft.X - pointHipRight.X, 2) + Math.Pow(pointHipLeft.Y - pointHipRight.Y, 2)));

            double hip_ab_right   = 180 / Math.PI * Math.Atan((pointKneeRight.X - pointHipRight.X) / Math.Sqrt(Math.Pow(pointKneeRight.Y - pointHipRight.Y, 2) + Math.Pow(pointKneeRight.Z - pointHipRight.Z, 2)));
            double hip_flex_right = 180 / Math.PI * Math.Atan(-(pointKneeRight.Z - pointHipRight.Z) / Math.Sqrt(Math.Pow(pointKneeRight.Y - pointHipRight.Y, 2) + Math.Pow(pointKneeRight.X - pointHipRight.X, 2)));

            double hip_ab_left   = 180 / Math.PI * Math.Atan(-(pointKneeLeft.X - pointHipLeft.X) / Math.Sqrt(Math.Pow(pointKneeLeft.Y - pointHipLeft.Y, 2) + Math.Pow(pointKneeLeft.Z - pointHipLeft.Z, 2)));
            double hip_flex_left = 180 / Math.PI * Math.Atan(-(pointKneeLeft.Z - pointHipLeft.Z) / Math.Sqrt(Math.Pow(pointKneeLeft.Y - pointHipLeft.Y, 2) + Math.Pow(pointKneeLeft.X - pointHipLeft.X, 2)));

            double knee_flex_right = getAngle(pointHipRight, pointKneeRight, pointAnkleRight);
            double knee_flex_left  = getAngle(pointHipLeft, pointKneeLeft, pointAnkleLeft);

            double ankle_left  = getAngle(pointKneeLeft, pointAnkleLeft, pointFootLeft);
            double ankle_right = getAngle(pointKneeRight, pointAnkleRight, pointFootRight);

            ///Calculating center of mass
            Coordinate CM = new Coordinate();

            CM = center_mass(pointAnkleLeft, pointAnkleRight, pointFootLeft, pointFootRight, pointHand, pointHand2, pointHipCenter, pointHipLeft, pointHipRight, pointKneeLeft, pointKneeRight, pointShoulder, pointShoulder2, pointElbow, pointElbow2, pointWrist, pointWrist2);

            ///Timestamp
            DateTime timestamp;

            timestamp = DateTime.Now;

            ///Calculating velocity of center of mass
            Coordinate velocity     = new Coordinate();
            Coordinate acceleration = new Coordinate();

            velocity     = getVelocity(CM, timestamp, prevCM, timestampPrev);
            acceleration = getAcceleration(prevCM, earlyCM, CM, timestampPrev, timestampEarly, timestamp);

            prev_velCM     = velocity;
            timestampEarly = timestampPrev;
            timestampPrev  = timestamp;
            earlyCM        = prevCM;
            prevCM         = CM;

            ///Calculating GRF
            Coordinate GRF = new Coordinate();

            GRF = getGRF(acceleration, Mass);

            ///For debugging purposes only

            /*System.Console.WriteLine("acc is " + acceleration.X + " " + acceleration.Y + " " + acceleration.Z);
             * System.Console.WriteLine("Coordinate is " + pointHipCenter.X + " " + pointHipCenter.Y + " " + pointHipCenter.Z );
             * System.Console.WriteLine("velocity is " + velocity.X + " " + velocity.Y + " " + velocity.Z);
             * System.Console.WriteLine("GRF is " + GRF.X + " " + GRF.Y + " " + GRF.Z);*/

            ///Add Gait parameters to the lists
            list1.Add(pelvis_obliquity);
            list2.Add(hip_ab_left);
            list3.Add(hip_ab_right);
            list4.Add(knee_flex_left);
            list5.Add(knee_flex_right);
            list6.Add(hip_flex_left);
            list7.Add(hip_flex_right);
            list8.Add(ankle_left);
            list9.Add(ankle_right);
            list10.Add(pelvic_rotation);
            list11.Add(GRF);
        }