Exemplo n.º 1
0
        protected override void Apply(HandDataAsset data)
        {
            Pose rootToPointer = PoseUtils.RelativeOffset(data.PointerPose, data.Root);

            rootToPointer.position = (rootToPointer.position / data.HandScale) * _scale;
            PoseUtils.Multiply(data.Root, rootToPointer, ref data.PointerPose);

            data.HandScale = _scale;
        }
Exemplo n.º 2
0
        private void UpdateWristJoint(HandJointId jointid, ref Pose pose)
        {
            int jointIndex = (int)jointid;

            if ((_dirtyWristJoints & (1 << jointIndex)) != 0)// its dirty
            {
                if (jointid > HandJointId.HandWristRoot)
                {
                    UpdateWristJoint((HandJointId)_originalJoints[jointIndex].parent, ref pose);
                    PoseUtils.Multiply(pose, _localPoses[jointIndex], ref _posesFromWrist[jointIndex]);
                }
                _dirtyWristJoints = _dirtyWristJoints & ~(1 << jointIndex); //set clean
            }
            pose.CopyFrom(_posesFromWrist[jointIndex]);
        }
Exemplo n.º 3
0
        public Pose WorldJointPose(HandJointId jointid, Pose rootPose, float handScale)
        {
            int jointIndex = (int)jointid;

            if ((_dirtyWorldJoints & (1 << jointIndex)) != 0) //its dirty
            {
                Pose wristPose = Pose.identity;
                UpdateWristJoint(jointid, ref wristPose);
                PoseUtils.Multiply(_localPoses[0], wristPose, ref _worldPoses[jointIndex]);
                _worldPoses[jointIndex].position *= handScale;
                _worldPoses[jointIndex].Postmultiply(rootPose);

                _dirtyWorldJoints = _dirtyWorldJoints & ~(1 << jointIndex); //set clean
            }

            return(_worldPoses[jointIndex]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Each call while the hand is selecting/grabbing an interactable, it moves the item to the
        /// new position while also attracting it towards the hand if the snapping mode requires it.
        ///
        /// In some cases the parameter can be null, for example if the selection was interrupted
        /// by another hand grabbing the object. In those cases it will come out of the release
        /// state once the grabbing gesture properly finishes.
        /// </summary>
        /// <param name="interactable">The selected item</param>
        protected override void DoSelectUpdate()
        {
            HandGrabInteractable interactable = _selectedInteractable;
            if (interactable == null)
            {
                _currentSnap.Clear();
                ShouldUnselect = true;
                return;
            }

            Pose grabbingPoint = PoseUtils.Multiply(_trackedGripPose, _snapOffset);
            _movement.UpdateTarget(grabbingPoint);
            _movement.Tick();

            HandGrab.StoreGrabData(this, interactable, ref _lastInteractableData);
            ShouldUnselect = HandGrab.ComputeShouldUnselect(this, interactable);

        }
Exemplo n.º 5
0
        /// <summary>
        /// When a new interactable is selected, start the grab at the ideal point. When snapping is
        /// involved that can be a point in the interactable offset from the hand
        /// which will be stored to progressively reduced it in the next updates,
        /// effectively attracting the object towards the hand.
        /// When no snapping is involved the point will be the grip point of the hand directly.
        /// Note: ideally this code would be in InteractableSelected but it needs
        /// to be called before the object is marked as active.
        /// </summary>
        /// <param name="snap">The selected Snap Data </param>
        protected override void InteractableSelected(HandGrabInteractable interactable)
        {
            if (SnapAddress.IsNullOrInvalid(_currentSnap))
            {
                base.InteractableSelected(interactable);
                return;
            }

            if (_currentSnap.SnappedToPinch)
            {
                _snapOffset = PoseUtils.RelativeOffset(_trackedPinchPose, _trackedGripPose);
            }
            else
            {
                _snapOffset = Pose.identity;
            }

            Pose handGrabStartPose = PoseUtils.Multiply(_trackedGripPose, _snapOffset);
            Pose interactableGrabStartPose = _currentSnap.WorldSnapPose;
            _movement = interactable.GenerateMovement(interactableGrabStartPose, handGrabStartPose);
            base.InteractableSelected(interactable);
        }
Exemplo n.º 6
0
        private void UpdateAllPosesFromWrist()
        {
            if (_dirtyWristJoints == 0) //its completely clean
            {
                return;
            }

            for (int jointIndex = 0; jointIndex < Constants.NUM_HAND_JOINTS; ++jointIndex)
            {
                if ((_dirtyWristJoints & (1 << jointIndex)) == 0) //its clean
                {
                    continue;
                }

                HandSkeletonJoint originalJoint = _originalJoints[jointIndex];
                if (originalJoint.parent >= 0)
                {
                    PoseUtils.Multiply(_posesFromWrist[originalJoint.parent],
                                       _localPoses[jointIndex], ref _posesFromWrist[jointIndex]);
                }
            }
            _dirtyWristJoints = 0; //set all clean
        }
        public void CustomAlignmentHandles(ProxyAlignmentForce alignmentForce)
        {
            Handles.matrix = Matrix4x4.identity;
            if (!alignmentForce || (!alignmentForce.enabled) || !alignmentForce.targetProxy)
            {
                return;
            }


            Pose myPose = PoseUtils.FromTransform(alignmentForce.transform);

            if (!alignmentForce.TryGetTargetPose(out Pose targetPose, true))
            {
                return;
            }
            if (!alignmentForce.TryGetGoalPose(out Pose goalPose, true))
            {
                return;
            }
            Handles.color = Color.gray;
            Handles.DrawLine(targetPose.position, goalPose.position);
            Handles.color = Color.green;
            Handles.DrawLine(myPose.position, goalPose.position);
        }
Exemplo n.º 8
0
        public void LerpObjectTowarsHand(Pose gripPose, float t)
        {
            Pose targetPose = PoseUtils.Lerp(originalPose, AllignedObjectPose(gripPose), t);

            point.RelativeTo.SetPose(targetPose);
        }
        protected override void UpdateData()
        {
            _handDataAsset.Config      = Config;
            _handDataAsset.IsDataValid = true;
            _handDataAsset.IsConnected = (OVRInput.GetConnectedControllers() & _ovrController) > 0;
            if (!_handDataAsset.IsConnected)
            {
                // revert state fields to their defaults
                _handDataAsset.IsTracked         = default;
                _handDataAsset.RootPoseOrigin    = default;
                _handDataAsset.PointerPoseOrigin = default;
                _handDataAsset.IsHighConfidence  = default;
                for (var fingerIdx = 0; fingerIdx < Constants.NUM_FINGERS; fingerIdx++)
                {
                    _handDataAsset.IsFingerPinching[fingerIdx]       = default;
                    _handDataAsset.IsFingerHighConfidence[fingerIdx] = default;
                }
                return;
            }

            _handDataAsset.IsTracked        = true;
            _handDataAsset.IsHighConfidence = true;
            _handDataAsset.HandScale        = 1f;

            _handDataAsset.IsDominantHand =
                OVRInput.GetDominantHand() == OVRInput.Handedness.LeftHanded &&
                _handedness == Handedness.Left ||
                (OVRInput.GetDominantHand() == OVRInput.Handedness.RightHanded &&
                 _handedness == Handedness.Right);

            float indexStrength = _pinchCurve.Evaluate(OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, _ovrController));
            float gripStrength  = _pinchCurve.Evaluate(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, _ovrController));

            _handDataAsset.IsFingerHighConfidence[(int)HandFinger.Thumb] = true;
            _handDataAsset.IsFingerPinching[(int)HandFinger.Thumb]       = indexStrength >= 1f || gripStrength >= 1f;
            _handDataAsset.FingerPinchStrength[(int)HandFinger.Thumb]    = Mathf.Max(indexStrength, gripStrength);

            _handDataAsset.IsFingerHighConfidence[(int)HandFinger.Index] = true;
            _handDataAsset.IsFingerPinching[(int)HandFinger.Index]       = indexStrength >= 1f;
            _handDataAsset.FingerPinchStrength[(int)HandFinger.Index]    = indexStrength;

            _handDataAsset.IsFingerHighConfidence[(int)HandFinger.Middle] = true;
            _handDataAsset.IsFingerPinching[(int)HandFinger.Middle]       = gripStrength >= 1f;
            _handDataAsset.FingerPinchStrength[(int)HandFinger.Middle]    = gripStrength;

            _handDataAsset.IsFingerHighConfidence[(int)HandFinger.Ring] = true;
            _handDataAsset.IsFingerPinching[(int)HandFinger.Ring]       = gripStrength >= 1f;
            _handDataAsset.FingerPinchStrength[(int)HandFinger.Ring]    = gripStrength;

            _handDataAsset.IsFingerHighConfidence[(int)HandFinger.Pinky] = true;
            _handDataAsset.IsFingerPinching[(int)HandFinger.Pinky]       = gripStrength >= 1f;
            _handDataAsset.FingerPinchStrength[(int)HandFinger.Pinky]    = gripStrength;

            _handDataAsset.PointerPoseOrigin = PoseOrigin.RawTrackedPose;
            _handDataAsset.PointerPose       = new Pose(
                OVRInput.GetLocalControllerPosition(_ovrController),
                OVRInput.GetLocalControllerRotation(_ovrController));

            for (int i = 0; i < _bones.Length; i++)
            {
                _handDataAsset.Joints[i] = _bones[i].localRotation;
            }

            _handDataAsset.Joints[0] = WristFixupRotation;

            // Convert controller pose from world to tracking space.
            Pose pose = new Pose(_ovrControllerAnchor.position, _ovrControllerAnchor.rotation);

            pose = Config.TrackingToWorldTransformer.ToTrackingPose(pose);

            PoseUtils.Multiply(pose, _poseOffset, ref _handDataAsset.Root);
            _handDataAsset.RootPoseOrigin = PoseOrigin.RawTrackedPose;
        }
Exemplo n.º 10
0
        public void UpdateTarget(Pose target)
        {
            Pose grabberDelta = PoseUtils.RelativeOffset(target, _originalTarget);

            PoseUtils.Multiply(_originalSource, grabberDelta, ref _current);
        }