Example #1
0
        /// <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);
        }
Example #2
0
        private void InitClockRebaser()
        {
            _stopwatch.Start();
            eLeapRS result = LeapC.CreateClockRebaser(out _clockRebaser);

            if (result != eLeapRS.eLeapRS_Success)
            {
                Debug.LogError("Failed to create clock rebaser");
            }

            if (_clockRebaser == IntPtr.Zero)
            {
                Debug.LogError("Clock rebaser is null");
            }
        }
        public void TestCreateDestroyWithConfigRequest()
        {
            IntPtr connHandle = IntPtr.Zero;
            int    iterations = 5000;
            uint   requestId;

            for (int i = 0; i < iterations; i++)
            {
                //LEAP_CONNECTION_MESSAGE msg  = new LEAP_CONNECTION_MESSAGE();
                LeapC.CreateConnection(out connHandle);
                LeapC.OpenConnection(connHandle);
                LeapC.RequestConfigValue(connHandle, "tracking_version", out requestId);
                LeapC.DestroyConnection(connHandle);
            }
        }
Example #4
0
        /// <summary>
        /// Stops the connection for the existing instance of a Controller, clearing old
        /// policy flags and resetting the Controller to null.
        /// </summary>
        public void destroyController()
        {
            if (_leapController != null)
            {
                _leapController.StopConnection();
                _leapController.Dispose();
                _leapController = null;

#if SVR
                if (_clockRebaser != IntPtr.Zero)
                {
                    LeapC.DestroyClockRebaser(_clockRebaser);
                    _stopwatch.Stop();
                }
#endif
            }
        }
Example #5
0
        /// <summary>
        /// Returns the internal status field of the current device
        /// </summary>
        protected uint GetDeviceStatus()
        {
            eLeapRS result;

            LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();

            deviceInfo.serial = IntPtr.Zero;
            deviceInfo.size   = (uint)System.Runtime.InteropServices.Marshal.SizeOf(deviceInfo);
            result            = LeapC.GetDeviceInfo(InternalHandle, ref deviceInfo);

            if (result != eLeapRS.eLeapRS_Success)
            {
                return(0);
            }
            uint status = deviceInfo.status;

            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(deviceInfo.serial);
            return(status);
        }
Example #6
0
        public bool SetPaused(bool pause)
        {
            ulong prior_state = 0;
            ulong set_flags   = 0;
            ulong clear_flags = 0;

            if (pause)
            {
                set_flags = (ulong)eLeapDeviceFlag.eLeapDeviceFlag_Stream;
            }
            else
            {
                clear_flags = (ulong)eLeapDeviceFlag.eLeapDeviceFlag_Stream;
            }

            eLeapRS result = LeapC.SetDeviceFlags(Handle, set_flags, clear_flags, out prior_state);

            return(result == eLeapRS.eLeapRS_Success);
        }
Example #7
0
 /**
  * Returns a timestamp value as close as possible to the current time.
  * Values are in microseconds, as with all the other timestamp values.
  *
  * @since 2.2.7
  *
  */
 public long Now()
 {
     return(LeapC.GetNow());
 }
 public UInt64 TelemetryGetNow()
 {
     return(LeapC.TelemetryGetNow());
 }
Example #9
0
        public bool SetPaused(bool pause)
        {
            eLeapRS result = LeapC.LeapSetPause(Handle, pause);

            return(result == eLeapRS.eLeapRS_Success);
        }
Example #10
0
        protected virtual void Update()
        {
            if (_workerThreadProfiling)
            {
                LeapProfiling.Update();
            }

            if (!checkConnectionIntegrity())
            {
                return;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isCompiling)
            {
                UnityEditor.EditorApplication.isPlaying = false;
                Debug.LogWarning("Unity hot reloading not currently supported. Stopping Editor Playback.");
                return;
            }
#endif

            _fixedOffset.Update(Time.time - Time.fixedTime, Time.deltaTime);

            if (_frameOptimization == FrameOptimizationMode.ReusePhysicsForUpdate)
            {
                DispatchUpdateFrameEvent(_transformedFixedFrame);
                return;
            }

#if SVR
            if (_clockRebaser != IntPtr.Zero)
            {
                eLeapRS result = LeapC.UpdateRebase(_clockRebaser, _stopwatch.ElapsedMilliseconds, LeapC.GetNow());
                if (result != eLeapRS.eLeapRS_Success)
                {
                    Debug.LogWarning("UpdateRebase call failed");
                }
            }
#endif

            if (_useInterpolation)
            {
#if !UNITY_ANDROID || UNITY_EDITOR
                _smoothedTrackingLatency.value = Mathf.Min(_smoothedTrackingLatency.value, 30000f);
                _smoothedTrackingLatency.Update((float)(_leapController.Now() - _leapController.FrameTimestamp()), Time.deltaTime);
#endif
                long timestamp = CalculateInterpolationTime() + (ExtrapolationAmount * 1000);
                _unityToLeapOffset = timestamp - (long)(Time.time * S_TO_NS);

                _leapController.GetInterpolatedFrameFromTime(_untransformedUpdateFrame, timestamp, CalculateInterpolationTime() - (BounceAmount * 1000));
            }
            else
            {
                _leapController.Frame(_untransformedUpdateFrame);
            }

            if (_untransformedUpdateFrame != null)
            {
                transformFrame(_untransformedUpdateFrame, _transformedUpdateFrame);

                DispatchUpdateFrameEvent(_transformedUpdateFrame);
            }
        }
Example #11
0
 /**
  * Updates the estimate of latency between render time
  * and the Leap Motion device time.
  *
  * Call this function when a frame is rendered.
  *
  * @param externalClockTime The time in milliseconds when the graphics frame is rendered.
  * @param leapClock the time in milliseconds obtained by calling Controller.Now().
  * @since 3.x.z
  */
 public void UpdateRebaseEstimate(Int64 applicationClock, Int64 leapClock)
 {
     LeapC.UpdateRebase(_rebaserHandle, applicationClock, leapClock);
 }
Example #12
0
 /**
  * Updates the estimate of latency between render time
  * and the Leap Motion device time.
  *
  * Call this function when a frame is rendered. Uses the leap clock time
  * at the moment this function is called.
  *
  * @param externalClockTime The time in milliseconds when the graphics frame is rendered.
  * @since 3.x.z
  */
 public void UpdateRebaseEstimate(Int64 applicationClock)
 {
     LeapC.UpdateRebase(_rebaserHandle, applicationClock, LeapC.GetNow());
 }