Exemple #1
0
    public static RaycastHit FindPlayerGaze(Camera cam, bool wantTobii) // Finds the gazepoint of the player
    {
        Ray ray;

        if (wantTobii) // Allows us to avoid the expensive Tobii computations when we don't need them.
        {
            // Get gazepoint from tobii and create ray
            GazePoint gazePoint = TobiiAPI.GetGazePoint();
            if (gazePoint.IsValid && gazePoint.IsRecent())
            {
                Vector3 gazePosition = new Vector3(gazePoint.Screen.x, gazePoint.Screen.y, 0);
                ray = cam.ScreenPointToRay(gazePosition);
            }
            else  // Use mouse position if gaze position is unavailable
            {
                ray = cam.ScreenPointToRay(Input.mousePosition);
            }
        }
        else
        {
            ray = cam.ScreenPointToRay(Input.mousePosition);
        }


        // Find first intersection from light in direction of mouse in world space
        RaycastHit hit;

        Physics.SphereCast(ray.origin, sphereRadius, ray.direction, out hit);
        return(hit);
    }
Exemple #2
0
    void Update()
    {
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        //Location is calculated by ViewPort from the bottom left.
        string       path   = "Assets/Resources/tobiidata.csv";
        StreamWriter writer = new StreamWriter(path, true);

        writer.WriteLine(gazePoint.Timestamp + "," + gazePoint.Viewport.x + "," + gazePoint.Viewport.y);
        writer.Close();
        //

        if (gazePoint.IsRecent() &&
            gazePoint.Timestamp > (_lastGazePoint.Timestamp + float.Epsilon))
        {
            if (UseFilter)
            {
                UpdateGazeBubblePosition(gazePoint);
            }
            else
            {
                UpdateGazePointCloud(gazePoint);
            }

            _lastGazePoint = gazePoint;
        }

        UpdateGazePointCloudVisibility();
        UpdateGazeBubbleVisibility();
    }
Exemple #3
0
        // Returns distance between user gaze and given (x,y)
        // Input should be in World Point Coordinates
        public double distanceFromGaze(double x, double y)
        {
            GazePoint gazePoint = TobiiAPI.GetGazePoint();

            if (gazePoint.IsRecent())
            {
                // Convert Tobii Coordinates to Viewport
                Vector3 original = new Vector3(gazePoint.Screen.x, gazePoint.Screen.y, 0);
                Vector3 tobii_world_coordinates    = cam.ScreenToWorldPoint(original);
                Vector3 tobii_viewport_coordinates = cam.WorldToViewportPoint(tobii_world_coordinates);

                // Convert given World Point Coordinates to Viewport
                Vector3 given_coordinates         = new Vector3((float)x, (float)y, 0);
                Vector3 give_viewport_coordinates = cam.WorldToViewportPoint(given_coordinates);

                double x_diff   = give_viewport_coordinates.x - tobii_viewport_coordinates.x;
                double y_diff   = give_viewport_coordinates.y - tobii_viewport_coordinates.y;
                double distance = Math.Sqrt(
                    Math.Pow(x_diff, 2f) +
                    Math.Pow(y_diff, 2f));

                return(distance);
            }
            return(-1);
        }
Exemple #4
0
    void Update()
    {
        if (_pauseTimer > 0)
        {
            _pauseTimer -= Time.deltaTime;
            return;
        }

        GazePoint.SetActive(false);
        _xOutline.enabled = false;
        _yOutline.enabled = false;

        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        if (gazePoint.IsValid)
        {
            Vector2 gazePosition = gazePoint.Screen;
            yCoord.color = xCoord.color = Color.white;
            Vector2 roundedSampleInput = new Vector2(Mathf.RoundToInt(gazePosition.x), Mathf.RoundToInt(gazePosition.y));
            xCoord.text = "x (in px): " + roundedSampleInput.x;
            yCoord.text = "y (in px): " + roundedSampleInput.y;
        }

        if (Input.GetKeyDown(KeyCode.Space) && gazePoint.IsRecent())
        {
            _pauseTimer = 3f;
            GazePoint.transform.localPosition = (gazePoint.Screen - new Vector2(Screen.width, Screen.height) / 2f) / GetComponentInParent <Canvas>().scaleFactor;
            yCoord.color = xCoord.color = new Color(0 / 255f, 190 / 255f, 255 / 255f);
            GazePoint.SetActive(true);
            _xOutline.enabled = true;
            _yOutline.enabled = true;
        }
    }
Exemple #5
0
    static extern bool SetCursorPos(float X, float Y); //added to make eye gaze determine "mouse" position

    void Update()
    {
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        if (NUIManager.Instance.typeOfNUI == 2)
        {
            if (gazePoint.IsRecent() &&
                gazePoint.Timestamp > (_lastGazePoint.Timestamp + float.Epsilon))
            {
                if (UseFilter)
                {
                    UpdateGazeBubblePosition(gazePoint);
                }
                else
                {
                    UpdateGazePointCloud(gazePoint);
                }

                _lastGazePoint = gazePoint;
                Vector2 gazePosition = _lastGazePoint.Screen;
                SetCursorPos(gazePosition.x, gazePosition.y);
            }

            UpdateGazePointCloudVisibility();
            UpdateGazeBubbleVisibility();
        }
    }
Exemple #6
0
    void CheckCursorCollisions()
    {
        if (Input.GetButtonDown("Fire"))
        {
            Ray ray;
            if (isEyeTrackingEnabled && currentGazePoint.IsRecent())
            {
                ray = mainCamera.ScreenPointToRay(new Vector3(currentGazePoint.Screen.x, currentGazePoint.Screen.y, 0.0f));
            }
            else
            {
                ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            }

            RaycastHit targetHit;

            if (Physics.Raycast(ray, out targetHit))
            {
                if (targetHit.transform.tag == "Balloon")
                {
                    targetHit.transform.GetComponent <BalloonController>().triggerExplosion();
                }
            }
        }
    }
Exemple #7
0
 void Update()
 {
     gazePoint = TobiiAPI.GetGazePoint();
     ticks    += Time.deltaTime;
     if (!gazePoint.IsRecent())
     {
         ticksOfScreen += Time.deltaTime;
     }
 }
Exemple #8
0
    protected void Update()
    {
        GazePoint currentGazePoint = TobiiAPI.GetGazePoint();

        if (!currentGazePoint.IsRecent())
        {
            return;
        }

        if (UIElements.Count == 0)
        {
            HasFocus = false;
            return;
        }

        UpdateFocus(currentGazePoint);

        if (!IsEnabled || HasFocus || !FadesOnGaze)
        {
            _currentOpacityInput = Mathf.Clamp01(_currentOpacityInput + Time.unscaledDeltaTime * (1.0f / FadeInTimeSecs));
        }
        else
        {
            _currentOpacityInput = Mathf.Clamp01(_currentOpacityInput - Time.unscaledDeltaTime * (1.0f / FadeOutTimeSecs));
        }

        //Now we need to update the opacity of all of our registered children
        var currentOpacity = OpacityCurve.Evaluate(_currentOpacityInput);

        for (var index = 0; index < UIElements.Count; ++index)
        {
            var element = UIElements[index];
            if (element == null)             //If it has been deleted, we need to remove our reference to allow GC. Unity overloads == to allow us to test like this
            {
                UIElements.RemoveAt(index);
                --index;
            }

            //If we have an override command component, we need to consider it.
            var maxOpacity = 1.0f;
            try
            {
                var opacityOverride = element.GetComponent <CleanUIOpacityOverride>();
                if (opacityOverride != null)
                {
                    maxOpacity = opacityOverride.OpacityOverride;
                }

                SetElementOpacity(element, currentOpacity * maxOpacity);
            }
            catch (Exception e)
            {
                Debug.Log("CleanUI: " + e.Message);
            }
        }
    }
Exemple #9
0
 void moveCursorWithGaze()
 {
     currentGazePoint = TobiiAPI.GetGazePoint();
     if (currentGazePoint.IsRecent())
     {
         Vector3 newPosition = mainCamera.ScreenToWorldPoint(new Vector3(currentGazePoint.Screen.x, currentGazePoint.Screen.y, needle.transform.position.z));
         newPosition = new Vector3(newPosition.x, newPosition.y, needle.transform.position.z);
         needle.transform.position = new Vector3(Mathf.Lerp(needle.transform.position.x, newPosition.x, 10 * Time.deltaTime), Mathf.Lerp(needle.transform.position.y, newPosition.y, 10 * Time.deltaTime), needle.transform.position.z);
     }
 }
Exemple #10
0
    void MoveCrossHair()
    {
        // I instantiate an object that will control eyes tracker
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        // check that eyes tracker is available
        if (gazePoint.IsRecent())
        {
            // reposition the center and coordinates to make the screen move with the eye tracker

            float xMouse = (gazePoint.Screen.x - centroX) * mouseSensitivity * Time.deltaTime;
            float yMouse = (gazePoint.Screen.y - centroY) * mouseSensitivity * Time.deltaTime;

            //transform.position = new Vector3(xMouse,yMouse,0f);
        }
    }
    // Update is called once per frame
    protected void Update()
    {
        gazePoint = TobiiAPI.GetGazePoint();
        if (gazePoint.IsRecent())
        {
            UpdateGazePointerPosition(gazePoint);
            newClickPosition = ProjectToPlaneInWorld(gazePoint);
            newClickPosition = Smoothify(newClickPosition);
            if (clickActive)
            {
                CheckClicker(newClickPosition, clickPosition, gazePoint);
            }

            clickPosition = ProjectToPlaneInWorld(gazePoint);
            clickPosition = Smoothify(clickPosition);
        }
    }
Exemple #12
0
    void MoveCamera()
    {
        // I instantiate an object that will control eyes tracker
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        // check that eyes tracker is available
        if (gazePoint.IsRecent())
        {
            // reposition the center and coordinates to make the screen move with the eye tracker

            float xMouse = (gazePoint.Screen.x - centroX) * mouseSensitivity * Time.deltaTime;
            float yMouse = (gazePoint.Screen.y - centroY) * mouseSensitivity * Time.deltaTime;
            rotationZ -= xMouse;
            rotationZ  = Mathf.Clamp(rotationZ, GradY * -1, GradY);

            transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, -rotationZ, transform.localEulerAngles.z);
        }
    }
Exemple #13
0
        public void UpdateEyes()
        {
            if (fpCamera == null)
            {
                return;
            }
#if hFACE
            GazePoint gazePoint = TobiiAPI.GetGazePoint();
            if (gazePoint.IsRecent())
            {
                gazePointScreen = gazePoint.Viewport;
                Vector3 gazePoint3    = new Vector3(gazePoint.Viewport.x, gazePoint.Viewport.y, 1);
                Vector3 lookDirection = fpCamera.ViewportPointToRay(gazePoint3).direction;
                lookDirection = Quaternion.Inverse(headTarget.transform.rotation) * headTarget.humanoid.transform.rotation * lookDirection;
                Debug.DrawRay(headTarget.transform.position, lookDirection.normalized, Color.magenta);
                headTarget.face.SetGazeDirection(lookDirection, 0.9F);
            }
#endif
        }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            thisBrush = (GameObject)Instantiate(brushPrefab, this.transform.position, Quaternion.identity);

            Ray mRay = Camera.main.ScreenPointToRay(gazePoint.Screen);

            float rayDistance;
            _hasHistoricPoint = false;
            if (objPlane.Raycast(mRay, out rayDistance))
            {
                startPos = mRay.GetPoint(rayDistance);
                //prevPos = mRay.GetPoint (rayDistance);
            }
        }
        else if (Input.GetKey(KeyCode.Space) && gazePoint.IsRecent())
        {
            Ray mRay = Camera.main.ScreenPointToRay(gazePoint.Screen);

            float rayDistance;
            if (objPlane.Raycast(mRay, out rayDistance))
            {
                thisBrush.transform.position = smoothFilter(new Vector2(mRay.GetPoint(rayDistance).x, mRay.GetPoint(rayDistance).y));
            }

            //prevPos = mRay.GetPoint (rayDistance);
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            if (Vector2.Distance(thisBrush.transform.position, startPos) < 0.1)
            {
                Destroy(thisBrush);
                _hasHistoricPoint = false;
            }
        }
    }
Exemple #15
0
    void Update()
    {
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        if (gazePoint.IsRecent() &&
            gazePoint.Timestamp > (_lastGazePoint.Timestamp + float.Epsilon))
        {
            if (UseFilter)
            {
                UpdateGazeBubblePosition(gazePoint);
            }
            else
            {
                UpdateGazePointCloud(gazePoint);
            }

            _lastGazePoint = gazePoint;
        }

        UpdateGazePointCloudVisibility();
        UpdateGazeBubbleVisibility();
    }
Exemple #16
0
    public static Vector3 FindPlayerGaze() // Finds the gazepoint of the player (Consider making a static function)
    {
        Ray ray;

        // Get gazepoint from tobii and create ray
        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        if (gazePoint.IsValid && gazePoint.IsRecent())
        {
            Vector3 gazePosition = new Vector3(gazePoint.Screen.x, gazePoint.Screen.y, 0);
            ray = cam.ScreenPointToRay(gazePosition);
        }
        else  // Use mouse position if gaze position is unavailable
        {
            ray = cam.ScreenPointToRay(Input.mousePosition);
        }

        // Find first intersection from light in direction of mouse in world space
        RaycastHit hit;

        Physics.SphereCast(ray.origin, 0.2f, ray.direction, out hit);
        return(hit.point);
    }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        position = Input.mousePosition;
        if (_manager.Gaze)
        {
            GazePoint gazePoint = TobiiAPI.GetGazePoint();
            if (gazePoint.IsRecent())
            {
                position = gazePoint.Screen;
            }
        }
        position = _mainCam.ScreenToWorldPoint(position);
        Vector2 v2 = new Vector2(position.x, position.y);

        // Show Trail
        Vector2 toScreen = _mainCam.WorldToScreenPoint(position);

        _camPos.text       = toScreen.ToString();
        transform.position = v2;

        // Stock position
        _points.Add(toScreen);
        if (_points.Count > MAXPOINT)
        {
            _points.RemoveAt(0);
        }

        Dictionary <Word, float> find = new Dictionary <Word, float>();

        for (int i = 0; i < _points.Count; ++i)
        {
            Vector2 pos = _points[i];

            /*
             * Dictionary<string, float> findForPoint = gestor.DistWordInPos(pos);
             * foreach (string word in findForPoint.Keys)
             * {
             *  if (!find.ContainsKey(word)) find[word] = 0;
             *  find[word] += findForPoint[word];
             * }
             */
            Word wordInPos = _manager.Gestor.WordInPos(pos);
            if (!find.ContainsKey(wordInPos))
            {
                find[wordInPos] = 0;
            }
            ++find[wordInPos];
        }

        Word  maxWord  = new Word();
        float maxIndex = 0;

        foreach (Word word in find.Keys)
        {
            if (find[word] > maxIndex && find[word] > MAXNEED)
            {
                maxWord  = word;
                maxIndex = find[word];
            }
        }

        _hoverWord.localPosition = Vector3.zero;
        _hoverWord.position      = new Vector3(maxWord.pos.x + maxWord.pos.width / 2, maxWord.pos.y + maxWord.pos.height / 2, 0);
        _hoverWord.sizeDelta     = new Vector2(maxWord.pos.width, maxWord.pos.height);
        _wordFind.text           = maxWord.text + " : " + maxIndex;
    }
Exemple #18
0
    void Update()
    {
        if (_pauseTimer > 0)
        {
            _pauseTimer -= Time.deltaTime;
            return;
        }

        GazePoint.SetActive(false);
        _xOutline.enabled = false;
        _yOutline.enabled = false;

        GazePoint gazePoint = TobiiAPI.GetGazePoint();

        Debug.Log("Go Eyetracking");

        //float angle = SwipeAngle();

        Vector2 MyGazePosition = new Vector2(0.0f, 0.0f);

        //WriteLog("C:\\Users\\mhci430\\Desktop\\GazeSwipeTest\\GazeTest.txt", "Haha");
        if (gazePoint.IsValid)
        {
            Vector2 gazePosition = gazePoint.Screen;
            MyGazePosition = gazePoint.Screen;
            yCoord.color   = xCoord.color = Color.white;
            Vector2 roundedSampleInput = new Vector2(Mathf.RoundToInt(gazePosition.x), Mathf.RoundToInt(gazePosition.y));
            xCoord.text = "x (in px): " + roundedSampleInput.x;
            yCoord.text = "y (in px): " + roundedSampleInput.y;


            GazeImage[0].GetComponent <RectTransform>().position = new Vector3(gazePosition.x, gazePosition.y, 1.0f);

            VisualHint(gazePosition.x, gazePosition.y);



            //Instantiate(MyGaze, (gazePoint.Screen - new Vector2(Screen.width, Screen.height) / 2f) / GetComponentInParent<Canvas>().scaleFactor);
            //MyGaze.transform.localPosition = (gazePoint.Screen - new Vector2(Screen.width, Screen.height) / 2f) / GetComponentInParent<Canvas>().scaleFactor;
            //tempGaze.GetComponent<RectTransform>().position = new Vector2(500f, 500f);
            //Debug.Log("X: " + roundedSampleInput.x + " Y: " + roundedSampleInput.y);
        }
        if (Input.GetKeyDown(KeyCode.Space) && gazePoint.IsRecent())
        {
            _pauseTimer = 3f;
            GazePoint.transform.localPosition = (gazePoint.Screen - new Vector2(Screen.width, Screen.height) / 2f) / GetComponentInParent <Canvas>().scaleFactor;
            yCoord.color = xCoord.color = new Color(0 / 255f, 190 / 255f, 255 / 255f);
            GazePoint.SetActive(true);
            _xOutline.enabled = true;
            _yOutline.enabled = true;
        }
        if (Input.touchCount > 0)  //if there is a touch event
        {
            float minError = Mathf.Infinity;
            float angle    = SwipeAngle();
            if (angle <= 360.0f)
            {
                int[]   test             = new int[25];
                int     testi            = 0;
                float   selectbtnangle   = 100000;
                int     selectedBtnIndex = 10000;
                Texture textureArrow     = TexArrow;
                for (int i = 0; i < loc.Length; i++)
                {
                    float   btnX         = buttons[i].GetComponent <RectTransform>().position.x;
                    float   btnY         = buttons[i].GetComponent <RectTransform>().position.y;
                    Vector2 BtnEyeVector = new Vector2(btnX - MyGazePosition.x, btnY - MyGazePosition.y);
                    bool    mytest       = (float)BtnEyeVector.sqrMagnitude < (float)GazeAreaRadius;
                    Debug.Log("button:" + i + " X:" + btnX + " Y:" + btnY + " GX:" + MyGazePosition.x + " GY:" + MyGazePosition.y + " dis " + BtnEyeVector.sqrMagnitude + " radius: " + GazeAreaRadius + "ans:" + mytest);
                    //Debug.Log("distance" + BtnEyeVector.sqrMagnitude);
                    if (BtnEyeVector.sqrMagnitude < GazeAreaRadius)
                    {
                        test[testi] = i;
                        testi       = testi + 1;
                        float BtnAngle = ComputeTheta(BtnEyeVector.x, BtnEyeVector.y);
                        float error    = Mathf.Pow(BtnAngle - angle, 2.0f);

                        if (error < minError)
                        {
                            selectbtnangle   = BtnAngle;
                            minError         = error;
                            selectedBtnIndex = i;
                        }
                    }
                }
                Debug.Log("Candidate:" + test[0] + "/" + test[1] + "/" + test[2] + "/" + test[3]);

                if (selectedBtnIndex != 10000)
                {
                    selectedbtn = selectedBtnIndex;
                    Debug.Log("We select : " + selectedBtnIndex + " selectbtnangle: " + selectbtnangle + " SwipeAngle: " + angle);
                    buttonClickCallBack(selectedBtnIndex);

                    //Debug.Log("reset");
                    //int a=showTarget(selectedBtnIndex);
                    //buttons[selectedBtnIndex].onClick();
                }
            }
        }
    }