HorizontalLeftHand, //水平左手
HorizontalRightHand, //水平右手
先添加枚举,然后是具体代码
case Gestures.HorizontalLeftHand:
switch (gestureData.state)
{
case 0: // gesture detection
if (jointsTracked[shoulderCenterIndex] && jointsTracked[leftHandIndex] && jointsTracked[leftElbowIndex] &&
jointsTracked[leftShoulderIndex] && jointsTracked[rightElbowIndex] && //检测到中心左肩左肘左手右手
Mathf.Abs(jointsPos[leftElbowIndex].y - jointsPos[leftShoulderIndex].y) < 0.2f && //左肘和左肩高度接近
Mathf.Abs(jointsPos[leftHandIndex].y - jointsPos[leftShoulderIndex].y) < 0.2f && //左肘和左手高度接近
(jointsPos[leftHandIndex].y - jointsPos[rightElbowIndex].y) > 0.2f && //左手足够高于右手
Mathf.Abs(jointsPos[shoulderCenterIndex].z - jointsPos[leftHandIndex].z) < 0.3f) //左手和肩膀中心,前后足够接近
{
SetGestureJoint(ref gestureData, timestamp, leftHandIndex, jointsPos[leftHandIndex]);
}
break;
case 1: // gesture complete
bool isInPose = jointsTracked[shoulderCenterIndex] && jointsTracked[leftHandIndex] && jointsTracked[leftElbowIndex] &&
jointsTracked[leftShoulderIndex] && jointsTracked[rightElbowIndex] &&
Mathf.Abs(jointsPos[leftElbowIndex].y - jointsPos[leftShoulderIndex].y) < 0.2f &&
Mathf.Abs(jointsPos[leftHandIndex].y - jointsPos[leftShoulderIndex].y) < 0.2f &&
(jointsPos[leftHandIndex].y - jointsPos[rightElbowIndex].y) > 0.2f &&
Mathf.Abs(jointsPos[shoulderCenterIndex].z - jointsPos[leftHandIndex].z) < 0.3f;
Vector3 jointPos = jointsPos[gestureData.joint];
CheckPoseComplete(ref gestureData, timestamp, jointPos, isInPose, KinectInterop.Constants.PoseCompleteDuration);
break;
}
break;
case Gestures.HorizontalRightHand:
switch (gestureData.state)
{
case 0: // gesture detection rightHandIndex
if (jointsTracked[shoulderCenterIndex] && jointsTracked[rightHandIndex] && jointsTracked[rightElbowIndex] &&
jointsTracked[rightShoulderIndex] && jointsTracked[leftElbowIndex] && //检测到中心右肩右肘左手右手
Mathf.Abs(jointsPos[rightElbowIndex].y - jointsPos[rightShoulderIndex].y) < 0.2f && //右肘和右肩高度接近
Mathf.Abs(jointsPos[rightHandIndex].y - jointsPos[rightShoulderIndex].y) < 0.2f && //右肘和右手高度接近
(jointsPos[rightHandIndex].y - jointsPos[leftElbowIndex].y) > 0.2f && //右手足够高于左手
Mathf.Abs(jointsPos[shoulderCenterIndex].z - jointsPos[rightHandIndex].z) < 0.3f) //右手和肩膀中心,前后足够接近
{
SetGestureJoint(ref gestureData, timestamp, rightHandIndex, jointsPos[rightHandIndex]);
}
break;
case 1: // gesture complete
bool isInPose = jointsTracked[shoulderCenterIndex] && jointsTracked[rightHandIndex] && jointsTracked[rightElbowIndex] &&
jointsTracked[rightShoulderIndex] && jointsTracked[leftElbowIndex] &&
Mathf.Abs(jointsPos[rightElbowIndex].y - jointsPos[rightShoulderIndex].y) < 0.2f &&
Mathf.Abs(jointsPos[rightHandIndex].y - jointsPos[rightShoulderIndex].y) < 0.2f &&
(jointsPos[rightHandIndex].y - jointsPos[leftElbowIndex].y) > 0.2f &&
Mathf.Abs(jointsPos[shoulderCenterIndex].z - jointsPos[rightHandIndex].z) < 0.3f;
Vector3 jointPos = jointsPos[gestureData.joint];
CheckPoseComplete(ref gestureData, timestamp, jointPos, isInPose, KinectInterop.Constants.PoseCompleteDuration);
break;
}
break;
}