/// <summary>
        /// Called by Handles when they are released.
        /// </summary>
        public void NotifyHandleDeactivated(TransformHandle handle)
        {
            if (handle is TransformTranslationHandle)
            {
                _activeTranslationAxes.Remove(((TransformTranslationHandle)handle).axis);
            }

            _activeHandles.Remove(handle);

            switch (_toolState)
            {
            case ToolState.Idle:
                Debug.LogWarning("Warning: Handle was deactived while Tool was already idle.");
                break;

            default:
                if (_activeHandles.Count == 0)
                {
                    _toolState = ToolState.Idle;
                }
                break;
            }
        }
        /// <summary>
        /// Called by handles when they are grasped.
        /// </summary>
        /// <param name="handle"></param>
        public void NotifyHandleActivated(TransformHandle handle)
        {
            switch (_toolState)
            {
            case ToolState.Idle:
                _activeHandles.Add(handle);

                if (handle is TransformTranslationHandle)
                {
                    _toolState = ToolState.Translating;
                    _activeTranslationAxes.Add(((TransformTranslationHandle)handle).axis);
                }
                else
                {
                    _toolState = ToolState.Rotating;
                }
                break;

            case ToolState.Translating:
                if (handle is TransformRotationHandle)
                {
                    Debug.LogError("Error: Can't rotate a transform while it is already being "
                                   + "translated.");
                }
                else
                {
                    _activeHandles.Add(handle);
                    _activeTranslationAxes.Add(((TransformTranslationHandle)handle).axis);
                }
                break;

            case ToolState.Rotating:
                Debug.LogError("Error: Only one handle can be active while a transform is being "
                               + "rotated.");
                break;
            }
        }
Esempio n. 3
0
        // Checks to see if object is being scaled + sets the intialScaling variable of object
        private void ScalingSetup()
        {
            if (_activeHandles.Count == 2)
            {
                float xCount = 0;
                float yCount = 0;
                float zCount = 0;

                foreach (TransformHandle handle in _activeHandles)
                {
                    if (handle.name == "Translate Pos X" || handle.name == "Translate Neg X")
                    {
                        xCount += 1;
                        if (xCount == 1)
                        {
                            HandleOne = handle;
                        }
                        if (xCount == 2)
                        {
                            HandleTwo  = handle;
                            ChosenAxis = ScaleAxis.x;
                            _toolState = ToolState.Scaling;
                        }
                    }
                    if (handle.name == "Translate Pos Y" || handle.name == "Translate Neg Y")
                    {
                        yCount += 1;

                        if (yCount == 1)
                        {
                            HandleOne = handle;
                        }
                        if (yCount == 2)
                        {
                            HandleTwo  = handle;
                            ChosenAxis = ScaleAxis.y;
                            _toolState = ToolState.Scaling;
                        }
                    }
                    if (handle.name == "Translate Pos Z" || handle.name == "Translate Neg Y")
                    {
                        zCount += 1;
                        if (zCount == 1)
                        {
                            HandleOne = handle;
                        }
                        if (zCount == 2)
                        {
                            HandleTwo  = handle;
                            ChosenAxis = ScaleAxis.z;
                            _toolState = ToolState.Scaling;
                        }
                    }
                }

                if (xCount == 2 || yCount == 2 || zCount == 2)
                {
                    if (!initialScaled)
                    {
                        Vector3 leftPosition  = new Vector3(hands[0].PalmPosition.x * 1 / 1000, hands[0].PalmPosition.y * 1 / 1000, hands[0].PalmPosition.z * 1 / 1000);
                        Vector3 rightPosition = new Vector3(hands[1].PalmPosition.x * 1 / 1000, hands[1].PalmPosition.y * 1 / 1000, hands[1].PalmPosition.z * 1 / 1000);

                        initialScaling      = target.transform.localScale;
                        initialHandDistance = Vector3.Distance(leftPosition, rightPosition);
                        initialScaled       = true;

                        InitialHandleOnePosition = HandleOne.transform.position;
                        InitialHandleTwoPosition = HandleTwo.transform.position;

                        InitialHandOnePosition = leftPosition;
                        InitialHandTwoPosition = rightPosition;
                    }
                }
            }

            // To reset values if we're done/not scaling.
            if (_activeHandles.Count != 2)
            {
                initialScaled = false;
            }
        }
        private void updateHandles()
        {
            switch (_toolState)
            {
            case ToolState.Idle:
                // Find the closest handle to any InteractionHand.
                TransformHandle closestHandleToAnyHand = null;
                float           closestHandleDist      = float.PositiveInfinity;
                foreach (var intController in interactionManager.interactionControllers
                         .Query()
                         .Where(controller => controller.isTracked))
                {
                    if (!intController.isPrimaryHovering)
                    {
                        continue;
                    }
                    TransformHandle testHandle = intController.primaryHoveredObject
                                                 .gameObject
                                                 .GetComponent <TransformHandle>();

                    if (testHandle == null || !_transformHandles.Contains(testHandle))
                    {
                        continue;
                    }

                    float testDist = intController.primaryHoverDistance;
                    if (testDist < closestHandleDist)
                    {
                        closestHandleToAnyHand = testHandle;
                        closestHandleDist      = testDist;
                    }
                }

                // While idle, only show the closest handle to any hand, hide other handles.
                foreach (var handle in _transformHandles)
                {
                    if (closestHandleToAnyHand != null && handle == closestHandleToAnyHand)
                    {
                        handle.EnsureVisible();
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;

            case ToolState.Translating:
                // While translating, show all translation handles except the other handle
                // on the same axis, and hide rotation handles.
                foreach (var handle in _transformHandles)
                {
                    if (handle is TransformTranslationHandle)
                    {
                        var translateHandle = handle as TransformTranslationHandle;

                        if (!_activeHandles.Contains(translateHandle) &&
                            _activeTranslationAxes.Contains(translateHandle.axis))
                        {
                            handle.EnsureHidden();
                        }
                        else
                        {
                            handle.EnsureVisible();
                        }
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;

            case ToolState.Rotating:
                // While rotating, only show the active rotating handle.
                foreach (var handle in _transformHandles)
                {
                    if (_activeHandles.Contains(handle))
                    {
                        handle.EnsureVisible();
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;
            }
        }
Esempio n. 5
0
        private void updateHandles()
        {
            switch (_toolState)
            {
            case ToolState.Idle:
                // Find the closest handle to any InteractionHand.
                TransformHandle closestHandleToAnyHand = null;
                float           closestHandleDist      = float.PositiveInfinity;
                foreach (var intController in interactionManager.interactionControllers
                         .Query()
                         .Where(controller => controller.isTracked))
                {
                    if (!intController.isPrimaryHovering)
                    {
                        continue;
                    }
                    TransformHandle testHandle = intController.primaryHoveredObject
                                                 .gameObject
                                                 .GetComponent <TransformHandle>();

                    if (testHandle == null || !_transformHandles.Contains(testHandle))
                    {
                        continue;
                    }

                    float testDist = intController.primaryHoverDistance;
                    if (testDist < closestHandleDist)
                    {
                        closestHandleToAnyHand = testHandle;
                        closestHandleDist      = testDist;
                    }
                }

                // While idle, only show the closest handle to any hand, hide other handles.
                foreach (var handle in _transformHandles)
                {
                    if (closestHandleToAnyHand != null && handle == closestHandleToAnyHand)
                    {
                        // Check if rotation should be restricted (aka is it connected?)
                        if (ObjectConnected)
                        {
                            // If it's a Link, then shouldn't be able to rotate it (but should be able to translate the parent using it)
                            if (target.GetComponent <ObjectJoint>() == null)
                            {
                                if (closestHandleToAnyHand is TransformTranslationHandle)
                                {
                                    handle.EnsureVisible();
                                }
                                else
                                {
                                    handle.EnsureHidden();
                                }
                            }
                            // If it's a Joint, then we want to be able to rotate around the designated axis.
                            else
                            {
                                if (rotateHandleNames.Contains(closestHandleToAnyHand.name) || closestHandleToAnyHand is TransformTranslationHandle)
                                {
                                    handle.EnsureVisible();
                                }
                                else
                                {
                                    handle.EnsureHidden();
                                }
                            }
                        }
                        // If rotation shouldn't be restricted, then just show any handle.
                        else
                        {
                            handle.EnsureVisible();
                        }
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;

            case ToolState.Translating:
                // ***************** TODO: How about if we make others not visible and only axis visible? ************************
                // While translating, show all translation handles except the other handle
                // on the same axis, and hide rotation handles.
                foreach (var handle in _transformHandles)
                {
                    if (handle is TransformTranslationHandle)
                    {
                        var translateHandle = handle as TransformTranslationHandle;

                        if (!_activeHandles.Contains(translateHandle) &&
                            _activeTranslationAxes.Contains(translateHandle.axis))
                        {
                            handle.EnsureVisible();
                        }
                        else
                        {
                            handle.EnsureVisible();
                        }
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;

            case ToolState.Rotating:
                // While rotating, only show the active rotating handle.
                foreach (var handle in _transformHandles)
                {
                    if (_activeHandles.Contains(handle))
                    {
                        handle.EnsureVisible();
                    }
                    else
                    {
                        handle.EnsureHidden();
                    }
                }
                break;
            }
        }