Beispiel #1
0
    private void UpdateFlag()
    {
        beforeHandFlag = handFlag;
        handFlag = 0;
        var raiseLeftHands = new List<HandFlags>();
        for (int i = 0; i < bodyHistoryList.Count; i++) {
            // 左手のY座標が左肩の上にあるか取得
            try {
                if (bodyHistoryList[i]["HandLeft"]["Y"] - bodyHistoryList[i]["ShoulderLeft"]["Y"] > 0) {
                    raiseLeftHands.Add(HandFlags.LeftHandUp);
                } else {
                    raiseLeftHands.Add(HandFlags.LeftHandDown);
                }
            } catch (NullReferenceException e) {
                print(e.Message);
            }
        }

        var raiseRightHands = new List<HandFlags>();
        // 右腕の位置関係の把握
        for (int i = 0; i < bodyHistoryList.Count; i++) {
            // 右手のY座標が右肩の上にあるか取得
            try {
                if (bodyHistoryList[i]["HandRight"]["Y"] - bodyHistoryList[i]["ShoulderRight"]["Y"] > 0) {
                    raiseRightHands.Add(HandFlags.RightHandUp);
                } else {
                    raiseRightHands.Add(HandFlags.RightHandDown);
                }
            } catch (KeyNotFoundException e) {
                print(e.Message);
            }
        }
        var spread = new List<bool>();
        var nearby = new List<bool>();
        double threshold = 0.2;
        for (int i = 0; i < bodyHistoryList.Count; i++) {
            //両手を広げているか取得
            try {
                double x = bodyHistoryList[i]["HandRight"]["X"] - bodyHistoryList[i]["HandLeft"]["X"];
                double z = bodyHistoryList[i]["HandRight"]["Z"] - bodyHistoryList[i]["HandLeft"]["Z"];
                if (x * x + z * z > 1) {
                    spread.Add(true);
                } else {
                    spread.Add(false);
                }
                if (x * x + z * z < threshold * threshold) {
                    nearby.Add(true);
                } else {
                    nearby.Add(false);
                }
            } catch (KeyNotFoundException e) {
                print(e.Message);
            }
        }
        BeforeIsSpread = IsSpread;
        IsSpread = spread.All(s => s);
        BeforeNearBy = NearBy;
        NearBy = nearby.All(n => n);
        foreach (HandFlags flag in Enum.GetValues(typeof(HandFlags))) {
            if (raiseLeftHands.All(r => r == flag) || raiseRightHands.All(r => r == flag)) {
                handFlag |= flag;
            }
        }
        bodyHistoryList.RemoveAt(0);
    }
Beispiel #2
0
 public static bool GetHandFlag(HandFlags flag)
 {
     return (handFlag & flag) == flag;
 }
Beispiel #3
0
 public static bool GetNewHandFlag(HandFlags flag)
 {
     return GetHandFlag(flag) && (beforeHandFlag & flag) != flag;
 }