[Unity] Kinect 添加左右手水平动作

        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;
        }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值