Beispiel #1
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);
        }
    }
Beispiel #2
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);
        }
    }
Beispiel #3
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();
        }
    }