/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * NRSDK is distributed in the hope that it will be usefull * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal.Experimental { using System; using UnityEngine; using System.Runtime.InteropServices; /// Only Internal Test Not Release !!!!! public static class NativeHeadTrackingExtension { /// A NativeHeadTracking extension method that gets eye pose. /// The headTracking to act on. /// [in,out] The out left eye pose. /// [in,out] The out right eye pose. /// The eye pose. public static NativeResult GetEyePose(this NativeHeadTracking headTracking, ref Pose outLeftEyePose, ref Pose outRightEyePose) { NativeMat4f lefteyepos = new NativeMat4f(Matrix4x4.identity); NativeMat4f righteyepos = new NativeMat4f(Matrix4x4.identity); NativeResult result = NativeApi.NRHeadTrackingGetEyePose(headTracking.TrackingHandle, headTracking.HeadTrackingHandle, ref lefteyepos, ref righteyepos); if (result == NativeResult.Success) { ConversionUtility.ApiPoseToUnityPose(lefteyepos, out outLeftEyePose); ConversionUtility.ApiPoseToUnityPose(righteyepos, out outRightEyePose); } NRDebugger.Info("[NativeHeadTracking] GetEyePose :" + result); return result; } /// A NativeHeadTracking extension method that gets projection matrix. /// The headTracking to act on. /// [in,out] The out left projection matrix. /// [in,out] The out right projection matrix. /// True if it succeeds, false if it fails. public static bool GetProjectionMatrix(this NativeHeadTracking headTracking, ref Matrix4x4 outLeftProjectionMatrix, ref Matrix4x4 outRightProjectionMatrix) { NativeMat4f projectmatrix = new NativeMat4f(Matrix4x4.identity); NativeResult result_left = NativeApi.NRInternalGetProjectionMatrix((int)NativeDevice.LEFT_DISPLAY, ref projectmatrix); outLeftProjectionMatrix = projectmatrix.ToUnityMat4f(); NativeResult result_right = NativeApi.NRInternalGetProjectionMatrix((int)NativeDevice.RIGHT_DISPLAY, ref projectmatrix); outRightProjectionMatrix = projectmatrix.ToUnityMat4f(); return (result_left == NativeResult.Success && result_right == NativeResult.Success); } /// A native api. private struct NativeApi { /// Nr head tracking get eye pose. /// Handle of the session. /// Handle of the head tracking. /// [in,out] The left eye. /// [in,out] The right eye. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRHeadTrackingGetEyePose(UInt64 session_handle, UInt64 head_tracking_handle, ref NativeMat4f left_eye, ref NativeMat4f right_eye); /// Nr internal get projection matrix. /// Zero-based index of the. /// [in,out] The eye. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRInternalGetProjectionMatrix(int index, ref NativeMat4f eye); }; } }