示例#1
0
        /// <summary>
        /// Starts dragging the object.
        /// </summary>
        private void StartDragging(Vector3 initialDraggingPosition)
        {
            if (!isDraggingEnabled || isDragging)
            {
                return;
            }

            // TODO: robertes: Fix push/pop and single-handler model so that multiple HandDraggable components can be active at once.

            // Add self as a modal input handler, to get all inputs during the manipulation
            InputSystem.PushModalInputHandler(gameObject);

            isDragging = true;

            if (hostRigidbody != null)
            {
                hostRigidbodyWasKinematic = hostRigidbody.isKinematic;
                hostRigidbody.isKinematic = true;
            }

            Transform cameraTransform = CameraCache.Main.transform;

            Vector3 inputPosition;

            currentPointer.TryGetPointerPosition(out inputPosition);

            Vector3 pivotPosition = GetHandPivotPosition(cameraTransform);

            handRefDistance         = Vector3.Magnitude(inputPosition - pivotPosition);
            objectReferenceDistance = Vector3.Magnitude(initialDraggingPosition - pivotPosition);

            Vector3 objForward = hostTransform.forward;
            Vector3 objUp      = hostTransform.up;

            // Store where the object was grabbed from
            objectReferenceGrabPoint = cameraTransform.transform.InverseTransformDirection(hostTransform.position - initialDraggingPosition);

            Vector3 objDirection  = Vector3.Normalize(initialDraggingPosition - pivotPosition);
            Vector3 handDirection = Vector3.Normalize(inputPosition - pivotPosition);

            // in camera space
            objForward    = cameraTransform.InverseTransformDirection(objForward);
            objUp         = cameraTransform.InverseTransformDirection(objUp);
            objDirection  = cameraTransform.InverseTransformDirection(objDirection);
            handDirection = cameraTransform.InverseTransformDirection(handDirection);

            objectReferenceForward = objForward;
            objectReferenceUp      = objUp;

            // Store the initial offset between the hand and the object, so that we can consider it when dragging
            gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection);
            draggingPosition  = initialDraggingPosition;
        }
示例#2
0
        private void TransformHandleWithPoint()
        {
            if (currentHandleType != HandleType.None)
            {
                Vector3 newGrabbedPosition;

                if (usingPose == false)
                {
                    Vector3 newRemotePoint;
                    currentPointer.TryGetPointerPosition(out newRemotePoint);
                    newGrabbedPosition = initialGrabbedPosition + (newRemotePoint - initialGrabPoint);
                }
                else
                {
                    if (initialGazePoint == Vector3.zero)
                    {
                        return;
                    }

                    newGrabbedPosition = currentPosePosition;
                }

                if (currentHandleType == HandleType.Rotation)
                {
                    RotateByHandle(newGrabbedPosition);
                }
                else if (currentHandleType == HandleType.Scale)
                {
                    ScaleByHandle(newGrabbedPosition);
                }
            }
        }
示例#3
0
        public void OnInputDown(InputEventData eventData)
        {
            if (currentInputSource == null)
            {
                IMixedRealityPointer pointer = eventData.InputSource.Pointers[0];
                Ray ray;
                if (pointer.TryGetPointingRay(out ray))
                {
                    handleMoveType = HandleMoveType.Ray;
                    float    distance;
                    Collider grabbedCollider = GetGrabbedCollider(ray, out distance);

                    if (grabbedCollider != null)
                    {
                        currentInputSource  = eventData.InputSource;
                        currentPointer      = pointer;
                        grabbedHandle       = grabbedCollider.gameObject;
                        currentHandleType   = GetHandleType(grabbedHandle);
                        currentRotationAxis = GetRotationAxis(grabbedHandle);
                        currentPointer.TryGetPointingRay(out initialGrabRay);
                        initialGrabMag         = distance;
                        initialGrabbedPosition = grabbedHandle.transform.position;
                        initialGrabbedCentroid = targetObject.transform.position;
                        initialScale           = targetObject.transform.localScale;
                        pointer.TryGetPointerPosition(out initialGrabPoint);
                        ShowOneHandle(grabbedHandle);
                        initialGazePoint = Vector3.zero;
                    }
                }
            }
        }
        /// <summary>
        /// Starts dragging the object.
        /// </summary>
        private void StartDragging(Vector3 initialDraggingPosition)
        {
            if (!isDraggingEnabled || isDragging)
            {
                return;
            }

            Transform cameraTransform = CameraCache.Main.transform;

            currentPointer.IsFocusLocked = true;
            isDragging = true;

            if (hostRigidbody != null)
            {
                hostRigidbodyWasKinematic = hostRigidbody.isKinematic;
                hostRigidbody.isKinematic = true;
            }

            if (isDraggingWithSourcePose)
            {
                Vector3 pivotPosition = HandPivotPosition;
                objectReferenceDistance  = Vector3.Magnitude(initialDraggingPosition - pivotPosition);
                objectReferenceDirection = cameraTransform.InverseTransformDirection(Vector3.Normalize(initialDraggingPosition - pivotPosition));
            }
            else
            {
                Vector3 inputPosition;
                currentPointer.TryGetPointerPosition(out inputPosition);

                previousPointerPositionHeadSpace = cameraTransform.InverseTransformPoint(inputPosition);
                stickLength = Vector3.Distance(initialDraggingPosition, inputPosition);
            }

            // Store where the object was grabbed from
            objectReferenceGrabPoint = cameraTransform.transform.InverseTransformDirection(hostTransform.position - initialDraggingPosition);

            // in camera space
            objectReferenceForward = cameraTransform.InverseTransformDirection(hostTransform.forward);
            objectReferenceUp      = cameraTransform.InverseTransformDirection(hostTransform.up);

            draggingPosition = initialDraggingPosition;
        }