Пример #1
0
        /*
         * private double getHorizonatalAngle(Skeleton skeleton, ExerciseVariant exercisevarinat)
         * {
         *  Joint centerPoint, leftPoint, rightPoint;
         *  switch (exercisevarinat)
         *  {
         *      case ExerciseVariant.HandLeft:
         *          leftPoint = skeleton.Joints[JointType.ShoulderRight];
         *          centerPoint = skeleton.Joints[JointType.ShoulderLeft];
         *          rightPoint = skeleton.Joints[JointType.HandLeft];
         *          break;
         *      case ExerciseVariant.HandRight:
         *      default:
         *          leftPoint = skeleton.Joints[JointType.ShoulderLeft];
         *          centerPoint = skeleton.Joints[JointType.ShoulderRight];
         *          rightPoint = skeleton.Joints[JointType.HandRight];
         *          break;
         *  }
         *
         *  return -1 * (MathsHelper.AngleBetweenJoints(leftPoint, centerPoint, rightPoint, Axis.X, Axis.Z) - 180); // 0 when straight angle, increase when twisting
         * }
         */

        /*
         * private double getWirstShoulderDistance(Skeleton skeleton, ExerciseVariant exercisevarinat, Axis axis)
         * {
         *  Joint firstPoint, secondPoint;
         *  switch (exercisevarinat)
         *  {
         *      case ExerciseVariant.HandLeft:
         *          firstPoint = skeleton.Joints[JointType.ShoulderLeft];
         *          secondPoint = skeleton.Joints[JointType.WristLeft];
         *          break;
         *      case ExerciseVariant.HandRight:
         *      default:
         *          firstPoint = skeleton.Joints[JointType.ShoulderRight];
         *          secondPoint = skeleton.Joints[JointType.WristRight];
         *          break;
         *  }
         *
         *  return MathsHelper.DistanceBetweenPoints(firstPoint, secondPoint, axis) ;
         * }
         */

        private void UpdateLabels(Skeleton skeleton, ExerciseVariant exercisevariant)
        {
            horizontalDistanceLabel.Content = String.Format("{0:0.0} cm", hand.getProtrudingDistance(skeleton, exercisevariant) * 100);
            verticalDistanceLabel.Content   = String.Format("{0:0.0} cm", hand.getLiftDistance(skeleton, exercisevariant) * -100);
            angleLabel.Content      = String.Format("{0:0}°", hand.getHorizonatalAngle(skeleton, exercisevariant)); // 0, 2, 4, ...
            RepetitionsCounter.Text = CountRepetitionsLeft().ToString();
        }
Пример #2
0
        public double getProtrudingDistance(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            Joint  handJoint        = GetGloveJoint(skeleton, exerciseVariant);
            Joint  shoulderJoint    = GetShoulderJoint(skeleton, exerciseVariant);
            double protrudingLength = Math.Abs(MathsHelper.DistanceBetweenPoints(shoulderJoint, handJoint, Axis.X, Axis.Z));

            return(protrudingLength);
        }
Пример #3
0
        public double getVerticalPosition(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            Joint        gloveJoint     = GetGloveJoint(skeleton, exerciseVariant);
            const double posYCorrection = -0.2f;
            double       diffY          = gloveJoint.Position.Y - skeleton.Joints[JointType.ShoulderCenter].Position.Y + posYCorrection;

            return(diffY);
        }
Пример #4
0
        public void UpdatePosition(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            double lift, angle, protruding;

            lift       = getVerticalPosition(skeleton, exerciseVariant);
            angle      = getHandHorizontalAngle(skeleton, exerciseVariant);
            protruding = getProtrudingDistance(skeleton, exerciseVariant);
            SetPosition(angle, lift, protruding);
        }
Пример #5
0
        private bool IsPlayerTurnedSideways(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            double rotationAngle = getPlayerRotationAngle(skeleton, exerciseVariant);
            double tolerance     = 30.0f / 180 * Math.PI;
            Joint  ShoulderLeft  = skeleton.Joints[JointType.ShoulderLeft];
            Joint  ShoulderRight = skeleton.Joints[JointType.ShoulderRight];
            bool   isTracked     = ShoulderLeft.TrackingState == JointTrackingState.Tracked && ShoulderRight.TrackingState == JointTrackingState.Tracked;

            return((rotationAngle > tolerance || rotationAngle < (-1) * tolerance) && !isTracked);
        }
Пример #6
0
        static public double getPlayerRotationAngle(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            Joint  ShoulderLeft        = skeleton.Joints[JointType.ShoulderLeft];
            Joint  ShoulderRight       = skeleton.Joints[JointType.ShoulderRight];
            double hypotenuseLength    = Math.Abs(MathsHelper.DistanceBetweenPoints(ShoulderLeft, ShoulderRight, Axis.X, Axis.Z));
            double oppositeSideLength  = MathsHelper.DistanceBetweenPoints(ShoulderLeft, ShoulderRight, Axis.Z);
            double playerRotationAngle = Math.Asin(oppositeSideLength / hypotenuseLength);// / Math.PI * 180;

            return(playerRotationAngle);
        }
Пример #7
0
 private void DisplayMessages(Skeleton skeleton, ExerciseVariant exerciseVariant)
 {
     if (IsPlayerTurnedSideways(skeleton, exerciseVariant))
     {
         warningBox.Visibility = System.Windows.Visibility.Visible;
     }
     else
     {
         warningBox.Visibility = System.Windows.Visibility.Hidden;
     }
 }
Пример #8
0
        private void ExerciseHandler(Skeleton skeleton)
        {
            if (exerciseChanged)
            {
                exerciseChanged = false;
                SetExerciseType();
            }
            ExerciseVariant exerciseVariant = exerciseSettings.exerciseVariant;

            Rescale(skeleton, exerciseVariant);
            DisplayMessages(skeleton, exerciseVariant);
            UpdateLabels(skeleton, exerciseVariant);
        }
Пример #9
0
        public Joint GetGloveJoint(Skeleton skeleton, ExerciseVariant exercisevariant)
        {
            Joint scaledJoint;

            switch (exercisevariant)
            {
            case ExerciseVariant.HandLeft:
                scaledJoint = skeleton.Joints[JointType.WristLeft];
                break;

            case ExerciseVariant.HandRight:
            default:
                scaledJoint = skeleton.Joints[JointType.WristRight];
                break;
            }

            return(scaledJoint);
        }
Пример #10
0
        static Joint GetShoulderJoint(Skeleton skeleton, ExerciseVariant exercisevariant)
        {
            Joint scaledJoint;

            switch (exercisevariant)
            {
            case ExerciseVariant.HandLeft:
                scaledJoint = skeleton.Joints[JointType.ShoulderLeft];
                break;

            case ExerciseVariant.HandRight:
            default:
                scaledJoint = skeleton.Joints[JointType.ShoulderRight];
                break;
            }

            return(scaledJoint);
        }
Пример #11
0
        public double getHandHorizontalAngle(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            double protrudingLength = getProtrudingDistance(skeleton, exerciseVariant);

            double angle;

            if (exerciseVariant == ExerciseVariant.HandRight)
            {
                angle = 180 - getHorizonatalAngle(skeleton, exerciseVariant);
            }
            else
            {
                angle = getHorizonatalAngle(skeleton, exerciseVariant);
            }
            // double positionX = - (protrudingLength * Math.Cos(angle/180*Math.PI));
            // textInfo1.Text = "debug\n" + positionX + "\nangle: " + getPlayerRotationAngle(skeleton, exerciseVariant);
            return(angle);
        }
Пример #12
0
        public double getLiftDistance(Skeleton skeleton, ExerciseVariant exercisevarinat)
        {
            Joint firstPoint, secondPoint;

            switch (exercisevarinat)
            {
            case ExerciseVariant.HandLeft:
                firstPoint  = skeleton.Joints[JointType.ShoulderLeft];
                secondPoint = skeleton.Joints[JointType.WristLeft];
                break;

            case ExerciseVariant.HandRight:
            default:
                firstPoint  = skeleton.Joints[JointType.ShoulderRight];
                secondPoint = skeleton.Joints[JointType.WristRight];
                break;
            }

            return(MathsHelper.DistanceBetweenPoints(firstPoint, secondPoint, Axis.Y));
        }
Пример #13
0
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (closing)
            {
                return;
            }

            //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);

            if (first == null)
            {
                return;
            }

            ExerciseVariant exercisevariant = ExerciseVariant.HandRight;

            ExerciseHandler(first);
            // UpdatePosition(first, exercisevariant);
        }
Пример #14
0
        public double getHorizonatalAngle(Skeleton skeleton, ExerciseVariant exercisevarinat)
        {
            Joint centerPoint, leftPoint, rightPoint;

            switch (exercisevarinat)
            {
            case ExerciseVariant.HandLeft:
                leftPoint   = skeleton.Joints[JointType.ShoulderRight];
                centerPoint = skeleton.Joints[JointType.ShoulderLeft];
                rightPoint  = skeleton.Joints[JointType.HandLeft];
                break;

            case ExerciseVariant.HandRight:
            default:
                leftPoint   = skeleton.Joints[JointType.ShoulderLeft];
                centerPoint = skeleton.Joints[JointType.ShoulderRight];
                rightPoint  = skeleton.Joints[JointType.HandRight];
                break;
            }

            return(-1 * (MathsHelper.AngleBetweenJoints(leftPoint, centerPoint, rightPoint, Axis.X, Axis.Z) - 180)); // 0 when straight angle, increase when twisting
        }
Пример #15
0
        /*
         * private double getProtrudingDistance(Skeleton skeleton, ExerciseVariant exerciseVariant)
         * {
         *  Joint handJoint = GetGloveJoint(skeleton, exerciseVariant);
         *  Joint shoulderJoint = GetShoulderJoint(skeleton, exerciseVariant);
         *  double protrudingLength = Math.Abs(MathsHelper.DistanceBetweenPoints(shoulderJoint, handJoint, Axis.X, Axis.Z));
         *  return protrudingLength;
         * }
         */

        /*
         * public double getHandHorizontalPositon(Skeleton skeleton, ExerciseVariant exerciseVariant)
         * {
         *  double protrudingLength = getProtrudingDistance(skeleton, exerciseVariant);
         *
         *  double angle;
         *  if (exerciseVariant == ExerciseVariant.HandRight)
         *  {
         *      angle = 180 - getHorizonatalAngle(skeleton, exerciseVariant);
         *  }
         *  else
         *  {
         *      angle = getHorizonatalAngle(skeleton, exerciseVariant);
         *  }
         *  double positionX = - (protrudingLength * Math.Cos(angle/180*Math.PI));
         *  // textInfo1.Text = "debug\n" + positionX + "\nangle: " + getPlayerRotationAngle(skeleton, exerciseVariant);
         *  return positionX;
         * }
         */

        /*
         * static public double getVerticalPosition(Skeleton skeleton, ExerciseVariant exerciseVariant)
         * {
         *  Joint gloveJoint = GetGloveJoint(skeleton, exerciseVariant);
         *  const double posYCorrection = -0.2f;
         *  double diffY = gloveJoint.Position.Y - skeleton.Joints[JointType.ShoulderCenter].Position.Y + posYCorrection;
         *  return diffY;
         * }
         */

        private void Rescale(Skeleton skeleton, ExerciseVariant exerciseVariant)
        {
            hand.UpdatePosition(skeleton, exerciseVariant);

            /*
             * Joint scaledJoint = GetGloveJoint(skeleton, exerciseVariant);
             *
             * const double scaleX = 1.0; // range of move
             * double scaleY = 1.0 * (Convert.ToDouble(windowSizeY)/Convert.ToDouble(windowSizeX)); // range of move
             *
             * double diffY = 0;
             * int posX = 0;
             * int posY = 0;
             * double posYCorrection = -0.2f;
             * double armLength = 0.6f;
             * int leftDisplayMargin = 100;
             * int rightDisplayMargin = 100;
             * double horizontalPosition = getHandHorizontalPositon(skeleton, exerciseVariant);
             *
             * posX = Convert.ToInt32((horizontalPosition + armLength/2)/ armLength * (windowSizeX - leftDisplayMargin - rightDisplayMargin) + leftDisplayMargin);
             * diffY = scaledJoint.Position.Y - skeleton.Joints[JointType.ShoulderCenter].Position.Y + posYCorrection;
             * posY = Convert.ToInt32(-2.0 * scaleY * diffY * Convert.ToDouble(windowSizeY));
             *
             * double handMaxSize = 250; // pixels
             * double handMaxPutForward = 0.4f; // meters
             * double handMaxPutForwardPercentageSize = 0.5f; // percent / 100, size of image during push
             * double handMinSize = handMaxPutForwardPercentageSize * handMaxSize;
             * double slope = (handMinSize - handMaxSize) / handMaxPutForward;
             *
             * int handSize = Convert.ToInt32(slope * getProtrudingDistance(skeleton, exerciseVariant) + handMaxSize);
             * HandImage.Width = handSize;
             * HandImage.Height = handSize;
             *
             * Canvas.SetLeft(HandImage, posX - HandImage.Width / 2);
             * Canvas.SetTop(HandImage, posY - HandImage.Width / 2);
             */
        }
Пример #16
0
 public Game(ExerciseVariant ev, int windowSizeX, int windowSizeY)
 {
 }