Esempio n. 1
0
    public bool BothEyesTracking()
    {
        var data = VarjoPlugin.GetGaze();

        return(data.leftStatus != VarjoPlugin.GazeEyeStatus.EYE_INVALID &&
               data.rightStatus != VarjoPlugin.GazeEyeStatus.EYE_INVALID);
    }
Esempio n. 2
0
        void Update()
        {
            // Returns current state of the gaze
            data = VarjoPlugin.GetGaze();

            // Check if gaze data is valid and calibrated
            if (data.status != VarjoPlugin.GazeStatus.INVALID)
            {
                switch (eye)
                {
                case Eye.both:
                    // Gaze data forward and position comes as 3 doubles: x,y,z. You need to construct a vector from them to a desired format.
                    gazeRayForward = new Vector3((float)data.gaze.forward[0], (float)data.gaze.forward[1], (float)data.gaze.forward[2]);
                    gazePosition   = new Vector3((float)data.gaze.position[0], (float)data.gaze.position[1], (float)data.gaze.position[2]);
                    break;

                case Eye.left:
                    gazeRayForward = new Vector3((float)data.left.forward[0], (float)data.left.forward[1], (float)data.left.forward[2]);
                    gazePosition   = new Vector3((float)data.left.position[0], (float)data.left.position[1], (float)data.left.position[2]);
                    break;

                case Eye.right:
                    gazeRayForward = new Vector3((float)data.right.forward[0], (float)data.right.forward[1], (float)data.right.forward[2]);
                    gazePosition   = new Vector3((float)data.right.position[0], (float)data.right.position[1], (float)data.right.position[2]);
                    break;
                }

                // Fetch head pose
                transform.position = VarjoManager.Instance.HeadTransform.position;
                transform.rotation = VarjoManager.Instance.HeadTransform.rotation;

                // Transform gaze direction and origin from HMD space to world space
                gazeRayDirection = transform.TransformVector(gazeRayForward);
                gazeRayOrigin    = transform.TransformPoint(gazePosition);

                // Raycast into world
                if (Physics.SphereCast(gazeRayOrigin, gazeRayRadius, gazeRayDirection, out gazeRayHit))
                {
                    // Use layers or tags preferably to identify looked objects in your application.
                    // This is done here via GetComponent for clarity's sake as example.
                    VarjoGazeTarget target = gazeRayHit.collider.gameObject.GetComponent <VarjoGazeTarget>();
                    if (target != null)
                    {
                        target.OnHit();
                    }

                    if (drawDebug)
                    {
                        Debug.DrawLine(gazeRayOrigin, gazeRayOrigin + gazeRayDirection * 10.0f, Color.green);
                    }
                }
                else
                {
                    if (drawDebug)
                    {
                        Debug.DrawLine(gazeRayOrigin, gazeRayOrigin + gazeRayDirection * 10.0f, Color.white);
                    }
                }
            }
        }
Esempio n. 3
0
    // gets and sets the data for the current frame (gaze, hmd pose, offset)
    void GetCurrentData()
    {
        // === gaze ===
        // validity
        leftInvalid  = VarjoPlugin.GetGaze().leftStatus == VarjoPlugin.GazeEyeStatus.EYE_INVALID;
        rightInvalid = VarjoPlugin.GetGaze().leftStatus == VarjoPlugin.GazeEyeStatus.EYE_INVALID;
        // origin & direction
        gazeOriginLeft     = transform.TransformPoint(Utils.Double3ToVector3(VarjoPlugin.GetGaze().left.position));
        gazeDirectionLeft  = transform.TransformVector(Utils.Double3ToVector3(VarjoPlugin.GetGaze().left.forward));
        gazeOriginRight    = transform.TransformPoint(Utils.Double3ToVector3(VarjoPlugin.GetGaze().left.position));
        gazeDirectionRight = transform.TransformVector(Utils.Double3ToVector3(VarjoPlugin.GetGaze().left.forward));
        // default
        gazeDirectionStraight = transform.TransformPoint(maskSettings.gazeDirectionStraight);

        // === hmd pose ===
        VarjoPlugin.Matrix matrix;
        VarjoManager.Instance.GetPose(VarjoPlugin.PoseType.CENTER, out matrix);
        if (Utils.Double3ToVector3(matrix.value) != Vector3.zero) // this is so we don't get annoying console logs when we are in editor mode...
        {
            transform.rotation = VarjoManager.Instance.GetHMDOrientation(VarjoPlugin.PoseType.CENTER);
            transform.position = VarjoManager.Instance.GetHMDPosition(VarjoPlugin.PoseType.CENTER);
        }

        // === offset ===
        offsetFocusLeft    = new Vector2(maskSettings.offsetFocusLeftX, maskSettings.offsetFocusLeftY);
        offsetFocusRight   = new Vector2(-(1 - maskSettings.offsetFocusLeftX), -(1 - maskSettings.offsetFocusLeftY));
        offsetContextLeft  = new Vector2(maskSettings.offsetContextLeftX, maskSettings.offsetContextLeftY);
        offsetContextRight = new Vector2(maskSettings.offsetContextLeftX, maskSettings.offsetContextLeftY);
    }
Esempio n. 4
0
 void Update()
 {
     if (Input.GetKeyDown(trackingResetKey))
     {
         VarjoPlugin.ResetPose(resetPosition, resetRotation);
     }
 }
Esempio n. 5
0
 void RequestGazeCalDelayed()
 {
     VarjoPlugin.GazeData data = VarjoPlugin.GetGaze();
     if (data.status != VarjoPlugin.GazeStatus.VALID)
     {
         GetComponent <VarjoExample.VarjoGazeCalibrationRequest>().RequestGazeCalibration();
     }
 }
Esempio n. 6
0
 private void Start()
 {
     if (!mouseGaze && !VarjoPlugin.InitGaze())
     {
         Debug.LogWarning("Failed to initialize gaze, enabling mouse gaze");
         mouseGaze = true;
     }
 }
Esempio n. 7
0
 private void Start()
 {
     // InitGaze must be called before using or calibrating gaze tracking.
     if (!VarjoPlugin.InitGaze())
     {
         Debug.LogError("Failed to initialize gaze");
         gameObject.SetActive(false);
     }
 }
Esempio n. 8
0
 private void Start()
 {
     // InitGaze must be called before using or calibrating gaze tracking.
     if (!VarjoPlugin.InitGaze())
     {
         Debug.LogError("Failed to initialize gaze");
         gameObject.SetActive(false);
     }
     gazeCircleOriginalScale = gazeCircle.gameObject.transform.localScale;
 }
Esempio n. 9
0
 void Update()
 {
     if (!calibrated)
     {
         VarjoPlugin.GazeData data = VarjoPlugin.GetGaze();
         if (data.status == VarjoPlugin.GazeStatus.VALID)
         {
             calibrated = true;
             endcription.Perform();
             mooseAnimation.enabled = true;
         }
     }
 }
Esempio n. 10
0
        void Update()
        {
            if (VarjoManager.Instance.IsLayerVisible())
            {
                if (Input.GetKeyDown(key))
                {
                    VarjoPlugin.RequestGazeCalibration();
                }
            }

            if (VarjoManager.Instance.GetButtonDown() && useApplicationButton)
            {
                VarjoPlugin.RequestGazeCalibration();
            }
        }
Esempio n. 11
0
        void Update()
        {
            // Do not run update if the application is not visible
            if (!VarjoManager.Instance.IsLayerVisible() || VarjoManager.Instance.IsInStandBy())
            {
                return;
            }

            if (Input.GetKeyDown(toggleLoggingKey))
            {
                if (!logging)
                {
                    StartLogging();
                }
                else
                {
                    StopLogging();
                }
                return;
            }

            if (logging)
            {
                if (oneGazeDataPerFrame)
                {
                    // Get and log latest gaze data
                    LogGazeData(VarjoPlugin.GetGaze());
                }
                else
                {
                    // Get and log all gaze data since last update
                    dataSinceLastUpdate = VarjoPlugin.GetGazeList();
                    foreach (var data in dataSinceLastUpdate)
                    {
                        LogGazeData(data);
                    }
                }
            }
            else if (startAutomatically)
            {
                if (VarjoPlugin.GetGaze().status == VarjoPlugin.GazeStatus.VALID)
                {
                    StartLogging();
                }
            }
        }
Esempio n. 12
0
    private void Update()
    {
        var data = VarjoPlugin.GetGaze();

        if (!mouseGaze && data.status == VarjoPlugin.GazeStatus.INVALID)
        {
            gazeHitTarget = null;
            return;
        }


        var headTransform = VarjoManager.Instance.HeadTransform;
        Ray gazeRay;

        if (!mouseGaze)
        {
            var gazeLocalPos = new Vector3((float)data.gaze.position[0], (float)data.gaze.position[1], (float)data.gaze.position[2]);
            var gazeLocalDir = new Vector3((float)data.gaze.forward[0], (float)data.gaze.forward[1], (float)data.gaze.forward[2]);
            gazeRay = new Ray(
                headTransform.TransformPoint(gazeLocalPos),
                headTransform.TransformVector(gazeLocalDir)
                );
        }
        else
        {
            gazeRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        }

        Color      debugColor;
        RaycastHit gazeRayHit;

        if (Physics.Raycast(gazeRay, out gazeRayHit))
        {
            gazeHitTarget = gazeRayHit.collider;
            debugColor    = Color.green;
        }
        else
        {
            gazeHitTarget = null;
            debugColor    = Color.red;
        }
        Debug.DrawLine(gazeRay.origin, gazeRay.origin + 10.0f * gazeRay.direction, debugColor);
    }
Esempio n. 13
0
 void Update()
 {
     if (logging)
     {
         // Get and log all gaze data since last update
         dataSinceLastUpdate = VarjoPlugin.GetGazeList();
         foreach (var data in dataSinceLastUpdate)
         {
             LogGazeData(data);
         }
     }
     else if (startAutomatically)
     {
         if (VarjoPlugin.GetGaze().status == VarjoPlugin.GazeStatus.VALID)
         {
             StartLogging();
         }
     }
 }
        void RequestGazeCalibration()
        {
            if (!useCalibrationParameters)
            {
                VarjoPlugin.RequestGazeCalibration();
            }
            else
            {
                parameters = new VarjoPlugin.GazeCalibrationParameters[2];

                parameters[0]       = new VarjoPlugin.GazeCalibrationParameters();
                parameters[0].key   = "GazeCalibrationType";
                parameters[0].value = calibrationType == CalibrationType.LEGACY ? "Legacy" : "Fast";

                parameters[1]       = new VarjoPlugin.GazeCalibrationParameters();
                parameters[1].key   = "OutputFilterType";
                parameters[1].value = outputFilterType == OutputFilterType.STANDARD ? "Standard" : "None";

                VarjoPlugin.RequestGazeCalibrationWithParameters(parameters);
            }
        }
Esempio n. 15
0
        private void GazeRay()
        {
            // Returns current state of the gaze
            data = VarjoPlugin.GetGaze();

            // Check if gaze data is valid and calibrated
            if (data.status != VarjoPlugin.GazeStatus.INVALID)
            {
                switch (eye)
                {
                case Eye.both:
                    // Gaze data forward and position comes as 3 doubles: x,y,z. You need to construct a vector from them to a desired format.
                    gazeRayForward = new Vector3((float)data.gaze.forward[0], (float)data.gaze.forward[1], (float)data.gaze.forward[2]);
                    gazePosition   = new Vector3((float)data.gaze.position[0], (float)data.gaze.position[1], (float)data.gaze.position[2]);
                    break;

                case Eye.left:
                    gazeRayForward = new Vector3((float)data.left.forward[0], (float)data.left.forward[1], (float)data.left.forward[2]);
                    gazePosition   = new Vector3((float)data.left.position[0], (float)data.left.position[1], (float)data.left.position[2]);
                    break;

                case Eye.right:
                    gazeRayForward = new Vector3((float)data.right.forward[0], (float)data.right.forward[1], (float)data.right.forward[2]);
                    gazePosition   = new Vector3((float)data.right.position[0], (float)data.right.position[1], (float)data.right.position[2]);
                    break;
                }

                // Fetch head pose
                transform.position = VarjoManager.Instance.HeadTransform.position;
                transform.rotation = VarjoManager.Instance.HeadTransform.rotation;

                // Transform gaze direction and origin from HMD space to world space
                gazeRayDirection = transform.TransformVector(gazeRayForward);
                gazeRayOrigin    = transform.TransformPoint(gazePosition);



                gazeCircle.gameObject.transform.position = gazeRayOrigin + (gazeRayDirection * 7.0f);
                ChangeGazeCircleSize(data.focusDistance);

                // Raycast into world
                if (Physics.SphereCast(gazeRayOrigin, gazeRayRadius, gazeRayDirection, out gazeRayHit))
                {
                    if (drawDebug)
                    {
                        Debug.DrawLine(gazeRayOrigin, gazeRayOrigin + gazeRayDirection * 10.0f, Color.green);
                    }

                    HeatmapDataReceiver dataTarget = gazeRayHit.collider.gameObject.GetComponent <HeatmapDataReceiver>();

                    if (dataTarget != null)
                    {
                        dataTarget.ReceivePosition(gazeRayHit.point, gazeRayRadius);
                    }

                    GazeTargetPanel panelTarget = gazeRayHit.collider.gameObject.GetComponent <GazeTargetPanel>();

                    if (panelTarget != null)
                    {
                        panelTarget.OnGazeRayHit();
                    }
                }
                else
                {
                    if (drawDebug)
                    {
                        Debug.DrawLine(gazeRayOrigin, gazeRayOrigin + gazeRayDirection * 10.0f, Color.white);
                    }
                }
            }
        }