예제 #1
0
 private static void FillGazeRayFrom(ref TobiiXR_GazeRay gazeRay, tobii_validity_t originValidity, TobiiVector3 origin, tobii_validity_t directionValidity, TobiiVector3 direction, Vector3 headToCenterEyeTranslation)
 {
     gazeRay.IsValid =
         originValidity == tobii_validity_t.TOBII_VALIDITY_VALID &&
         directionValidity == tobii_validity_t.TOBII_VALIDITY_VALID;
     gazeRay.Origin.x    = origin.x * -1 / 1000f;
     gazeRay.Origin.y    = origin.y / 1000f;
     gazeRay.Origin.z    = origin.z / 1000f;
     gazeRay.Origin     += headToCenterEyeTranslation;
     gazeRay.Direction.x = direction.x * -1;
     gazeRay.Direction.y = direction.y;
     gazeRay.Direction.z = direction.z;
 }
예제 #2
0
        /// <summary>
        /// Converts gaze rays to projected gaze points in screen space coordinates.
        /// Be aware that screen space and texture space may have different Y directions. Also be aware that in single pass rendering the screen buffer contains both eyes so you would have to renormalize the x value of left and right gaze point.
        /// </summary>
        /// <param name="leftGazeRayViewSpace">Left gaze ray in view space coordinates.</param>
        /// <param name="rightGazeRayViewSpace">Right gaze ray in view space coordinates.</param>
        /// <param name="leftGazePoint">Normalized Gaze point where 0, 0 is bottom left and 1, 1 is top right of the left screen. Null means no value could be produced.</param>
        /// <param name="rightGazePoint">Normalized Gaze point where 0, 0 is bottom left and 1, 1 is top right of the right screen. Null means no value could be produced.</param>
        public static void GetScreenSpaceFor(TobiiXR_GazeRay leftGazeRayViewSpace, TobiiXR_GazeRay rightGazeRayViewSpace, out Vector2?leftGazePoint, out Vector2?rightGazePoint)
        {
            leftGazePoint  = null;
            rightGazePoint = null;
            var     cam = CameraHelper.GetMainCamera();
            Vector3 leftOffset;
            Vector3 rightOffset;

            if (!GetEyeOffsets(out leftOffset, out rightOffset))
            {
                return;
            }

            if (leftGazeRayViewSpace.IsValid)
            {
                leftGazePoint = GetScreenSpaceFor(leftGazeRayViewSpace.Direction, leftOffset - leftGazeRayViewSpace.Origin, cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left));
            }
            if (rightGazeRayViewSpace.IsValid)
            {
                rightGazePoint = GetScreenSpaceFor(rightGazeRayViewSpace.Direction, rightOffset - rightGazeRayViewSpace.Origin, cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right));
            }
        }
예제 #3
0
        private 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;
        }
 private static void TransformToWorldSpace(ref TobiiXR_GazeRay eyeData, Matrix4x4 hmdOrigin)
 {
     eyeData.Origin    = hmdOrigin.MultiplyPoint(eyeData.Origin);
     eyeData.Direction = hmdOrigin.MultiplyVector(eyeData.Direction);
 }
 private static void TransformToWorldSpace(ref TobiiXR_GazeRay eyeData, Transform hmdOrigin)
 {
     eyeData.Origin    = hmdOrigin.TransformPoint(eyeData.Origin);
     eyeData.Direction = hmdOrigin.TransformDirection(eyeData.Direction);
 }