protected virtual void GetTargetValues(out Vector3 targetHandPosition, out Quaternion targetHandRotation, out Vector3 targetItemPosition, out Quaternion targetItemRotation)
        {
            if (AttachedHands.Count == 1) //faster path if only one hand, which is the standard scenario
            {
                NVRHand hand = AttachedHands[0];

                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
                else
                {
                    targetItemPosition = this.transform.position;
                    targetItemRotation = this.transform.rotation;

                    targetHandPosition = PickupTransforms[hand].position;
                    targetHandRotation = PickupTransforms[hand].rotation;
                }
            }
            else
            {
                Vector3    cumulativeItemVector   = Vector3.zero;
                Vector4    cumulativeItemRotation = Vector4.zero;
                Quaternion?firstItemRotation      = null;
                targetItemRotation = Quaternion.identity;

                Vector3    cumulativeHandVector   = Vector3.zero;
                Vector4    cumulativeHandRotation = Vector4.zero;
                Quaternion?firstHandRotation      = null;
                targetHandRotation = Quaternion.identity;

                for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
                {
                    NVRHand hand = AttachedHands[handIndex];

                    if (InteractionPoint != null && handIndex == 0)
                    {
                        targetItemRotation    = InteractionPoint.rotation;
                        cumulativeItemVector += InteractionPoint.position;

                        targetHandRotation    = hand.transform.rotation;
                        cumulativeHandVector += hand.transform.position;
                    }
                    else
                    {
                        targetItemRotation    = this.transform.rotation;
                        cumulativeItemVector += this.transform.position;

                        targetHandRotation    = PickupTransforms[hand].rotation;
                        cumulativeHandVector += PickupTransforms[hand].position;
                    }

                    if (firstItemRotation == null)
                    {
                        firstItemRotation = targetItemRotation;
                    }
                    if (firstHandRotation == null)
                    {
                        firstHandRotation = targetHandRotation;
                    }

                    targetItemRotation = NVRHelpers.AverageQuaternion(ref cumulativeItemRotation, targetItemRotation, firstItemRotation.Value, handIndex);
                    targetHandRotation = NVRHelpers.AverageQuaternion(ref cumulativeHandRotation, targetHandRotation, firstHandRotation.Value, handIndex);
                }

                targetItemPosition = cumulativeItemVector / AttachedHands.Count;
                targetHandPosition = cumulativeHandVector / AttachedHands.Count;
            }
        }
예제 #2
0
        protected virtual void GetTargetValues(out Vector3 targetHandPosition, out Quaternion targetHandRotation, out Vector3 targetItemPosition, out Quaternion targetItemRotation)
        {
            if (AttachedHands.Count == 1) //faster path if only one hand, which is the standard scenario
            {
                NVRHand hand = AttachedHands[0];

                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
                else
                {
                    targetItemPosition = PickupTransforms[hand].position;;
                    targetItemRotation = PickupTransforms[hand].rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
            }
            else if (AttachedHands.Count == 2)
            {
                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = AttachedHands[0].transform.position;
                    targetHandRotation = Quaternion.LookRotation(AttachedHands[1].transform.position - AttachedHands[0].transform.position, Vector3.up);
                }
                else
                {
                    NVRHand mainHand;
                    NVRHand secondHand;

                    if (Vector3.Distance(AttachedHands[0].transform.position, transform.position) >= Vector3.Distance(AttachedHands[1].transform.position, transform.position))
                    {
                        mainHand   = AttachedHands[0];
                        secondHand = AttachedHands[1];
                    }
                    else
                    {
                        mainHand   = AttachedHands[1];
                        secondHand = AttachedHands[0];
                    }

                    targetItemPosition = PickupTransforms[mainHand].position;
                    targetItemRotation = this.transform.rotation;

                    targetHandPosition = mainHand.transform.position;
                    if (PickupTransforms[mainHand].localPosition.z <= 0)
                    {
                        targetHandRotation = Quaternion.LookRotation(secondHand.transform.position - mainHand.transform.position, Vector3.up);
                    }
                    else
                    {
                        targetHandRotation = Quaternion.LookRotation(mainHand.transform.position - secondHand.transform.position, Vector3.up);
                    }
                }
            }
            else
            {
                Vector3    cumulativeItemVector   = Vector3.zero;
                Vector4    cumulativeItemRotation = Vector4.zero;
                Quaternion?firstItemRotation      = null;
                targetItemRotation = Quaternion.identity;

                Vector3    cumulativeHandVector   = Vector3.zero;
                Vector4    cumulativeHandRotation = Vector4.zero;
                Quaternion?firstHandRotation      = null;
                targetHandRotation = Quaternion.identity;

                for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
                {
                    NVRHand hand = AttachedHands[handIndex];

                    if (InteractionPoint != null && handIndex == 0)
                    {
                        targetItemRotation    = InteractionPoint.rotation;
                        cumulativeItemVector += InteractionPoint.position;

                        targetHandRotation    = hand.transform.rotation;
                        cumulativeHandVector += hand.transform.position;
                    }
                    else
                    {
                        targetItemRotation    = this.transform.rotation;
                        cumulativeItemVector += this.transform.position;

                        targetHandRotation    = PickupTransforms[hand].rotation;
                        cumulativeHandVector += PickupTransforms[hand].position;
                    }

                    if (firstItemRotation == null)
                    {
                        firstItemRotation = targetItemRotation;
                    }
                    if (firstHandRotation == null)
                    {
                        firstHandRotation = targetHandRotation;
                    }
                }
                targetItemPosition = cumulativeItemVector / AttachedHands.Count;
                targetHandPosition = cumulativeHandVector / AttachedHands.Count;
                targetItemRotation = NVRHelpers.AverageQuaternion(ref cumulativeItemRotation, targetItemRotation, firstItemRotation.Value, AttachedHands.Count);
                targetHandRotation = NVRHelpers.AverageQuaternion(ref cumulativeHandRotation, targetHandRotation, firstHandRotation.Value, AttachedHands.Count);
            }
        }