示例#1
0
        internal GestureResult(GestureResultRaw raw)
        {
            isLeft  = raw.isLeft;
            gesture = raw.gesture;
            points  = raw.points;

            if (GestureProvider.HaveSkeleton)
            {
                Vector3 wrest = points[0];
                // finger roots
                Vector3 index = points[5], middle = points[9], ring = points[13], pinky = points[17];

                Vector3 vec1 = (index + middle) / 2 - wrest;
                Vector3 vec2 = (ring + pinky) / 2 - wrest;
                position = (vec1 + vec2) / 3 + wrest;

                Vector3 forward = isLeft ? Vector3.Cross(vec1, vec2) : Vector3.Cross(vec2, vec1);
                if (forward.sqrMagnitude < 1e-6)
                {
                    forward = Vector3.forward;
                }
                Vector3 up = middle - wrest;
                if (up.sqrMagnitude < 1e-6)
                {
                    up = Vector3.up;
                }
                rotation = Quaternion.LookRotation(forward, up);
            }
            else
            {
                position = points[0];
                var cameraTransform = GestureProvider.Current.transform;
                rotation = Quaternion.LookRotation(position - cameraTransform.position);
            }
        }
示例#2
0
 void SetFingerPoints(GestureResultRaw hand, wvr.WVR_SingleFinger_t finger, int startIndex)
 {
     hand.points[startIndex]     = WaveVR_Utils.GetPosition(finger.joint1);
     hand.points[startIndex + 1] = WaveVR_Utils.GetPosition(finger.joint2);
     hand.points[startIndex + 2] = WaveVR_Utils.GetPosition(finger.joint3);
     hand.points[startIndex + 3] = WaveVR_Utils.GetPosition(finger.tip);
 }
示例#3
0
        void SetHandPoints(GestureResultRaw hand, wvr.WVR_PoseState_t pose, wvr.WVR_Fingers_t fingers)
        {
            if (hand == null || !pose.IsValidPose)
            {
                return;
            }
            rigidTransform.update(pose.PoseMatrix);
            hand.points[0] = rigidTransform.pos;
            SetFingerPoints(hand, fingers.thumb, 1);
            SetFingerPoints(hand, fingers.index, 5);
            SetFingerPoints(hand, fingers.middle, 9);
            SetFingerPoints(hand, fingers.ring, 13);
            SetFingerPoints(hand, fingers.pinky, 17);

            // calculate pinch level
            hand.pinchLevel = Mathf.Clamp01(0.0425f - Vector3.Distance(hand.points[4], hand.points[8])) / 0.025f;

            // apply camera offset to hand points
            var transform = GestureProvider.Current.transform;

            if (transform.parent != null)
            {
                for (int i = 0; i < 21; i++)
                {
                    hand.points[i] = transform.parent.rotation * hand.points[i] + transform.parent.position;
                }
            }
        }
        internal GestureResult(GestureResultRaw raw)
        {
            isLeft     = raw.isLeft;
            gesture    = raw.gesture;
            points     = raw.points;
            confidence = raw.confidence;
            var pinchInfo = new PinchInfo();

            pinchInfo.pinchLevel = raw.pinchLevel;

            if (GestureProvider.HaveSkeleton)
            {
                Vector3 wrist = points[0], index = points[5], middle = points[9];
                Vector3 vec1    = index - wrist;
                Vector3 vec2    = middle - wrist;
                Vector3 forward = isLeft ? Vector3.Cross(vec1, vec2) : Vector3.Cross(vec2, vec1);

                position             = (middle + wrist) / 2;
                rotation             = Quaternion.LookRotation(forward, vec2);
                pinchInfo.pinchStart = (points[8] + points[4] * 3) / 4;
                var start = (GestureProvider.Current.transform.position + position) / 2;
                pinchInfo.pinchDirection = pinchInfo.pinchStart - start;
            }
            else
            {
                position = pinchInfo.pinchStart = points[0];
                pinchInfo.pinchDirection = position - GestureProvider.Current.transform.position;
                rotation = Quaternion.LookRotation(pinchInfo.pinchDirection);
            }
            pinch = pinchInfo;
        }
示例#5
0
        GestureResultRaw CreateHand(bool left)
        {
            var hand = new GestureResultRaw();

            hand.isLeft     = left;
            hand.points     = new Vector3[21];
            hand.confidence = 1;
            return(hand);
        }
示例#6
0
        public override IEnumerator Setup()
        {
            var transform  = GestureProvider.Current.transform;
            var gameObject = GestureProvider.Current.gameObject;

            if (WaveVR_GestureManager.Instance == null)
            {
                gameObject.AddComponent <WaveVR_GestureManager>();
                WaveVR_GestureManager.Instance.EnableHandGesture  = false;
                WaveVR_GestureManager.Instance.EnableHandTracking = false;
            }

            leftHand  = CreateHand(true);
            rightHand = CreateHand(false);
            yield break;
        }