コード例 #1
0
    private void Update()
    {
        TobiiXR_GazeRay gazeRay = TobiiXR.EyeTrackingData.GazeRay;

        if (gazeRay.IsValid && Physics.Raycast(gazeRay.Origin, gazeRay.Direction, out RaycastHit hit, 10f))
        {
            LastGazeRay = new Ray(gazeRay.Origin, gazeRay.Direction);

            _bufferedGazePositions[_gazeBufferIndex] = hit.point;
            int     i = _gazeBufferIndex;
            Vector3 averageGazePos = Vector3.zero;
            for (int s = 0; s < _numFramesToBuffer; s++)
            {
                averageGazePos += _bufferedGazePositions[i];
                i = (i + 1) % _numFramesToBuffer;
            }
            averageGazePos /= _numFramesToBuffer;

            _gazeBufferIndex = (_gazeBufferIndex + 1) % _numFramesToBuffer;
            GazePos          = averageGazePos;
        }
    }
コード例 #2
0
        public void SetPositionAndScale(TobiiXR_GazeRay gazeRay)
        {
            RaycastHit hit;
            var        distance = _defaultDistance;

            if (Physics.Raycast(gazeRay.Origin, gazeRay.Direction, out hit))
            {
                distance = hit.distance;
            }

            var interpolatedGazeDirection = Vector3.Lerp(_lastGazeDirection, gazeRay.Direction,
                                                         _smoothMoveSpeed * Time.unscaledDeltaTime);

            var usedDirection = _smoothMove ? interpolatedGazeDirection.normalized : gazeRay.Direction.normalized;

            transform.position = gazeRay.Origin + usedDirection * distance;

            transform.localScale = Vector3.one * distance * ScaleFactor;

            transform.forward = usedDirection.normalized;

            _lastGazeDirection = usedDirection;
        }