Exemple #1
0
        /// <summary>
        /// Starts scaling the object with the given input source.
        /// </summary>
        public void StartScaling(IInputSource inputSource, uint inputSourceId)
        {
            if (isScaling)
            {
                return;
            }

            if (inputSource == null || !inputSource.SupportsInputInfo(inputSourceId, SupportedInputInfo.Position))
            {
                Debug.Log("The provided input source does not support the required positional info.");
                return;
            }

            currentInputSource   = inputSource;
            currentInputSourceId = inputSourceId;

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

            currentInputSource.TryGetPosition(currentInputSourceId, out prevHandPosition);
            grabPoint     = prevHandPosition;
            scaleUpVector = Vector3.Normalize(grabPoint - TargetGameObject.transform.position);

            isScaling = true;
            StartedScaling.RaiseEvent();
        }
Exemple #2
0
    // Update is called once per frame
    // FixedUpdate is called in a regular timeline, same time between each call, to use for physics
    void FixedUpdate()
    {
        // bit shift the index of the layer to get a bit mask
        int layerMask = 1 << 8; // the layer 8 is the kern layer

        RaycastHit gazeHitResult = GazeManager.Instance.HitInfo;

        if (!isInputUp)
        {
            Debug.DrawLine(drawOriginPosition, drawOriginPosition + (replacedHandPosition - drawOriginPosition) * 2);

            //get current inputsource Position information if we can
            if (currentInputSource.SupportsInputInfo(currentInputSourceId, SupportedInputInfo.Position))
            {
                currentInputSource.TryGetPosition(currentInputSourceId, out handPosition);
                //Debug.Log("Hand Position " + handPosition);
                //replacing hand close to the user gaze direction to avoid occlusion issues
                replacedHandPosition = handPosition + replacingHand;

                //Raycast(originPoint, DIRECTION, etc.)
                if (Physics.Raycast(drawOriginPosition, replacedHandPosition - drawOriginPosition, out hit, Mathf.Infinity, layerMask))
                {
                    //drawingCursor show current drawing position and orientation
                    Vector3 lookForward = -GazeManager.Instance.GazeNormal; //Get the forward vector looking back at camera
                    drawingCursor.transform.position = hit.point + (lookForward * 0.02f);
                    drawingCursor.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(gazeHitResult.normal, lookForward, 0.5f), Vector3.up);
                    drawingCursor.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f));

                    if (currentPoints.Count == 1)//first time in the loop
                    {
                        drawingCursor.SetActive(true);
                        mainCursor.SetVisiblity(false);
                    }
                    //to avoid a point repetitions
                    if (currentPoints.Count != 0 && currentPoints[currentPoints.Count - 1] != hit.point)
                    {
                        currentPoints.Add(hit.point + hit.normal * 0.0015f);
                    }
                    //drawing the line
                    if (currentPoints.Count != 0)
                    {
                        //setting the points of the line one by one
                        //using this instead of setPositions because it's more logical to use list here
                        currentLine.positionCount = currentPoints.Count;
                        for (int i = 0; i < currentPoints.Count; i++)
                        {
                            currentLine.SetPosition(i, currentPoints[i]);
                        }
                    }
                }
                else //no collision found between drawOriginPosition, handPosition and 3Dmodel
                {
                    drawingCursor.transform.position = replacedHandPosition + Vector3.Normalize(replacedHandPosition - drawOriginPosition) * 1.5f;
                }
            }
        }
    }
Exemple #3
0
        /// <summary>
        /// Starts rotating the object with the given input source.
        /// </summary>
        public void StartRotating(IInputSource inputSource, uint inputSourceId)
        {
            if (IsRotating)
            {
                return;
            }

            if (inputSource == null || !inputSource.SupportsInputInfo(inputSourceId, SupportedInputInfo.Position))
            {
                Debug.Log("The input source must provide positional data for Rotatable to be usable.");
                return;
            }

            currentInputSource   = inputSource;
            currentInputSourceId = inputSourceId;

            currentInputSource.TryGetPosition(currentInputSourceId, out prevHandPosition);

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

            IsRotating = true;
            StartedRotating.RaiseEvent();
        }
Exemple #4
0
 private bool SupportsPointingRay(IInputSource inputSource, uint sourceId)
 {
     return(inputSource.SupportsInputInfo(sourceId, SupportedInputInfo.Pointing));
 }