コード例 #1
0
    /**
     * Detects if the skeleton is kicking
     * */
    private bool detectKick(HNJOINT jointype)
    {
        var foot = joints[(int)jointype];
        var hip  = joints[(int)HNJOINT.HIP_CENTER];

        return(Math.Max(hip.y - foot.y, foot.y - hip.y) < .5f && Math.Max(hip.x - foot.x, foot.x - hip.x) > .3f);
    }
コード例 #2
0
 /**
  * Detects if the given hand is closed
  * */
 private bool isHandClosed(HNJOINT handType)
 {
     if (handType == HNJOINT.HAND_LEFT)
     {
         return(leftHand != HNHANDSTATE.HNHANDSTATE_OPEN);
     }
     else
     {
         return(rightHand != HNHANDSTATE.HNHANDSTATE_OPEN);
     }
 }
コード例 #3
0
 /**
  * Detects if the given hand is open
  * */
 private bool isHandOpen(HNJOINT handType)
 {
     if (handType == HNJOINT.HAND_LEFT)
     {
         return(leftHand != HNHANDSTATE.HNHANDSTATE_CLOSED);
     }
     else
     {
         return(rightHand != HNHANDSTATE.HNHANDSTATE_CLOSED);
     }
 }
コード例 #4
0
    /**
     * Detects if the given hand is doing the fistpump gesture
     * */
    private bool detectFistPump(HNJOINT handType)
    {
        getVerticalDisplacement(handType);
        bool ishandMovingVertical;

        if (handType == HNJOINT.HAND_LEFT)
        {
            ishandMovingVertical = (leftHandVertDelay > 0); //if moved at VERT_LARGE_DISPLACEMENT_THRESHOLD in the last MAX_VERTICAL_DELAY frames
        }
        else
        {
            ishandMovingVertical = (rightHandVertDelay > 0);
        }

        return(!shrug && detectHandHorizontal(handType, .1f) && isHandClosed(handType) && isHandOverElbow(handType) && ishandMovingVertical);
    }
コード例 #5
0
    /**
     * Detects if the skeleton is stepping
     * */
    private bool detectStep(HNJOINT jointype)
    {
        var     knee = joints[(int)jointype];
        var     hip  = joints[(int)HNJOINT.HIP_CENTER];
        Vector3 foot;

        if (jointype == HNJOINT.KNEE_LEFT)
        {
            foot = joints[(int)HNJOINT.FOOT_LEFT];
        }
        else
        {
            foot = joints[(int)HNJOINT.FOOT_RIGHT];
        }
        return((Math.Max(hip.y - knee.y, knee.y - hip.y) < .2f) && !sitting && (Math.Max(knee.x - foot.x, foot.x - knee.x) < .1f));
    }
コード例 #6
0
    /**
     * Detects if the hand is above the y of the elbow
     * */
    private bool isHandOverElbow(HNJOINT handType)
    {
        HNJOINT elbowType;

        if (handType == HNJOINT.HAND_RIGHT)
        {
            elbowType = HNJOINT.ELBOW_RIGHT;
        }
        else
        {
            elbowType = HNJOINT.ELBOW_LEFT;
        }
        var hand  = joints[(int)handType];
        var elbow = joints[(int)elbowType];

        return(hand.y > elbow.y);
    }
コード例 #7
0
    /**
     * Detects if the given hand is waving
     * */
    private bool detectWave(HNJOINT handType)
    {
        bool isHandOpened  = isHandOpen(handType);
        bool handOverElbow = isHandOverElbow(handType);
        bool isHandWithinHorizontalBounds = detectHandHorizontal(handType, .4f);
        bool isMovingHorizontal;

        getHorizontalDisplacement(handType);

        if (handType == HNJOINT.HAND_LEFT)
        {
            isMovingHorizontal = (leftHandHorizDelay > 0); //if moved at that speed in the last MAX_HORIZONTAL_DELAY frames
        }
        else
        {
            isMovingHorizontal = (rightHandHorizDelay > 0);
        }
        return(!shrug && handOverElbow && isHandWithinHorizontalBounds && isMovingHorizontal && isHandOpened);
    }
コード例 #8
0
    /**
     * Detects if the hand is too far from the x pos of the elbow
     * */
    private bool detectHandHorizontal(HNJOINT handType, float maxHorizontalDistance)
    {
        //float maxHorizontalDistance = .25f;
        HNJOINT elbowType;

        if (handType == HNJOINT.HAND_RIGHT)
        {
            elbowType = HNJOINT.ELBOW_RIGHT;
        }
        else
        {
            elbowType = HNJOINT.ELBOW_LEFT;
        }
        var hand  = joints[(int)handType];
        var elbow = joints[(int)elbowType];

        var horizontalDifference = hand.x - elbow.x;

        return((horizontalDifference < maxHorizontalDistance) && (horizontalDifference > 0 - maxHorizontalDistance));
    }
コード例 #9
0
    /**
     * Detects if any Joint is moving vertically, and returns the distance
     * */
    private float getVerticalDisplacement(HNJOINT jointType)
    {
        var     joint = joints[(int)jointType];
        Vector3 lastJoint;

        if (lastFrameJoints.Length > 0)
        {
            lastJoint = lastFrameJoints[(int)jointType];
            if (jointType == HNJOINT.SHOULDER_RIGHT)
            {
                if (rightShoulderVertDelay > 0)//if the delay is > 0, that means we've detected horiz movement
                {
                    rightShoulderVertDelay++;
                }
                if (rightShoulderVertDelay > MAX_VERTICAL_DELAY)
                {
                    rightShoulderVertDelay = 0;
                }
                float displacement = rightShoulderVertDisplacement;
                if (Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y) < 1f)
                {
                    displacement = Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > VERT_SMALL_DISPLACEMENT_THRESHOLD)
                {
                    rightShoulderVertDelay        = 1;
                    rightShoulderVertDisplacement = displacement;
                }

                return(displacement);
            }
            else if (jointType == HNJOINT.SHOULDER_LEFT)
            {
                if (leftShoulderVertDelay > 0)
                {
                    leftShoulderVertDelay++;
                }
                if (leftShoulderVertDelay > MAX_VERTICAL_DELAY)
                {
                    leftShoulderVertDelay = 0;
                }
                float displacement = leftShoulderVertDisplacement;
                if (Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y) < 1f)
                {
                    displacement = Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > VERT_SMALL_DISPLACEMENT_THRESHOLD)
                {
                    leftShoulderVertDelay        = 1;
                    leftShoulderVertDisplacement = displacement;
                }

                return(displacement);
            }
            else if (jointType == HNJOINT.HAND_RIGHT)
            {
                if (rightHandVertDelay > 0)//if the delay is > 0, that means we've detected horiz movement
                {
                    rightHandVertDelay++;
                }
                if (rightHandVertDelay > MAX_VERTICAL_LARGE_DELAY)
                {
                    rightHandVertDelay = 0;
                }
                float displacement = rightHandVertDisplacement;
                if (Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y) < 1f)
                {
                    displacement = Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > VERT_LARGE_DISPLACEMENT_THRESHOLD)
                {
                    rightHandVertDelay        = 1;
                    rightHandVertDisplacement = displacement;
                }

                return(displacement);
            }
            else if (jointType == HNJOINT.HAND_LEFT)
            {
                if (leftHandVertDelay > 0)
                {
                    leftHandVertDelay++;
                }
                if (leftHandVertDelay > MAX_VERTICAL_LARGE_DELAY)
                {
                    leftHandVertDelay = 0;
                }
                float displacement = leftHandVertDisplacement;
                if (Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y) < 1f)
                {
                    displacement = Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > VERT_LARGE_DISPLACEMENT_THRESHOLD)
                {
                    leftHandVertDelay        = 1;
                    leftHandVertDisplacement = displacement;
                }

                return(displacement);
            }

            return(Math.Max(joint.y - lastJoint.y, lastJoint.y - joint.y));
        }
        else
        {
            return(0);
        }
    }
コード例 #10
0
    /**
     * Detects if any Joint is moving horizontally, and returns the distance
     * */
    private float getHorizontalDisplacement(HNJOINT jointType)
    {
        var     joint = joints[(int)jointType];
        Vector3 lastJoint;

        if (lastFrameJoints.Length > 0)
        {
            lastJoint = lastFrameJoints[(int)jointType];
            if (jointType == HNJOINT.HAND_RIGHT)
            {
                if (rightHandHorizDelay > 0)//if the delay is > 0, that means we've detected horiz movement
                {
                    rightHandHorizDelay++;
                }
                if (rightHandHorizDelay > MAX_HORIZONTAL_DELAY)
                {
                    rightHandHorizDelay = 0;
                }
                float displacement = rightHandHorizDisplacement;
                if (Math.Max(joint.x - lastJoint.x, lastJoint.x - joint.x) < 1f)
                {
                    displacement = Math.Max(joint.x - lastJoint.x, lastJoint.x - joint.x);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > HORIZ_DISPLACEMENT_THRESHOLD)
                {
                    rightHandHorizDelay        = 1;
                    rightHandHorizDisplacement = displacement;
                }

                return(displacement);
            }
            else if (jointType == HNJOINT.HAND_LEFT)
            {
                if (leftHandHorizDelay > 0)
                {
                    leftHandHorizDelay++;
                }
                if (leftHandHorizDelay > MAX_HORIZONTAL_DELAY)
                {
                    leftHandHorizDelay = 0;
                }
                float displacement = leftHandHorizDisplacement;
                if (Math.Max(joint.x - lastJoint.x, lastJoint.x - joint.x) < 1f)
                {
                    displacement = Math.Max(joint.x - lastJoint.x, lastJoint.x - joint.x);
                }
                //if we've got displacement, then start the delay at 1
                if (displacement > HORIZ_DISPLACEMENT_THRESHOLD)
                {
                    leftHandHorizDelay        = 1;
                    leftHandHorizDisplacement = displacement;
                }

                return(displacement);
            }

            return(Math.Max(joint.x - lastJoint.x, lastJoint.x - joint.x));
        }
        else
        {
            return(0);
        }
    }