public HandsState(Body body) { CameraSpacePoint handLeft = body.Joints[JointType.HandLeft].Position; CameraSpacePoint handRight = body.Joints[JointType.HandRight].Position; wristLeft = body.Joints[JointType.WristLeft].Position; wristRight = body.Joints[JointType.WristRight].Position; CameraSpacePoint spineBase = body.Joints[JointType.SpineBase].Position; input = new HandInput(); input.isLeftGrip = (body.HandLeftState == HandState.Closed); input.isRightGrip = (body.HandRightState == HandState.Closed); //select wrist if (prime_hand) { primeHandy = (int)(wristRight.Y * 100); isRight = true; } else { primeHandy = (int)(wristLeft.Y * 100); isRight = false; } //set left hand position float leftDepth = spineBase.Z - handLeft.Z; input._LPressExtent = (leftDepth - TOUCH_REGION) / (EMBED_REGION - TOUCH_REGION); if (leftDepth > EMBED_REGION) { LeftHandPosition = HandPositionZ.EMBED; } else if (leftDepth > TOUCH_REGION) { LeftHandPosition = HandPositionZ.TOUCH; } else { LeftHandPosition = HandPositionZ.UNKNOW; } //set right hand position float rightDepth = spineBase.Z - handRight.Z; input._RPressExtent = (rightDepth - TOUCH_REGION) / (EMBED_REGION - TOUCH_REGION); if (rightDepth > EMBED_REGION) { RightHandPosition = HandPositionZ.EMBED; } else if (rightDepth > TOUCH_REGION) { RightHandPosition = HandPositionZ.TOUCH; } else { RightHandPosition = HandPositionZ.UNKNOW; } //set left hand state LeftHandState = body.HandLeftState; //set right hand state RightHandState = body.HandRightState; //no hand if (LeftHandPosition == HandPositionZ.UNKNOW && RightHandPosition == HandPositionZ.UNKNOW) { operation = Operation.no_operation; input._isWhich = 0; } //single hand else if (LeftHandPosition == HandPositionZ.UNKNOW || RightHandPosition == HandPositionZ.UNKNOW) { //left hand operate if (LeftHandPosition != HandPositionZ.UNKNOW) { SelectHandPosition = LeftHandPosition; SelectHandState = LeftHandState; input._isWhich = 1; isRight = false; } //right hand operate else { SelectHandPosition = RightHandPosition; SelectHandState = RightHandState; input._isWhich = 2; isRight = true; } //single hand touch region if (SelectHandPosition == HandPositionZ.TOUCH) { if (SelectHandState == HandState.Closed) { if (mouse_click_region) { operation = Operation.left_down; } else { operation = Operation.right_down; } } else { operation = Operation.move; } } //single hand embed region else { if (SelectHandState == HandState.Closed) { if (mouse_click_region) { operation = Operation.right_down; } else { operation = Operation.left_down; } } else { operation = Operation.move; } } } else { //two hand closed will operate wheel input._isWhich = 3; if (LeftHandState == HandState.Closed && RightHandState == HandState.Closed) { if (middle_button_and_wheel) { operation = Operation.wheel; } else { operation = Operation.middle_down; } } //one hand closed else if (LeftHandState == HandState.Closed || RightHandState == HandState.Closed) { if (middle_button_and_wheel) { operation = Operation.middle_down; } else { operation = Operation.wheel; } } else { operation = Operation.move; } } }
public HandsState(Body body) { CameraSpacePoint handLeft = body.Joints[JointType.HandLeft].Position; CameraSpacePoint handRight = body.Joints[JointType.HandRight].Position; CameraSpacePoint wristLeft = body.Joints[JointType.WristLeft].Position; CameraSpacePoint wristRight = body.Joints[JointType.WristRight].Position; spineBase = body.Joints[JointType.SpineBase].Position; primeHandy = (int)(handRight.Y * 100); //set left hand position if (spineBase.Z - handLeft.Z > EMBED_REGION) { LeftHandPosition = HandPositionZ.EMBED; } else if (spineBase.Z - handLeft.Z > TOUCH_REGION) { LeftHandPosition = HandPositionZ.TOUCH; } else { LeftHandPosition = HandPositionZ.UNKNOW; } //set right hand position if (spineBase.Z - handRight.Z > EMBED_REGION) { RightHandPosition = HandPositionZ.EMBED; } else if (spineBase.Z - handRight.Z > TOUCH_REGION) { RightHandPosition = HandPositionZ.TOUCH; } else { RightHandPosition = HandPositionZ.UNKNOW; } //set left hand state LeftHandState = body.HandLeftState; //set right hand state RightHandState = body.HandRightState; //no hand if (LeftHandPosition == HandPositionZ.UNKNOW && RightHandPosition == HandPositionZ.UNKNOW) { operation = Operation.no_operation; } //single hand else if (LeftHandPosition == HandPositionZ.UNKNOW || RightHandPosition == HandPositionZ.UNKNOW) { //left hand operate if (LeftHandPosition != HandPositionZ.UNKNOW) { selectHand = wristLeft; SelectHandPosition = LeftHandPosition; SelectHandState = LeftHandState; } //right hand operate else { selectHand = wristRight; SelectHandPosition = RightHandPosition; SelectHandState = RightHandState; } //single hand touch region if (SelectHandPosition == HandPositionZ.TOUCH) { if (SelectHandState == HandState.Closed) { operation = Operation.left_down; } else { operation = Operation.move; } } //single hand embed region else { if (SelectHandState == HandState.Closed) { operation = Operation.right_down; } else { operation = Operation.move; } } } //two hand the prime hand is right else { //select wrist selectHand = wristRight; //two hand closed will operate wheel if (LeftHandState == HandState.Closed && RightHandState == HandState.Closed) { operation = Operation.wheel; } //one hand closed else if (LeftHandState == HandState.Closed || RightHandState == HandState.Closed) { operation = Operation.middle_down; } else { operation = Operation.move; } } }