Exemple #1
0
 public void init(ActionData action)
 {
     actionData = action;
     preStart   = false;
     start      = false;
     vectorList.Clear();
     startPosture = new Posture.Posture(Posture.PostureType.Both, action.dataList[0]);
     matchCount   = 0;
 }
Exemple #2
0
        private void drawPosture2D(Posture.Posture posture, Texture2D spriteGraphic)
        {
            // PINTA HUESOS
            this.DrawBone(posture.joints, JointType.Head, JointType.ShoulderCenter);
            this.DrawBone(posture.joints, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(posture.joints, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(posture.joints, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(posture.joints, JointType.Spine, JointType.HipCenter);
            this.DrawBone(posture.joints, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(posture.joints, JointType.HipCenter, JointType.HipRight);

            this.DrawBone(posture.joints, JointType.ShoulderLeft, JointType.ElbowLeft);
            this.DrawBone(posture.joints, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(posture.joints, JointType.WristLeft, JointType.HandLeft);

            this.DrawBone(posture.joints, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(posture.joints, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(posture.joints, JointType.WristRight, JointType.HandRight);

            this.DrawBone(posture.joints, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(posture.joints, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(posture.joints, JointType.AnkleLeft, JointType.FootLeft);

            this.DrawBone(posture.joints, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(posture.joints, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(posture.joints, JointType.AnkleRight, JointType.FootRight);

            // PINTA ARTICULACIONES
            Vector2 jointOrigin = new Vector2(spriteGraphic.Width / 2, spriteGraphic.Height / 2);

            foreach (Vector3 joint in posture.joints)
            {
                Color jointColor = Color.White;
                //Es posible que se pueda usar otro override con menos parámetros.
                //Pero mola mas asi :P xD
                this.spriteBatch.Draw(
                    spriteGraphic,
                    this.SkeletonToColorMap(joint),
                    null,
                    jointColor,
                    0.0f,
                    jointOrigin,
                    1.0f,
                    SpriteEffects.None,
                    0.0f);
            }
        }
Exemple #3
0
        /// <summary>
        /// Lógica del programa.
        /// </summary>
        /// <returns>Si se sale del programa o no</returns>
        public Boolean update()
        {
            this.currentScreenState = this.nextScreenState;
            this.currentPlayState   = this.nextPlayState;

            switch (this.currentScreenState)
            {
            case screenState.INIT:
                // algo en inicio?
                this.nextScreenState = screenState.MENU;
                break;

            case screenState.MENU:
                updateButtonsState(this.menuButtons);
                if (this.menuButtons[(int)GameButtonList.menuButton.PLAY].justPushed())
                {
                    this.nextScreenState = screenState.PLAY;
                    this.nextPlayState   = playState.INIT;
                }
                else if (this.menuButtons[(int)GameButtonList.menuButton.EXIT].justPushed())
                {
                    // termina el juego
                    return(false);
                }
                break;

            case screenState.PLAY:
                switch (this.currentPlayState)
                {
                case playState.INIT:
                    // algo en inicio?
                    this.gamePostures = null;
                    this.gameScores.Clear();
                    this.nextPlayState = playState.SELECT_POSTURE;
                    break;

                case playState.SELECT_POSTURE:
                    // actualiza la postura objetivo
                    if (updateCurrentGamePosture())
                    {
                        /// @FIX001:
                        this.drawPostureTimeOut = Stopwatch.StartNew();
                        this.nextPlayState      = playState.DRAW_POSTURE;
                    }
                    // si no quedan mas posturas va a la puntuacion final
                    else
                    {
                        this.nextPlayState = playState.FINAL_SCORE;
                    }
                    break;

                case playState.DRAW_POSTURE:
                    // Esta fase es para presentarle al usuario la postura objetivo
                    // TIMEOUT de 10 segundos o pulsar CONTINUE

                    /// @FIX001: Estaba a null el this.drawPostureTimeOut, asique le he puesto valor en SELECT_POSTURE (Margen de error: 1frame).
                    updateButtonsState(this.pauseButtons);
                    if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed() ||
                        isTimedOut(this.drawPostureTimeOut, DRAW_POSTURE_TIME))
                    {
                        this.drawPostureTimeOut.Reset();
                        this.nextPlayState = playState.DETECT_POSTURE;
                    }
                    break;

                case playState.DETECT_POSTURE:
                    updateButtonsState(this.gameButtons);
                    if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed())
                    {
                        this.nextPlayState = playState.PAUSE;
                    }
                    else
                    {
                        if (playerSkeleton != null)
                        {
                            Posture.Posture p = new Posture.Posture(playerSkeleton);
                            score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance);
                            if (score < 1.0)
                            {
                                this.holdPostureTimeOut = Stopwatch.StartNew();
                                this.nextPlayState      = playState.HOLD_POSTURE;
                            }
                        }
                    }
                    break;

                case playState.HOLD_POSTURE:
                    updateButtonsState(this.gameButtons);
                    if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed())
                    {
                        this.nextPlayState = playState.PAUSE;
                    }
                    else
                    {
                        if (playerSkeleton != null)
                        {
                            Posture.Posture p = new Posture.Posture(playerSkeleton);
                            score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance);
                            if (score < 1.0)
                            {
                                // La postura hay que mantenerla 2 segundos (HOLD_POSTURE_TIME)
                                if (isTimedOut(this.holdPostureTimeOut, HOLD_POSTURE_TIME))
                                {
                                    gameScores.Add(gamePostures[gamePosturesIndex], score);
                                    this.holdPostureTimeOut.Reset();
                                    this.scoreTimeOut  = Stopwatch.StartNew();
                                    this.nextPlayState = playState.SCORE;
                                }
                            }
                            else
                            {
                                this.holdPostureTimeOut.Reset();
                                this.nextPlayState = playState.DETECT_POSTURE;
                            }
                        }
                    }
                    break;

                case playState.PAUSE:
                    updateButtonsState(this.pauseButtons);
                    if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed())
                    {
                        this.nextPlayState = playState.DETECT_POSTURE;
                    }
                    else if (this.pauseButtons[(int)GameButtonList.pauseButton.REPLAY].justPushed())
                    {
                        this.nextPlayState = playState.INIT;
                    }
                    else if (this.pauseButtons[(int)GameButtonList.pauseButton.EXIT].justPushed())
                    {
                        this.nextPlayState = playState.END;
                    }
                    break;

                case playState.SCORE:
                    updateButtonsState(this.scoreButtons);
                    // TIMEOUT de 10 segundos a la siguiente postura o se pulsa alguna opcion
                    if (this.scoreButtons[(int)GameButtonList.scoreButton.NEXT].justPushed() ||
                        isTimedOut(this.scoreTimeOut, SCORE_TIME))
                    {
                        this.scoreTimeOut.Reset();
                        this.nextPlayState = playState.SELECT_POSTURE;
                    }
                    else if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed())
                    {
                        this.scoreTimeOut.Reset();
                        this.nextPlayState = playState.END;
                    }
                    else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed())
                    {
                        this.scoreTimeOut.Reset();
                        this.nextPlayState = playState.INIT;
                    }
                    break;

                case playState.FINAL_SCORE:
                    updateButtonsState(this.scoreButtons);
                    if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed())
                    {
                        this.nextPlayState = playState.END;
                    }
                    else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed())
                    {
                        this.nextPlayState = playState.INIT;
                    }
                    break;

                default:
                case playState.END:
                    this.nextScreenState = screenState.MENU;
                    break;
                }
                break;

            default:
            case screenState.END:
                return(false);    // Se avisa de que el programa dejara de actualizarse
            }

            return(true); // Si no esta en estado de END se continua con la ejecucion
        }
        /// <summary>
        /// Lógica del programa.
        /// </summary>
        /// <returns>Si se sale del programa o no</returns>
        public Boolean update()
        {
            this.currentScreenState = this.nextScreenState;
            this.currentPlayState   = this.nextPlayState;

            switch (this.currentScreenState)
            {
                case screenState.INIT:
                    // algo en inicio?
                    this.nextScreenState = screenState.MENU;
                    break;

                case screenState.MENU:
                    updateButtonsState(this.menuButtons);
                    if (this.menuButtons[(int)GameButtonList.menuButton.PLAY].justPushed())
                    {
                        this.nextScreenState = screenState.PLAY;
                        this.nextPlayState = playState.INIT;
                    }
                    else if (this.menuButtons[(int)GameButtonList.menuButton.EXIT].justPushed())
                    {
                        // termina el juego
                        return false;
                    }
                    break;

                case screenState.PLAY:
                    switch (this.currentPlayState)
                    {
                        case playState.INIT:
                            // algo en inicio?
                            this.gamePostures = null;
                            this.gameScores.Clear();
                            this.nextPlayState = playState.SELECT_POSTURE;
                            break;

                        case playState.SELECT_POSTURE:
                            // actualiza la postura objetivo
                            if (updateCurrentGamePosture())
                            {
                                /// @FIX001:
                                this.drawPostureTimeOut = Stopwatch.StartNew();
                                this.nextPlayState = playState.DRAW_POSTURE;
                            }
                            // si no quedan mas posturas va a la puntuacion final
                            else
                            {
                                this.nextPlayState = playState.FINAL_SCORE;
                            }
                            break;

                        case playState.DRAW_POSTURE:
                            // Esta fase es para presentarle al usuario la postura objetivo
                            // TIMEOUT de 10 segundos o pulsar CONTINUE

                            /// @FIX001: Estaba a null el this.drawPostureTimeOut, asique le he puesto valor en SELECT_POSTURE (Margen de error: 1frame).
                            updateButtonsState(this.pauseButtons);
                            if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed() ||
                                isTimedOut(this.drawPostureTimeOut, DRAW_POSTURE_TIME))
                            {
                                this.drawPostureTimeOut.Reset();
                                this.nextPlayState = playState.DETECT_POSTURE;
                            }
                            break;

                        case playState.DETECT_POSTURE:
                            updateButtonsState(this.gameButtons);
                            if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed())
                                this.nextPlayState = playState.PAUSE;
                            else
                            {
                                if (playerSkeleton != null)
                                {
                                    Posture.Posture p = new Posture.Posture(playerSkeleton);
                                    score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance);
                                    if (score < 1.0)
                                    {
                                        this.holdPostureTimeOut = Stopwatch.StartNew();
                                        this.nextPlayState = playState.HOLD_POSTURE;
                                    }
                                }
                            }
                            break;

                        case playState.HOLD_POSTURE:
                            updateButtonsState(this.gameButtons);
                            if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed())
                                this.nextPlayState = playState.PAUSE;
                            else
                            {
                                if (playerSkeleton != null)
                                {
                                    Posture.Posture p = new Posture.Posture(playerSkeleton);
                                    score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance);
                                    if (score < 1.0)
                                    {
                                        // La postura hay que mantenerla 2 segundos (HOLD_POSTURE_TIME)
                                        if (isTimedOut(this.holdPostureTimeOut, HOLD_POSTURE_TIME))
                                        {
                                            gameScores.Add(gamePostures[gamePosturesIndex], score);
                                            this.holdPostureTimeOut.Reset();
                                            this.scoreTimeOut = Stopwatch.StartNew();
                                            this.nextPlayState = playState.SCORE;
                                        }
                                    }
                                    else
                                    {
                                        this.holdPostureTimeOut.Reset();
                                        this.nextPlayState = playState.DETECT_POSTURE;
                                    }
                                }
                            }
                            break;

                        case playState.PAUSE:
                            updateButtonsState(this.pauseButtons);
                            if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed())
                                this.nextPlayState = playState.DETECT_POSTURE;
                            else if (this.pauseButtons[(int)GameButtonList.pauseButton.REPLAY].justPushed())
                                this.nextPlayState = playState.INIT;
                            else if (this.pauseButtons[(int)GameButtonList.pauseButton.EXIT].justPushed())
                                this.nextPlayState = playState.END;
                            break;

                        case playState.SCORE:
                            updateButtonsState(this.scoreButtons);
                            // TIMEOUT de 10 segundos a la siguiente postura o se pulsa alguna opcion
                            if (this.scoreButtons[(int)GameButtonList.scoreButton.NEXT].justPushed() ||
                                isTimedOut(this.scoreTimeOut, SCORE_TIME))
                            {
                                this.scoreTimeOut.Reset();
                                this.nextPlayState = playState.SELECT_POSTURE;
                            }
                            else if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed())
                            {
                                this.scoreTimeOut.Reset();
                                this.nextPlayState = playState.END;
                            }
                            else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed())
                            {
                                this.scoreTimeOut.Reset();
                                this.nextPlayState = playState.INIT;
                            }
                            break;

                        case playState.FINAL_SCORE:
                            updateButtonsState(this.scoreButtons);
                            if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed())
                                this.nextPlayState = playState.END;
                            else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed())
                                this.nextPlayState = playState.INIT;
                            break;

                        default:
                        case playState.END:
                            this.nextScreenState = screenState.MENU;
                            break;
                    }
                    break;

                default:
                case screenState.END:
                    return false; // Se avisa de que el programa dejara de actualizarse
            }

            return true; // Si no esta en estado de END se continua con la ejecucion
        }
Exemple #5
0
        public bool onData(double[][] vectorData, Action <int> action)
        {
            Posture.Posture currentPosture = new Posture.Posture(Posture.PostureType.Both, vectorData);
            if (!preStart)
            {
                if (Posture.PostureRecognition.matches(currentPosture, startPosture))
                {
                    vectorList.AddLast(vectorData);
                    preStart   = true;
                    prePosture = currentPosture;

                    LogUtil.log("动作预开始");
                }
                return(false);
            }

            if (!start && !Posture.PostureRecognition.matches(currentPosture, startPosture))
            {
                start = true;
                action(1);
                LogUtil.log("动作开始");
            }

            if (!start)
            {
                return(false);
            }

            vectorList.AddLast(vectorData);

            if (Posture.PostureRecognition.matches(currentPosture, prePosture))
            {
                matchCount++;
            }
            else
            {
                matchCount = 0;
                prePosture = currentPosture;
            }


            if (matchCount > 15)
            {
                LogUtil.log("动作结束");

                int length             = vectorList.Count - 15;
                List <double[][]> data = new List <double[][]>(length);

                int i = 0;
                foreach (double[][] v in vectorList)
                {
                    if (i++ == length)
                    {
                        break;
                    }
                    data.Add(v);
                }

                ActionData acData = ActionMatchingUtil.loadActionData(data);


                LogUtil.log(actionData.dataList.Count + "," + acData.dataList.Count);
                bool result = ActionMatchingUtil.match(actionData, acData);
                init(actionData);
                action(0);
                return(result);
            }

            return(false);
        }
 public void TestPostureCompareTo_ClosePosture()
 {
     Posture.Posture p1 = PostureLibrary.loadPosture("./postures/T_JOSE");
     Posture.Posture p2 = PostureLibrary.loadPosture("./postures/T_JOSE2");
     Assert.Less(p1.compareTo(p2, ref jointScore, puntualTolerance, averageTolerance), 1);
 }