/**************************************************************************** * 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; using System.Text; using UnityEngine; /// 6-dof Trackable Image Tracking's Native API . public partial class NativeTrackableImage { /// The native interface. private NativeInterface m_NativeInterface; /// Constructor. /// The native interface. public NativeTrackableImage(NativeInterface nativeInterface) { m_NativeInterface = nativeInterface; } /// Creates data base. /// The new data base. public UInt64 CreateDataBase() { UInt64 database_handle = 0; var result = NativeApi.NRTrackableImageDatabaseCreate(m_NativeInterface.TrackingHandle, ref database_handle); NativeErrorListener.Check(result, this, "CreateDataBase"); return database_handle; } /// Destroys the data base described by database_handle. /// Handle of the database. /// True if it succeeds, false if it fails. public bool DestroyDataBase(UInt64 database_handle) { var result = NativeApi.NRTrackableImageDatabaseDestroy(m_NativeInterface.TrackingHandle, database_handle); NativeErrorListener.Check(result, this, "DestroyDataBase"); return result == NativeResult.Success; } /// Loads data base. /// Handle of the database. /// Full pathname of the file. /// True if it succeeds, false if it fails. public bool LoadDataBase(UInt64 database_handle, string path) { var result = NativeApi.NRTrackableImageDatabaseLoadDirectory(m_NativeInterface.TrackingHandle, database_handle, path); return result == NativeResult.Success; } /// Gets center pose. /// Handle of the trackable. /// The center pose. public Pose GetCenterPose(UInt64 trackable_handle) { Pose pose = Pose.identity; NativeMat4f center_pose_native = NativeMat4f.identity; NativeApi.NRTrackableImageGetCenterPose(m_NativeInterface.TrackingHandle, trackable_handle, ref center_pose_native); ConversionUtility.ApiPoseToUnityPose(center_pose_native, out pose); return pose; } /// Gets a size. /// Handle of the trackable. /// The size. public Vector2 GetSize(UInt64 trackable_handle) { float extent_x, extent_z; extent_x = extent_z = 0; NativeApi.NRTrackableImageGetExtentX(m_NativeInterface.TrackingHandle, trackable_handle, ref extent_x); NativeApi.NRTrackableImageGetExtentZ(m_NativeInterface.TrackingHandle, trackable_handle, ref extent_z); return new Vector2(extent_x * 0.001f, extent_z * 0.001f); } private partial struct NativeApi { /// Nr trackable image database create. /// Handle of the session. /// [in,out] Handle of the out trackable /// image database. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableImageDatabaseCreate(UInt64 session_handle, ref UInt64 out_trackable_image_database_handle); /// Nr trackable image database destroy. /// Handle of the session. /// Handle of the trackable image database. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableImageDatabaseDestroy(UInt64 session_handle, UInt64 trackable_image_database_handle); /// Nr trackable image database load directory. /// Handle of the session. /// Handle of the trackable image database. /// Pathname of the trackable image database /// directory. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary, CallingConvention = CallingConvention.Cdecl)] public static extern NativeResult NRTrackableImageDatabaseLoadDirectory(UInt64 session_handle, UInt64 trackable_image_database_handle, string trackable_image_database_directory); /// Nr trackable image get center pose. /// Handle of the session. /// Handle of the trackable. /// [in,out] The out center pose. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableImageGetCenterPose(UInt64 session_handle, UInt64 trackable_handle, ref NativeMat4f out_center_pose); /// Nr trackable image get extent x coordinate. /// Handle of the session. /// Handle of the trackable. /// [in,out] The out extent x coordinate. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableImageGetExtentX(UInt64 session_handle, UInt64 trackable_handle, ref float out_extent_x); /// Nr trackable image get extent z coordinate. /// Handle of the session. /// Handle of the trackable. /// [in,out] The out extent z coordinate. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableImageGetExtentZ(UInt64 session_handle, UInt64 trackable_handle, ref float out_extent_z); }; } }