Exemple #1
0
    public void OnInputUp(InputEventData eventData)
    {
        if (currInputSource != null && eventData.SourceId == currInputSourceId)
        {
            //Debug.Log("InputUp");
            isHolding       = false;
            currInputSource = null;
            // Remove self as a modal input handler
            InputManager.Instance.PopModalInputHandler();
            //set the maincursor back
            mainCursor.SetVisiblity(true);

            //Project object
            if (option == 1)
            {
                RectangleSelection();
            }
            else if (option == 2)
            {
                RectangleProjection();
            }
            else
            {
                Debug.Log("Error option number should be 1 or 2");
            }
        }
    }
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;
                }
            }
        }
    }