/// <summary>
        /// Return the predicted display time as a leap time
        /// </summary>
        /// <returns></returns>
        private long GetPredictedDisplayTime_LeapTime()
        {
            long leapClock = 0;

            // Predicted display time for the current frame in milliseconds
            float displayTime_ms = SxrShim.GetPredictedDisplayTime(SystemInfo.graphicsMultiThreaded);

            if (_clockRebaser != IntPtr.Zero)
            {
                LeapC.RebaseClock(_clockRebaser, (long)displayTime_ms + _stopwatch.ElapsedMilliseconds, out leapClock);
            }

            return(leapClock);
        }
        protected virtual LeapTransform GetWarpedMatrix(long timestamp, bool updateTemporalCompensation = true)
        {
            if (_mainCamera == null || this == null)
            {
                return(LeapTransform.Identity);
            }

            LeapTransform leapTransform = new LeapTransform();

            // If temporal warping is turned off
            if (_temporalWarpingMode == TemporalWarpingMode.Off)
            {
                //Calculate the Current Pose
                Pose currentPose = Pose.identity;
                if (_deviceOffsetMode == DeviceOffsetMode.Transform && deviceOrigin != null)
                {
                    currentPose = deviceOrigin.ToPose();
                }
                else
                {
                    transformHistory.SampleTransform(timestamp, out currentPose.position, out currentPose.rotation);
                }

                warpedPosition = currentPose.position;
                warpedRotation = currentPose.rotation;
            }
            //Calculate a Temporally Warped Pose
            else if (updateTemporalCompensation && transformHistory.history.IsFull)
            {
#if SVR
                if (_xr2TimewarpMode == TimewarpMode.Default && transformHistory.history.IsFull)
                {
                    var imageAdjustment = _temporalWarpingMode == TemporalWarpingMode.Images ? -20000 : 0;
                    var sampleTimestamp = timestamp - (long)(warpingAdjustment * 1000f) - imageAdjustment;
                    transformHistory.SampleTransform(sampleTimestamp, out warpedPosition, out warpedRotation);
                }
                else if (_xr2TimewarpMode == TimewarpMode.Experimental_XR2)
                {
                    // Get the predicted display time for the current frame in milliseconds, then get the predicted head pose
                    float predictedDisplayTime_ms = SxrShim.GetPredictedDisplayTime(SystemInfo.graphicsMultiThreaded);

                    Vector3    predictedWarpedPosition;
                    Quaternion predictedWarpedRotation;
                    SxrShim.GetPredictedHeadPose(predictedDisplayTime_ms, out predictedWarpedRotation, out predictedWarpedPosition);
                    warpedPosition.x = -predictedWarpedPosition.x;
                    warpedPosition.y = -predictedWarpedPosition.y;
                    warpedPosition.z = predictedWarpedPosition.z;
                    warpedRotation   = predictedWarpedRotation;
                }
#else
                if (transformHistory.history.IsFull)
                {
                    var imageAdjustment = _temporalWarpingMode == TemporalWarpingMode.Images ? -20000 : 0;
                    var sampleTimestamp = timestamp - (long)(warpingAdjustment * 1000f) - imageAdjustment;
                    transformHistory.SampleTransform(sampleTimestamp, out warpedPosition, out warpedRotation);
                }
#endif
            }

            // Normalize the rotation Quaternion.
            warpedRotation = warpedRotation.ToNormalized();

            // If we are NOT using a transform to offset the tracking
            if (_deviceOffsetMode != DeviceOffsetMode.Transform)
            {
                warpedPosition += warpedRotation * Vector3.up * deviceOffsetYAxis
                                  + warpedRotation * Vector3.forward * deviceOffsetZAxis;
                warpedRotation *= Quaternion.Euler(deviceTiltXAxis, 0f, 0f);

                warpedRotation *= Quaternion.Euler(-90f, 180f, 0f);
            }
            else
            {
                warpedRotation *= Quaternion.Euler(-90f, 90f, 90f);
            }


#if !SVR
            // Use the _mainCamera parent to transfrom the warped positions so the player can move around
            if (_mainCamera.transform.parent != null)
            {
                leapTransform = new LeapTransform(
                    _mainCamera.transform.parent.TransformPoint(warpedPosition).ToVector(),
                    _mainCamera.transform.parent.TransformRotation(warpedRotation).ToLeapQuaternion(),
                    Vector.Ones * 1e-3f
                    );
            }
            else
#endif
            {
                leapTransform = new LeapTransform(
                    warpedPosition.ToVector(),
                    warpedRotation.ToLeapQuaternion(),
                    Vector.Ones * 1e-3f
                    );
            }

            leapTransform.MirrorZ();

            return(leapTransform);
        }