/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using System; using System.Runtime.InteropServices; /// Native Tracking API. public partial class NativeTracking { /// The native interface. private NativeInterface m_NativeInterface; /// Handle of the tracking. private UInt64 m_TrackingHandle; /// Constructor. /// The native interface. public NativeTracking(NativeInterface nativeInterface) { m_NativeInterface = nativeInterface; } /// Creates a new bool. /// True if it succeeds, false if it fails. public bool Create() { NativeResult result = NativeApi.NRTrackingCreate(ref m_TrackingHandle); NativeErrorListener.Check(result, this, "Create"); m_NativeInterface.TrackingHandle = m_TrackingHandle; return result == NativeResult.Success; } /// Inits tracking mode. /// The mode. /// True if it succeeds, false if it fails. public bool InitTrackingMode(TrackingMode mode) { if (m_TrackingHandle == 0) { return false; } NativeResult result = NativeApi.NRTrackingInitSetTrackingMode(m_TrackingHandle, mode); NativeErrorListener.Check(result, this, "InitTrackingMode"); return result == NativeResult.Success; } /// Starts this object. /// True if it succeeds, false if it fails. public bool Start() { if (m_TrackingHandle == 0) { return false; } NativeResult result = NativeApi.NRTrackingStart(m_TrackingHandle); NativeErrorListener.Check(result, this, "Start"); return result == NativeResult.Success; } /// Switch tracking mode. /// The mode. /// True if it succeeds, false if it fails. public bool SwitchTrackingMode(TrackingMode mode) { NativeResult result = NativeApi.NRTrackingSetTrackingMode(m_TrackingHandle, mode); NativeErrorListener.Check(result, this, "SwitchTrackingMode"); return result == NativeResult.Success; } /// Pauses this object. /// True if it succeeds, false if it fails. public bool Pause() { if (m_TrackingHandle == 0) { return false; } NativeResult result = NativeApi.NRTrackingPause(m_TrackingHandle); NativeErrorListener.Check(result, this, "Pause"); return result == NativeResult.Success; } /// Resumes this object. /// True if it succeeds, false if it fails. public bool Resume() { if (m_TrackingHandle == 0) { return false; } NativeResult result = NativeApi.NRTrackingResume(m_TrackingHandle); NativeErrorListener.Check(result, this, "Resume"); return result == NativeResult.Success; } /// only worked at 3dof mode. public void Recenter() { if (m_TrackingHandle == 0) { return; } var result = NativeApi.NRTrackingRecenter(m_TrackingHandle); NativeErrorListener.Check(result, this, "Recenter"); } /// Destroys this object. /// True if it succeeds, false if it fails. public bool Destroy() { if (m_TrackingHandle == 0) { return false; } NativeResult result = NativeApi.NRTrackingDestroy(m_TrackingHandle); NativeErrorListener.Check(result, this, "Destroy"); m_TrackingHandle = 0; m_NativeInterface.TrackingHandle = m_TrackingHandle; return result == NativeResult.Success; } private partial struct NativeApi { /// Nr tracking create. /// [in,out] Handle of the out tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingCreate(ref UInt64 out_tracking_handle); /// Nr tracking initialize set tracking mode. /// Handle of the tracking. /// The tracking mode. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingInitSetTrackingMode(UInt64 tracking_handle, TrackingMode tracking_mode); /// Nr tracking start. /// Handle of the tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingStart(UInt64 tracking_handle); /// Nr tracking set tracking mode. /// Handle of the tracking. /// The tracking mode. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingSetTrackingMode(UInt64 tracking_handle, TrackingMode tracking_mode); /// Nr tracking destroy. /// Handle of the tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingDestroy(UInt64 tracking_handle); /// Nr tracking pause. /// Handle of the tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingPause(UInt64 tracking_handle); /// Nr tracking resume. /// Handle of the tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingResume(UInt64 tracking_handle); /// Nr tracking recenter. /// Handle of the tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingRecenter(UInt64 tracking_handle); }; } }