예제 #1
0
        //
        // Update
        //
        public virtual void Update(Game1 game)
        {
            if (IsVisible)
            {
                Vector3 objPos, pos, dirSrc, dirDst;
                float   dirScale;

                pos      = game.getJointPos2D(this.attatchedTo.pos);
                dirSrc   = game.getJointPos2D(this.attatchedTo.dirSrc);
                dirDst   = game.getJointPos2D(this.attatchedTo.dirDst);
                dirScale = this.attatchedTo.dirScale;

                objPos = pos + dirScale * (dirDst - dirSrc);

                // 変換行列作成
                world = getScaleMatrix(objPos.Z) *
                        getRotateMatrixFromFv(game.getJointPosture("BodyForward")) * // 回転
                        getRotateMatrixFromUv(game.getJointPosture("BodyUp")) *      // 回転
                        getTranslationMatrix(objPos);                                // 移動
            }
            else
            {
                world = Matrix.CreateScale(0.0f); // サイズ0にする
            }
        }
예제 #2
0
        private void UpdateVFX(Game1 game)
        {
            Vector3 righthand, lefthand, handsCenter;

            righthand = game.getJointPos2D(JointID.HandRight);
            lefthand  = game.getJointPos2D(JointID.HandLeft);

            handsCenter = (righthand + lefthand) / 2;

            if (actionState == 1)
            {
                if (actionCnt < 500)
                {
                    ++actionCnt;
                }
            }
            else if (actionState == 2)
            {
            }
            else if (actionState == 3)
            {
                actionCnt += 30;
            }
            else
            {
                actionCnt = 0;
            }

            // 変換行列作成
            world = Matrix.CreateScale(actionCnt / 10) *
                    getTranslationMatrix(handsCenter); // 移動
        }
예제 #3
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            // 状態をクリア
            gesture_ok     = false;
            gesture_byebye = false;

            // データを格納
            PutData(JointID.HandRight, game.getJointPos2D(JointID.HandRight));
            PutData(JointID.HandLeft, game.getJointPos2D(JointID.HandLeft));
            PutData(JointID.ShoulderCenter, game.getJointPos2D(JointID.ShoulderCenter));
            PutData(JointID.ElbowRight, game.getJointPos2D(JointID.ElbowRight));
            PutData(JointID.ElbowLeft, game.getJointPos2D(JointID.ElbowLeft));
            PutData(JointID.ShoulderRight, game.getJointPos2D(JointID.ShoulderRight));

            swipeDetect.PutData(game.getJointPos2D(JointID.HandRight), game.getJointPos2D(JointID.ElbowRight), game.getJointPos2D(JointID.ShoulderRight));

            // OKジェスチャの認識
            if (samplingData[JointID.HandRight][0].X <samplingData[JointID.ElbowRight][0].X && // 手が肘より内側
                                                      samplingData[JointID.HandLeft][0].X> samplingData[JointID.ElbowLeft][0].X &&
                samplingData[JointID.HandRight][0].Y < samplingData[JointID.ElbowRight][0].Y && // 手が肘より上側
                samplingData[JointID.HandLeft][0].Y < samplingData[JointID.ElbowLeft][0].Y &&
                samplingData[JointID.ElbowRight][0].Y < samplingData[JointID.ShoulderCenter][0].Y && // 肘が肩より上側
                samplingData[JointID.ElbowLeft][0].Y < samplingData[JointID.ShoulderCenter][0].Y)
            {
                gesture_ok = true;
            }

            // バイバイジェスチャの認識
            gesture_byebye = DetectByeBye();

            // Swipeジェスチャの認識
            float margin = Math.Abs(samplingData[JointID.ShoulderRight][0].X - samplingData[JointID.ShoulderCenter][0].X);

            gesture_swiperight = swipeDetect.DetectSwipe((int)SwipeDirection.SwipeRight, margin);
            gesture_swipeleft  = swipeDetect.DetectSwipe((int)SwipeDirection.SwipeLeft, margin);
            gesture_swipeup    = swipeDetect.DetectSwipe((int)SwipeDirection.SwipeUp, margin);
            gesture_swipedown  = swipeDetect.DetectSwipe((int)SwipeDirection.SwipeDown, margin);

            base.Update(gameTime);
        }
예제 #4
0
        private void UpdateAction(Game1 game)
        {
            //
            // Y字ポーズの認識
            //
            Vector3 head;
            Vector3 righthand, lefthand;
            Vector3 rightshoulder, leftshoulder;
            Vector3 handscenter;

            head          = game.getJointPos2D(JointID.Head);
            righthand     = game.getJointPos2D(JointID.HandRight);
            lefthand      = game.getJointPos2D(JointID.HandLeft);
            handscenter   = (righthand + lefthand) / 2;
            rightshoulder = game.getJointPos2D(JointID.ShoulderRight);
            leftshoulder  = game.getJointPos2D(JointID.ShoulderLeft);

            float handsdistance = Math.Abs(lefthand.X - righthand.X);
            float shoulderwidth = Math.Abs(leftshoulder.X - rightshoulder.X);

            if (handsdistance > shoulderwidth && // 両手の間隔が肩幅より大きい
                handscenter.Y < head.Y)          // 両手が頭より高い位置にある
            {
                pose_handsupY = true;
                ++pose_handsupY_cnt;
            }
            else
            {
                pose_handsupY     = false;
                pose_handsupY_cnt = 0;
            }

            //
            // 静止の認識
            //

            Vector3 righthand_mv = game.getJointMotion2D(JointID.HandRight);
            Vector3 lefthand_mv  = game.getJointMotion2D(JointID.HandLeft);

            if (Math.Abs(righthand_mv.X) < 15 &&
                Math.Abs(righthand_mv.Y) < 15 &&
                Math.Abs(lefthand_mv.X) < 15 &&
                Math.Abs(lefthand_mv.Y) < 15)
            {
                pose_still = true;
                ++pose_still_cnt;
            }
            else
            {
                pose_still     = false;
                pose_still_cnt = 0;
            }

            //
            // 両手の降りおろしの認識
            //

            if (Math.Abs(righthand.Y - lefthand.Y) <= 30 &&
                Math.Abs(righthand_mv.Y) > 20)
            {
                pose_sweepdown = true;
                ++pose_sweepdown_cnt;
            }
            else
            {
                pose_sweepdown     = false;
                pose_sweepdown_cnt = 0;
            }

            //
            // 両手が腰より下にある状態の認識
            //
            Vector3 torso = game.getJointPos(JointID.HipCenter);

            if (righthand.Y > torso.Y &&
                lefthand.Y > torso.Y)
            {
                pose_handsonwaist = true;
                ++pose_handsonwaist_cnt;
            }
            else
            {
                pose_handsonwaist     = false;
                pose_handsonwaist_cnt = 0;
            }

            ///
            /// アクション認識ステートマシン
            ///

            switch (actionState)
            {
            case 0:     // 初期状態
                if (pose_handsupY_cnt > 60 && pose_still_cnt > 60)
                {
                    ++actionState;
                }
                break;

            case 1:     // 両手をあげた状態
                if (pose_sweepdown)
                {
                    ++actionState;     // 振り下ろしていたら次の状態へ
                    effectLifeTimer = 90;
                }
                else if (pose_handsupY == false)
                {
                    actionState = 0;
                }
                break;

            case 2:     // 降りおろし中
                if (pose_handsonwaist)
                {
                    ++actionState;     // 発動
                }
                else if (pose_sweepdown)
                {
                    // 状態継続
                }
                else
                {
                    actionState = 0;
                }
                break;

            case 3:     // 発動
                --effectLifeTimer;
                if (effectLifeTimer == 0)
                {
                    actionState = 0;     // 初期状態へ
                }
                break;
            }
        }