コード例 #1
0
        // Grab with second hand moving to object
        private static void GrabRigidbodyBarHandle2(HandTarget handTarget, Rigidbody objRigidbody, Handle handle)
        {
            //Debug.Log("Grab Second Hand");
            Transform objTransform = handle.transform;

            MoveHandBoneToHandle(handTarget, handle);
            GrabRigidbodyJoint(handTarget, objRigidbody);
            handTarget.grabbedHandle = handle;

            handTarget.handPhysics.mode = AdvancedHandPhysics.PhysicsMode.ForceLess;

            handTarget.handMovements.toOtherHandle = handTarget.grabbedHandle.GetWorldPosition() - handTarget.otherHand.grabbedHandle.GetWorldPosition();
            Quaternion hand2handle = Quaternion.LookRotation(handTarget.handMovements.toOtherHandle);

            handTarget.otherHand.handMovements.hand2handle = Quaternion.Inverse(hand2handle) * handTarget.otherHand.hand.target.transform.rotation;

            handTarget.grabbedRigidbody = true;
        }
コード例 #2
0
        public static void MoveObjectToHand(HandTarget handTarget, Transform objTransform, Handle handle)
        {
            //Quaternion localHandleRotation = handle.transform.rotation * Quaternion.Inverse(objTransform.rotation)
            Quaternion handleRotation = handle.transform.rotation * Quaternion.Inverse(objTransform.rotation) * Quaternion.Euler(handle.rotation);

            objTransform.rotation = handTarget.palmRotation * Quaternion.Inverse(handleRotation); // Quaternion.Euler(handle.rotation));

            Vector3 handleWPos = handle.transform.TransformPoint(handle.position);

            objTransform.Translate(handTarget.palmPosition - handleWPos, Space.World);
        }
コード例 #3
0
        private static void GrabRigidbodyHandle(HandTarget handTarget, Rigidbody objRigidbody, Handle handle)
        {
            Transform objTransform = objRigidbody.transform;

            if (AlreadyGrabbedWithOtherHand(handTarget, objRigidbody))
            {
                GrabRigidbodyBarHandle2(handTarget, objRigidbody, handle);
                return;
            }

            Joint joint = objRigidbody.GetComponent <Joint>();

            if (joint != null || objRigidbody.constraints != RigidbodyConstraints.None)
            {
                MoveHandBoneToHandle(handTarget, handle);

                // To add: if handle.rotation = true
                Vector3 handleWorldPosition = handle.transform.TransformPoint(handle.position);
                Vector3 handleLocalPosition = handTarget.hand.bone.transform.InverseTransformPoint(handleWorldPosition);

                Quaternion handleWorldRotation = handle.transform.rotation * Quaternion.Euler(handle.rotation);
                Vector3    handleRotationAxis  = handleWorldRotation * Vector3.up;

                Vector3 handleLocalRotationAxis = handTarget.hand.bone.transform.InverseTransformDirection(handleRotationAxis);

                GrabRigidbodyJoint(handTarget, objRigidbody, handleLocalPosition, handleLocalRotationAxis);
            }
            else
            {
                MoveObjectToHand(handTarget, objTransform, handle);
                GrabRigidbodyParenting(handTarget, objRigidbody);
            }
            handTarget.grabbedHandle = handle;
            if (handle.pose != null)
            {
                handTarget.poseMixer.SetPoseValue(handle.pose, 1);
            }
            handTarget.grabbedRigidbody = true;
        }