Esempio n. 1
0
    public List <RaycastResult> Raycast2Canvas(GameObject canvas)
    {
        GraphicRaycaster graphic = canvas.GetComponent <GraphicRaycaster>();
        PointerEventData point   = new PointerEventData(null);
        Camera           Camera  = GameObject.Find("Main Camera").GetComponent <Camera> ();

        if (Camera == null)
        {
            throw new System.ArgumentException("Camera not found");
        }

        if (!mouse)
        {
            Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
            // Map gaze indicator
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            point.position = new Vector3((float)gp.X, (float)gp.Y, Camera.nearClipPlane + 1f);
        }
        else
        {
            point.position = Input.mousePosition;
        }


        List <RaycastResult> results = new List <RaycastResult>();

        graphic.Raycast(point, results);

        EventSystem.current.RaycastAll(point, results);

        return(results);
    }
    void Update()
    {
        Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();

        Vector3 planeCoord = Vector3.zero;

        if (null != gazeCoords)
        {
            // Map gaze indicator
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);

            Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f);

            planeCoord = _Camera.ScreenToWorldPoint(screenPoint);
            _GazeIndicator.transform.position = planeCoord;
        }

        if (_ShowGazeIndicator && !_GazeIndicator.activeSelf)
        {
            _GazeIndicator.SetActive(true);
        }
        else if (!_ShowGazeIndicator && _GazeIndicator.activeSelf)
        {
            _GazeIndicator.SetActive(false);
        }
    }
Esempio n. 3
0
    public void OnGazeUpdate(GazeData gazeData)
    {
        if (CooldownTimer > 0f)
        {
            return;
        }

        if ((gazeData.State & (GazeData.STATE_TRACKING_FAIL | GazeData.STATE_TRACKING_LOST)) > 0)
        {
            Blinked = true;
        }

        Point2D point = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeData.SmoothedCoordinates);

        if ((gazeData.State & GazeData.STATE_TRACKING_GAZE) > 0)
        {
            if (Blinked)
            {
                CooldownTimer = BlinkCooldown;
                Blinked       = false;
            }
            else
            {
                gazeX = (float)point.X;
                gazeY = (float)point.Y;
            }
        }
    }
Esempio n. 4
0
    public Vector3 GetPosition()
    {
        Vector3 positionMouse;
        Camera  positionCamera = GameObject.Find("Main Camera").GetComponent <Camera> ();

        if (positionCamera == null)
        {
            throw new System.ArgumentException("Camera not found");
        }

        if (!mouse)
        {
            Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
            // Map gaze indicator
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            positionMouse = new Vector3((float)gp.X, (float)gp.Y, 0);
            positionMouse = Camera.main.ScreenToWorldPoint(positionMouse);
            if (Points.stateGame.saveData)
            {
                Points.stateGame.Save((float)gp.X, (float)gp.Y);
            }
        }

        else
        {
            positionMouse = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionCamera.nearClipPlane + 1f));
        }

        return(positionMouse);
    }
Esempio n. 5
0
    public void Update()
    {
        bool    useMouseAsInput = true;
        Point2D userPos         = gazeUtils.GetLastValidUserPosition();

        if (null != userPos)
        {
            //mapping cam panning to 3:2 aspect ratio
            double tx = (userPos.X * 5) - 2.5f;
            double ty = (userPos.Y * 3) - 1.5f;



            //camera 'look at' origo
            cam.transform.LookAt(Vector3.zero);
        }

        if (!useMouseAsInput)
        {
            Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates();

            if (null != gazeCoords)
            {
                //map gaze indicator
                Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords);

                Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f);

                Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint);
                //gazeIndicator.transform.position = planeCoord;

                //handle collision detection
                checkGazeCollision(screenPoint); // eye tracker
            }
        }

        if (useMouseAsInput)
        {
            Ray     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Vector3 PositionToMoveTo = ray.GetPoint(5);
            checkGazeCollision(PositionToMoveTo); // mouse
            //go.transform.position = PositionToMoveTo;
        }


        //handle keypress
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            Application.LoadLevel(0);
        }
    }
Esempio n. 6
0
    void Update()
    {
        Point2D userPos = gazeUtils.GetLastValidUserPosition();

        if (null != userPos)
        {
            //mapping cam panning to 3:2 aspect ratio
            double tx = (userPos.X * 5) - 2.5f;
            double ty = (userPos.Y * 3) - 1.5f;

            //position camera X-Y plane and adjust distance
            eyesDistance = gazeUtils.GetLastValidUserDistance();
            depthMod     = 2 * eyesDistance;

            Vector3 newPos = new Vector3(
                (float)tx,
                (float)ty,
                (float)(baseDist + depthMod));
            cam.transform.position = newPos;

            //camera 'look at' origo
            cam.transform.LookAt(Vector3.zero);

            //tilt cam according to eye angle
            double angle = gazeUtils.GetLastValidEyesAngle();
            cam.transform.eulerAngles = new Vector3(cam.transform.eulerAngles.x, cam.transform.eulerAngles.y, cam.transform.eulerAngles.z + (float)angle);
        }

        Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates();

        if (null != gazeCoords)
        {
            //map gaze indicator
            Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords);

            Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f);

            Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint);
            gazeIndicator.transform.position = planeCoord;

            //handle collision detection
            checkGazeCollision(screenPoint);
        }

        //handle keypress
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            Application.LoadLevel(0);
        }
    }
Esempio n. 7
0
    public new void Enqueue(GazeData gd)
    {
        GazeData last;

        while (base.Count > 0 && null != (last = base.Peek()) && UnityGazeUtils.GetTimeDeltaNow(last) > TimeLimit)
        {
            base.Dequeue();
        }

        base.Enqueue(gd);
    }
Esempio n. 8
0
 private Vector3 GetGazeScreenPosition(Point2D gp)
 {
     if (null != gp)
     {
         Point2D sp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gp);
         return(new Vector3((float)sp.X, (float)sp.Y, 0f));
     }
     else
     {
         return(Vector3.zero);
     }
 }
Esempio n. 9
0
    public Vector3 GetGazeScreenPosition()
    {
        Point2D gp = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();

        if (null != gp)
        {
            Point2D sp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gp);
            return(new Vector3((float)sp.X, (float)sp.Y, 0f));
        }
        else
        {
            return(Vector3.zero);
        }
    }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        Point2D          gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
        GraphicRaycaster gr         = this.GetComponent <GraphicRaycaster>();
        //Current pointer position
        PointerEventData point = new PointerEventData(null);

        if (!Global.useMouse)
        {
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f);
        }

        else
        {
            point.position = Input.mousePosition;
        }

        //result will contain all of the hit canvas
        List <RaycastResult> results = new List <RaycastResult> ();

        gr.Raycast(point, results);

        if (results.Count > 0)
        {
            if (results [0].gameObject.name == "Back")
            {
                backText.color = Color.green;
                if (delay > waitTimeButtons)
                {
                    SceneManager.LoadScene("MainMenu");
                }
                else
                {
                    delay += Time.deltaTime;
                }
            }
            else
            {
                backText.color = Color.white;
                delay          = 0;
            }
        }
    }
Esempio n. 11
0
        private void PositionWayPoint()
        {
            if (null != _CurrentHit)
            {
                // position based on Gazable target if not too close

                Vector3 targetVec = _CurrentHit.transform.position - transform.position;
                double  distance  = Math.Abs(targetVec.magnitude);

                if (distance > 40)
                {
                    Vector3 newTarget = _CurrentHit.transform.position;

                    // We adjust target vertically to force pitch
                    float yDiff = _CurrentHit.transform.position.y - transform.position.y;
                    newTarget.y += yDiff;

                    _EyeTarget.transform.position = newTarget;
                    SetTarget(_EyeTarget.transform);
                    return;
                }
            }

            //position based on gaze

            if (m_TakenOff)
            {
                Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();

                Vector3 planeCoord = Vector3.zero;
                if (null != gazeCoords)
                {
                    // Map gaze to Unity space
                    Point2D gp          = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
                    Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, WAYPOINT_DISTANCE);

                    planeCoord = _Camera.ScreenToWorldPoint(screenPoint);

                    _EyeTarget.transform.position = planeCoord;
                    SetTarget(_EyeTarget.transform);
                }
            }
        }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        /* @TheEyeTribe Check for collision and position waypoint */
        Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
        Vector3 mouse;

        playerPos = transform.position;
        float radio = GetComponent <Renderer> ().bounds.extents.x;

        if (!Global.useMouse)
        {
            // Map gaze indicator
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            mouse = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.z);
            mouse = Camera.main.ScreenToWorldPoint(mouse);
            if (Global.saveData == true)
            {
                SaveMedicalData.instance.Save((float)gp.X, (float)gp.Y);
            }
        }
        else
        {
            mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }

        if (mouse.x - playerPos.x < -radio / 100)         //Raton a la izquierda
        {
            transform.Translate(-1 * speed);
        }
        else if (mouse.x - playerPos.x > radio / 3)
        {
            transform.Translate(speed);
        }

        if (transform.position.x > WallPosition.rightWallX)
        {
            transform.position = new Vector3(WallPosition.rightWallX, transform.position.y, transform.position.z);;
        }
        if (transform.position.x < WallPosition.leftWallX)
        {
            transform.position = new Vector3(WallPosition.leftWallX, transform.position.y, transform.position.z);
        }
    }
Esempio n. 13
0
    public void UpdateGazeCamera()
    {
        Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates();

        if (null != gazeCoords)
        {
            //map gaze indicator
            Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords);

            screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f);

            if (useGazeTracker)
            {
                Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint);
                gazeIndicator.transform.position = planeCoord;
            }

            //handle collision detection, just as an example
            //checkGazeCollision(screenPoint);
        }
    }
Esempio n. 14
0
        private void Update()
        {
            /* @TheEyeTribe Check for collision and position waypoint */
            Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();

            if (null != gazeCoords)
            {
                // Map gaze indicator
                Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);

                Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f);

                // Handle collision detection
                Vector3 hitPoint;
                if (checkGazeCollision(screenPoint, out hitPoint))
                {
                    //do nothing
                }
            }
            else
            {
                // Use mouse position for hover effect as default
                Vector3 hitPoint;
                if (checkGazeCollision(Input.mousePosition, out hitPoint))
                {
                    //do nothing
                }
            }

            /* @TheEyeTribe Handling callback queue on main thread */
            lock (_CallbackQueue)
            {
                //we handle queued callback in the update loop
                while (_CallbackQueue.Count > 0)
                {
                    _CallbackQueue.Dequeue()();
                }
            }
        }
Esempio n. 15
0
    void Update()
    {
        if (!GazeManager.Instance.IsCalibrating)
        {
            //Set eyes size based on distance
            _EyesDistance = GazeDataValidator.Instance.GetLastValidUserPosition().Z;
            _DepthMod     = (1 - _EyesDistance) * .25f;
            Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z);

            Eye left  = GazeDataValidator.Instance.GetLastValidLeftEye();
            Eye right = GazeDataValidator.Instance.GetLastValidRightEye();

            double angle = -GazeDataValidator.Instance.GetLastValidEyesAngle();

            if (null != left)
            {
                if (!_LeftEye.GetComponent <Renderer>().enabled)
                {
                    _LeftEye.GetComponent <Renderer>().enabled = true;
                }

                //position GO based on screen coordinates
                Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates);
                PositionGOFromScreenCoords(_LeftEye, gp);
                _LeftEye.transform.localScale  = scaleVec;
                _LeftEye.transform.eulerAngles = new Vector3(_LeftEye.transform.eulerAngles.x, _LeftEye.transform.eulerAngles.y, (float)angle);
            }
            else
            {
                if (_LeftEye.GetComponent <Renderer>().enabled)
                {
                    _LeftEye.GetComponent <Renderer>().enabled = false;
                }
            }

            if (null != right)
            {
                if (!_RightEye.GetComponent <Renderer>().enabled)
                {
                    _RightEye.GetComponent <Renderer>().enabled = true;
                }

                //position GO based on screen coordinates
                Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates);
                PositionGOFromScreenCoords(_RightEye, gp);
                _RightEye.transform.localScale  = scaleVec;
                _RightEye.transform.eulerAngles = new Vector3(_RightEye.transform.eulerAngles.x, _RightEye.transform.eulerAngles.y, (float)angle);
            }
            else
            {
                if (_RightEye.GetComponent <Renderer>().enabled)
                {
                    _RightEye.GetComponent <Renderer>().enabled = false;
                }
            }
        }
        else
        {
            _LeftEye.GetComponent <Renderer>().enabled  = false;
            _RightEye.GetComponent <Renderer>().enabled = false;
        }

        if (GazeManager.Instance.IsCalibrated)
        {
            if (!_GazeIndicator.GetComponent <Renderer>().enabled)
            {
                _GazeIndicator.GetComponent <Renderer>().enabled = true;
            }

            Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
            if (null != gazeCoords)
            {
                // Map gaze indicator
                Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);

                Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f);

                Vector3 planeCoord = _Camera.ScreenToWorldPoint(screenPoint);
                _GazeIndicator.transform.position = planeCoord;
            }
        }
        else
        {
            if (_GazeIndicator.GetComponent <Renderer>().enabled)
            {
                _GazeIndicator.GetComponent <Renderer>().enabled = false;
            }
        }


        lock (_CallbackQueue)
        {
            //we handle queued callback in the update loop
            while (_CallbackQueue.Count > 0)
            {
                _CallbackQueue.Dequeue()();
            }
        }

        //handle keypress
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
    // Update is called once per frame
    void Update()
    {
        Point2D          gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
        GraphicRaycaster gr         = this.GetComponent <GraphicRaycaster>();
        //Current pointer position
        PointerEventData point = new PointerEventData(null);

        if (!Global.useMouse)
        {
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f);
        }

        else
        {
            point.position = Input.mousePosition;
        }
        //result will contain all of the hit canvas
        List <RaycastResult> results = new List <RaycastResult> ();

        gr.Raycast(point, results);


        if (results.Count > 0)
        {
            for (int i = 0; i < results.Count; i++)
            {
                if (results [i].gameObject.name == "menu")
                {
                    text.color = Color.blue;
                    if (delay > waitTime)
                    {
                        try{
                            if (KeyboardManager.keyboardManager.getText() != "")
                            {
                                SavePoints.pointsInstance.Save(new PlayerPoints(KeyboardManager.keyboardManager.getText(), Global.points));
                                KeyboardManager.keyboardManager.setText("");
                                SceneManager.LoadScene("MainMenu");
                            }
                        } catch (System.Exception e) {
                            SceneManager.LoadScene("MainMenu");
                        }
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
                else
                {
                    text.color = Color.white;
                }
                if (results [i].gameObject.name == "keyboard")
                {
                    if (delay > waitTime)
                    {
                        SceneManager.LoadScene("Keyboard");
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
            }
        }
    }
Esempio n. 17
0
    public virtual void Update(GazeData frame)
    {
        _GazeFrameCache.Enqueue(frame);

        // update valid gazedata based on store
        Eye      right = null, left = null;
        Point2D  gazeCoords       = null;
        Point2D  gazeCoordsSmooth = null;
        Point2D  userPos          = null;
        double   userDist         = 0d;
        Point2D  eyeDistVecHalf   = null;
        GazeData gd;

        lock (_GazeFrameCache)
        {
            for (int i = _GazeFrameCache.Count; --i >= 0;)
            {
                gd = _GazeFrameCache.ElementAt(i);

                // if no tracking problems, then cache eye data
                if ((gd.State & NO_TRACKING_MASK) == 0)
                {
                    if (null == userPos &&
                        !gd.LeftEye.PupilCenterCoordinates.Equals(Point2D.zero) &&
                        !gd.RightEye.PupilCenterCoordinates.Equals(Point2D.zero))
                    {
                        userPos        = (gd.LeftEye.PupilCenterCoordinates + gd.RightEye.PupilCenterCoordinates) / 2;
                        eyeDistVecHalf = (gd.RightEye.PupilCenterCoordinates - gd.LeftEye.PupilCenterCoordinates) / 2;
                        userDist       = UnityGazeUtils.getDistancePoint2D(gd.LeftEye.PupilCenterCoordinates, gd.RightEye.PupilCenterCoordinates);

                        left  = gd.LeftEye;
                        right = gd.RightEye;
                    }
                    else if (null == userPos && left == null && !gd.LeftEye.PupilCenterCoordinates.Equals(Point2D.zero))
                    {
                        left = gd.LeftEye;
                    }
                    else if (null == userPos && right == null && !gd.RightEye.PupilCenterCoordinates.Equals(Point2D.zero))
                    {
                        right = gd.RightEye;
                    }

                    // if gaze coordinates available, cache both raw and smoothed
                    if (/*(gd.State & GazeData.STATE_TRACKING_GAZE) != 0 && */ null == gazeCoords && !gd.RawCoordinates.Equals(Point2D.zero))
                    {
                        gazeCoords       = gd.RawCoordinates;
                        gazeCoordsSmooth = gd.SmoothedCoordinates;
                    }
                }

                // break loop if valid values found
                if (null != userPos && null != gazeCoords)
                {
                    break;
                }
            }

            if (null != gazeCoords)
            {
                _LastValidRawGazeCoords      = gazeCoords;
                _LastValidSmoothedGazeCoords = gazeCoordsSmooth;
            }

            if (null != eyeDistVecHalf)
            {
                _LastValidEyesDistHalfVec = eyeDistVecHalf;
            }

            //Update user position values if needed data is valid
            if (null != userPos)
            {
                _LastValidLeftEye  = left;
                _LastValidRightEye = right;

                //update 'depth' measure
                if (userDist < _MinimumEyesDistance)
                {
                    _MinimumEyesDistance = userDist;
                }

                if (userDist > _MaximumEyesDistance)
                {
                    _MaximumEyesDistance = userDist;
                }

                //_LastValidEyeDistance = _LastValidEyeDistance / (_MaximumEyesDistance - _MinimumEyesDistance);
                _LastValidEyeDistance = 1 - (userDist / _MaximumEyesDistance);

                //update user position
                _LastValidUserPosition = new Point3D(userPos.X, userPos.Y, _LastValidEyeDistance);

                //map to normalized 3D space
                _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;

                //update angle
                _LastValidEyeAngle = ((180 / Math.PI * Math.Atan2(_LastValidRightEye.PupilCenterCoordinates.Y - _LastValidLeftEye.PupilCenterCoordinates.Y,
                                                                  _LastValidRightEye.PupilCenterCoordinates.X - _LastValidLeftEye.PupilCenterCoordinates.X)));
            }
            else if (null != left)
            {
                _LastValidLeftEye  = left;
                _LastValidRightEye = null;
                Point2D newPos = _LastValidLeftEye.PupilCenterCoordinates + _LastValidEyesDistHalfVec;
                _LastValidUserPosition = new Point3D(newPos.X, newPos.Y, _LastValidEyeDistance);

                //map to normalized 3D space
                _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;
            }
            else if (null != right)
            {
                _LastValidRightEye = right;
                _LastValidLeftEye  = null;
                Point2D newPos = _LastValidRightEye.PupilCenterCoordinates - _LastValidEyesDistHalfVec;
                _LastValidUserPosition = new Point3D(newPos.X, newPos.Y, _LastValidEyeDistance);

                //map to normalized 3D space
                _LastValidUserPosition.X = (_LastValidUserPosition.X * 2) - 1;
                _LastValidUserPosition.Y = (_LastValidUserPosition.Y * 2) - 1;
            }
            else
            {
                _LastValidRightEye = null;
                _LastValidLeftEye  = null;
            }
        }
    }
Esempio n. 18
0
        void Update()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (!VRMode.IsRunningInVRMode && !_IsOff)
            {
                if (!GazeManager.Instance.IsCalibrating)
                {
                    // If running in 'remote' mode and not calibrating, we position eyes
                    // and set size based on distance

                    _EyesDistance = GazeFrameCache.Instance.GetLastUserPosition().Z;

                    _DepthMod = (1 - _EyesDistance) * .25f;
                    Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z);

                    Eye left  = GazeFrameCache.Instance.GetLastLeftEye();
                    Eye right = GazeFrameCache.Instance.GetLastRightEye();

                    double angle = GazeFrameCache.Instance.GetLastEyesAngle();

                    if (null != left)
                    {
                        if (!left.Equals(_LastLeftEye))
                        {
                            _LastLeftEye = left;

                            if (!_LeftEye.IsRendererEnabled())
                            {
                                _LeftEye.SetRendererEnabled(true);
                            }

                            //position GO based on screen coordinates
                            Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates);
                            _LeftEye.SetWorldPositionFromGaze(_Camera, gp, _LeftEye.transform.localPosition.z);
                            _LeftEye.transform.localScale       = scaleVec * _EyeScaleInitSize;
                            _LeftEye.transform.localEulerAngles = new Vector3(_LeftEye.transform.localEulerAngles.x, _LeftEye.transform.localEulerAngles.y, (float)-angle);
                        }
                    }
                    else
                    {
                        if (_LeftEye.IsRendererEnabled())
                        {
                            _LeftEye.SetRendererEnabled(false);
                        }
                    }

                    if (null != right)
                    {
                        if (!right.Equals(_LastRightEye))
                        {
                            _LastRightEye = right;

                            if (!_RightEye.IsRendererEnabled())
                            {
                                _RightEye.SetRendererEnabled(true);
                            }

                            //position GO based on screen coordinates
                            Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates);
                            _RightEye.SetWorldPositionFromGaze(_Camera, gp, _RightEye.transform.localPosition.z);
                            _RightEye.transform.localScale       = scaleVec * _EyeScaleInitSize;
                            _RightEye.transform.localEulerAngles = new Vector3(_RightEye.transform.localEulerAngles.x, _RightEye.transform.localEulerAngles.y, (float)-angle);
                        }
                    }
                    else
                    {
                        if (_RightEye.IsRendererEnabled())
                        {
                            _RightEye.SetRendererEnabled(false);
                        }
                    }
                }
            }
            else
            {
                if (_LeftEye.IsRendererEnabled())
                {
                    _LeftEye.SetRendererEnabled(false);
                }
                if (_RightEye.IsRendererEnabled())
                {
                    _RightEye.SetRendererEnabled(false);
                }
            }
        }
Esempio n. 19
0
    // Update is called once per frame
    void Update()
    {
        Point2D          gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates();
        GraphicRaycaster gr         = this.GetComponent <GraphicRaycaster>();
        //Current pointer position
        PointerEventData point = new PointerEventData(null);

        if (!Global.useMouse)
        {
            Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords);
            point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f);
        }

        else
        {
            point.position = Input.mousePosition;
        }

        //result will contain all of the hit canvas
        List <RaycastResult> results = new List <RaycastResult> ();

        gr.Raycast(point, results);

        if (results.Count > 0)
        {
            for (int i = 0; i < results.Count; i++)
            {
                if (results [i].gameObject.name == "Save")
                {
                    results [i].gameObject.GetComponent <Image> ().color    = Color.green;
                    objectObserved.gameObject.GetComponent <Image> ().color = Color.green;
                    if (delay > waitTime)
                    {
                        SceneManager.LoadScene("FinishGame");
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
                else
                {
                    GameObject.Find("Save").gameObject.GetComponent <Image> ().color = bColor;
                }

                if (results [i].gameObject.name == "Delete")
                {
                    results [i].gameObject.GetComponent <Image> ().color = Color.green;
                    if (delay > waitTime)
                    {
                        try {
                            text          = text.Substring(0, text.Length - 1);
                            nameText.text = text;

                            delay = 0;
                        } catch (System.Exception e) {
                            text  = "";
                            delay = 0;
                        }
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
                else
                {
                    GameObject.Find("Delete").gameObject.GetComponent <Image> ().color = bColor;
                }

                if (results [i].gameObject.name == "Space")
                {
                    results [i].gameObject.GetComponent <Image> ().color = Color.green;
                    if (delay > waitTime)
                    {
                        text  = text + " ";
                        delay = 0;
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
                else
                {
                    GameObject.Find("Space").gameObject.GetComponent <Image> ().color = bColor;
                }

                if (results [i].gameObject.name == "letter")
                {
                    objectObserved = results [i].gameObject;
                    objectObserved.gameObject.GetComponent <Image> ().color = Color.green;
                    if (delay > waitTime)
                    {
                        text         += results [i].gameObject.GetComponentInChildren <Text> ().text;
                        nameText.text = text;
                        delay         = 0;
                    }
                    else
                    {
                        delay += Time.deltaTime;
                    }
                }
                else
                {
                    if (objectObserved != null && results [i].gameObject != objectObserved)
                    {
                        objectObserved.GetComponent <Image> ().color = bColor;
                    }
                }
            }
        }
    }
Esempio n. 20
0
    void Update()
    {
        if (!GazeManager.Instance.IsCalibrating)
        {
            Point2D userPos = gazeUtils.GetLastValidUserPosition();

            if (null != userPos)
            {
                //Make eyes visible
                if (!leftEye.renderer.enabled)
                {
                    leftEye.renderer.enabled = true;
                }
                if (!rightEye.renderer.enabled)
                {
                    rightEye.renderer.enabled = true;
                }

                //Set eyes size based on distance
                eyesDistance = gazeUtils.GetLastValidUserDistance();
                depthMod     = eyesDistance * .5f;
                Vector3 scaleVec = new Vector3((float)(depthMod), (float)(depthMod), (float)eyeBaseScale.z);

                Eye left  = gazeUtils.GetLastValidLeftEye();
                Eye right = gazeUtils.GetLastValidRightEye();

                double angle = gazeUtils.GetLastValidEyesAngle();

                if (null != left)
                {
                    //position GO based on screen coordinates
                    Point2D gp = UnityGazeUtils.getRelativeToScreenSpace(left.PupilCenterCoordinates);
                    PositionGOFromScreenCoords(leftEye, gp);
                    leftEye.transform.localScale  = scaleVec;
                    leftEye.transform.eulerAngles = new Vector3(leftEye.transform.eulerAngles.x, leftEye.transform.eulerAngles.y, (float)angle);
                }

                if (null != right)
                {
                    //position GO based on screen coordinates
                    Point2D gp = UnityGazeUtils.getRelativeToScreenSpace(right.PupilCenterCoordinates);
                    PositionGOFromScreenCoords(rightEye, gp);
                    rightEye.transform.localScale  = scaleVec;
                    rightEye.transform.eulerAngles = new Vector3(rightEye.transform.eulerAngles.x, rightEye.transform.eulerAngles.y, (float)angle);
                }
            }
        }
        else
        {
            //Make eyes invisible eyes
            if (leftEye.renderer.enabled)
            {
                leftEye.renderer.enabled = false;
            }
            if (rightEye.renderer.enabled)
            {
                rightEye.renderer.enabled = false;
            }
        }

        lock (_callbackQueue)
        {
            //we handle queued callback in the update loop
            while (_callbackQueue.Count > 0)
            {
                _callbackQueue.Dequeue()();
            }
        }

        //handle keypress
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
Esempio n. 21
0
        void Update()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (!VRMode.IsRunningInVRMode && !_IsOff)
            {
                if (!GazeManager.Instance.IsCalibrating)
                {
                    // If running in 'remote' mode and not calibrating, we position eyes
                    // and set size based on distance

                    _EyesDistance = GazeFrameCache.Instance.GetLastUserPosition().Z;

                    _DepthMod = (1 - _EyesDistance) * .25f;
                    Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z);

                    Eye left  = GazeFrameCache.Instance.GetLastLeftEye();
                    Eye right = GazeFrameCache.Instance.GetLastRightEye();

                    double angle = GazeFrameCache.Instance.GetLastEyesAngle();

                    if (null != left)
                    {
                        if (!left.Equals(_LastLeftEye))
                        {
                            _LastLeftEye = left;

                            if (!_LeftEye.IsRendererEnabled())
                            {
                                _LeftEye.SetRendererEnabled(true);
                            }

                            //position GO based on screen coordinates
                            Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates);

                            ////////////////
                            // normalize coordinates to top right corner
                            //float xMin = 0, xMax = Screen.width, yMin = 0, yMax = Screen.height;
                            float xMin = 0, xMax = xScreen, yMin = 0, yMax = yScreen;
                            float xOffset = xMax * (1 - _ResizeMultiplier), yOffset = yMax * (1 - _ResizeMultiplier);
                            gp.X = (((gp.X - xMin) / (xMax - xMin)) * _ResizeMultiplier * xMax + xOffset);
                            gp.Y = (((gp.Y - yMin) / (yMax - yMin)) * _ResizeMultiplier * yMax + yOffset) - yMax * (1 - _ResizeMultiplier);
                            ////////////////

                            _LeftEye.SetWorldPositionFromGaze(_Camera, gp, _LeftEye.transform.localPosition.z);
                            _LeftEye.transform.localScale       = scaleVec * _EyeScaleInitSize;
                            _LeftEye.transform.localEulerAngles = new Vector3(_LeftEye.transform.localEulerAngles.x, _LeftEye.transform.localEulerAngles.y, (float)-angle);
                        }
                    }
                    else
                    {
                        if (_LeftEye.IsRendererEnabled())
                        {
                            _LeftEye.SetRendererEnabled(false);
                        }
                    }

                    if (null != right)
                    {
                        if (!right.Equals(_LastRightEye))
                        {
                            _LastRightEye = right;

                            if (!_RightEye.IsRendererEnabled())
                            {
                                _RightEye.SetRendererEnabled(true);
                            }

                            //position GO based on screen coordinates
                            Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates);

                            ////////////////
                            // normalize coordinates to top right corner
                            //float xMin = 0, xMax = Screen.width, yMin = 0, yMax = Screen.height;
                            float xMin = 0, xMax = xScreen, yMin = 0, yMax = yScreen;
                            float xOffset = xMax * (1 - _ResizeMultiplier), yOffset = yMax * (1 - _ResizeMultiplier);
                            gp.X = (((gp.X - xMin) / (xMax - xMin)) * _ResizeMultiplier * xMax + xOffset);
                            gp.Y = (((gp.Y - yMin) / (yMax - yMin)) * _ResizeMultiplier * yMax + yOffset) - yMax * (1 - _ResizeMultiplier);
                            ////////////////

                            _RightEye.SetWorldPositionFromGaze(_Camera, gp, _RightEye.transform.localPosition.z);
                            _RightEye.transform.localScale       = scaleVec * _EyeScaleInitSize;
                            _RightEye.transform.localEulerAngles = new Vector3(_RightEye.transform.localEulerAngles.x, _RightEye.transform.localEulerAngles.y, (float)-angle);
                        }
                    }
                    else
                    {
                        if (_RightEye.IsRendererEnabled())
                        {
                            _RightEye.SetRendererEnabled(false);
                        }
                    }
                }
            }
            else
            {
                if (_LeftEye.IsRendererEnabled())
                {
                    _LeftEye.SetRendererEnabled(false);
                }
                if (_RightEye.IsRendererEnabled())
                {
                    _RightEye.SetRendererEnabled(false);
                }
            }
        }