private void SetHandOrientation(Hand hand, PXCMHandData.IHand handInfo) { var d4 = handInfo.QueryPalmOrientation(); PXCMRotation rotationHelper; _camera.Session.CreateImpl(out rotationHelper); rotationHelper.SetFromQuaternion(d4); var rotationEuler = rotationHelper.QueryEulerAngles(PXCMRotation.EulerOrder.PITCH_YAW_ROLL); var x = rotationEuler.x * 180 / Math.PI; var y = rotationEuler.y * 180 / Math.PI; var z = rotationEuler.z * 180 / Math.PI; hand.Rotation = new Rotation(x, y, z); rotationHelper.Dispose(); }
/* Displaying current frames hand joints */ private void TrackJoints(PXCMHandData handOutput) { //Get hand by time of appearence if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMPoint4DF32 palmOrientation = handData.QueryPalmOrientation(); handData.QueryTrackedJoint(PXCMHandData.JointType.JOINT_THUMB_TIP, out ThumbJointData); handData.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out IndexJointData); handData.QueryTrackedJoint(PXCMHandData.JointType.JOINT_CENTER, out PalmCenterJointData); /* get joint distance */ Vector3 thumb = new Vector3(ThumbJointData.positionWorld.x, ThumbJointData.positionWorld.y, ThumbJointData.positionWorld.z); Vector3 index = new Vector3(IndexJointData.positionWorld.x, IndexJointData.positionWorld.y, IndexJointData.positionWorld.z); Vector3 palm = new Vector3(PalmCenterJointData.positionWorld.x, PalmCenterJointData.positionWorld.y, PalmCenterJointData.positionWorld.z); switch (rotationType) { case RotationType.FingerDelta: //Rotate along y-axis ///Compare the difference between the z values and determine if is great than the threshold float diff = CompareFloats(index.z, palm.z); if (Mathf.Abs(diff) > 0.02f) { //begin to rotate using the difference thershold as a multiplier for rotation speed. logo.transform.Rotate(Time.deltaTime * (diff * 500), 0, 0); } //rotate along x-axis diff = CompareFloats(thumb.z, palm.z); if (Mathf.Abs(diff) > 0.02f) { Debug.Log(diff.ToString()); //begin to rotate using the difference thershold as a multiplier for rotation speed. logo.transform.Rotate(0, Time.deltaTime * (diff * 500), 0); } //rotate along x-axis diff = CompareFloats(thumb.z, index.z); if (Mathf.Abs(diff) > 0.02f) { Debug.Log(diff.ToString()); //begin to rotate using the difference thershold as a multiplier for rotation speed. logo.transform.Rotate(0, 0, Time.deltaTime * (diff * 500)); } break; case RotationType.handleDelta: //logo.transform.localRotation = new Quaternion(-palmOrientation.w, -palmOrientation.z, -palmOrientation.y, -palmOrientation.x); logo.transform.Rotate(index.y * Time.deltaTime * 750, index.x * Time.deltaTime * 750, 0); break; case RotationType.Pinch: pinch_dist = Vector3.Distance(index, thumb); if (HandlePinchResult(pinch_dist)) { //set the initial position if (pinchPos == Vector3.zero) { pinchPos = index; } //get the vector between the initial position and the current index postion Vector3 temp = pinchPos - index; logo.transform.Rotate(-temp.y * Time.deltaTime * 750, -temp.x * Time.deltaTime * 750, -temp.z * Time.deltaTime * 750); } break; default: Debug.Log("something went wrong"); break; } } }