123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
-
- namespace NRKernal
- {
- using System;
- using UnityEngine;
- using System.Runtime.InteropServices;
-
- public partial class NativeHMD
- {
-
- private UInt64 m_HmdHandle;
-
-
- public UInt64 HmdHandle
- {
- get
- {
- return m_HmdHandle;
- }
- }
-
-
- public bool Create()
- {
- NativeResult result = NativeApi.NRHMDCreate(ref m_HmdHandle);
- NativeErrorListener.Check(result, this, "Create");
- return result == NativeResult.Success;
- }
-
-
- public bool Pause()
- {
- NativeResult result = NativeApi.NRHMDPause(m_HmdHandle);
- NativeErrorListener.Check(result, this, "Pause");
- return result == NativeResult.Success;
- }
-
-
- public bool Resume()
- {
- NativeResult result = NativeApi.NRHMDResume(m_HmdHandle);
- NativeErrorListener.Check(result, this, "Resume");
- return result == NativeResult.Success;
- }
-
-
-
- public Pose GetDevicePoseFromHead(NativeDevice device)
- {
- return GetDevicePoseFromHead((int)device);
- }
-
-
-
- public Pose GetDevicePoseFromHead(int device)
- {
- Pose outDevicePoseFromHead = Pose.identity;
- NativeMat4f mat4f = new NativeMat4f(Matrix4x4.identity);
- NativeResult result = NativeApi.NRHMDGetEyePoseFromHead(m_HmdHandle, device, ref mat4f);
- if (result == NativeResult.Success)
- {
- ConversionUtility.ApiPoseToUnityPose(mat4f, out outDevicePoseFromHead);
- }
- return outDevicePoseFromHead;
- }
-
-
-
-
-
- public bool GetProjectionMatrix(ref EyeProjectMatrixData outEyesProjectionMatrix, float znear, float zfar)
- {
- NativeFov4f fov = new NativeFov4f();
- NativeResult result_left = NativeApi.NRHMDGetEyeFovInCoord(m_HmdHandle, (int)NativeDevice.LEFT_DISPLAY, ref fov);
- NativeErrorListener.Check(result_left, this, "GetProjectionMatrix-L");
- NRDebugger.Info("[GetProjectionMatrix] LEFT_DISPLAY: {0}", fov.ToString());
- outEyesProjectionMatrix.LEyeMatrix = ConversionUtility.GetProjectionMatrixFromFov(fov, znear, zfar).ToUnityMat4f();
-
- NativeResult result_right = NativeApi.NRHMDGetEyeFovInCoord(m_HmdHandle, (int)NativeDevice.RIGHT_DISPLAY, ref fov);
- NativeErrorListener.Check(result_right, this, "GetProjectionMatrix-R");
- NRDebugger.Info("[GetProjectionMatrix] RIGHT_DISPLAY: {0}", fov.ToString());
- outEyesProjectionMatrix.REyeMatrix = ConversionUtility.GetProjectionMatrixFromFov(fov, znear, zfar).ToUnityMat4f();
-
- NativeResult result_RGB = NativeApi.NRHMDGetEyeFovInCoord(m_HmdHandle, (int)NativeDevice.RGB_CAMERA, ref fov);
- NativeErrorListener.Check(result_RGB, this, "GetProjectionMatrix-RGB");
- outEyesProjectionMatrix.RGBEyeMatrix = ConversionUtility.GetProjectionMatrixFromFov(fov, znear, zfar).ToUnityMat4f();
- return (result_left == NativeResult.Success && result_right == NativeResult.Success && result_RGB == NativeResult.Success);
- }
- [Obsolete("Use 'GetEyeFovInCoord' to replace.")]
- public NativeFov4f GetEyeFov(NativeEye eye)
- {
- NativeFov4f fov = new NativeFov4f();
- NativeApi.NRHMDGetEyeFov(m_HmdHandle, (int)eye, ref fov);
- return fov;
- }
- public NativeFov4f GetEyeFovInCoord(NativeDevice eye)
- {
- NativeFov4f fov = new NativeFov4f();
- NativeApi.NRHMDGetEyeFovInCoord(m_HmdHandle, (int)eye, ref fov);
- return fov;
- }
-
-
-
-
- public bool GetCameraIntrinsicMatrix(int eye, ref NativeMat3f CameraIntrinsicMatix)
- {
- var result = NativeApi.NRHMDGetCameraIntrinsicMatrix(m_HmdHandle, (int)eye, ref CameraIntrinsicMatix);
- return result == NativeResult.Success;
- }
-
-
-
-
- public bool GetCameraDistortion(int eye, ref NRDistortionParams distortion)
- {
- var result = NativeApi.NRHMDGetCameraDistortionParams(m_HmdHandle, eye, ref distortion);
- return result == NativeResult.Success;
- }
-
-
-
- public NativeResolution GetEyeResolution(int eye)
- {
- NativeResolution resolution = new NativeResolution(1920, 1080);
- #if UNITY_EDITOR
- return resolution;
- #else
- var result = NativeApi.NRHMDGetEyeResolution(m_HmdHandle, eye, ref resolution);
- NativeErrorListener.Check(result, this, "GetEyeResolution");
- return resolution;
- #endif
- }
-
-
- public NRDeviceType GetDeviceType()
- {
- NRDeviceType deviceType = NRDeviceType.NrealLight;
- NativeApi.NRHMDGetDeviceType(m_HmdHandle, ref deviceType);
- return deviceType;
- }
-
-
-
- public bool IsFeatureSupported(NRSupportedFeature feature)
- {
- bool result = false;
- NativeApi.NRHMDIsFeatureSupported(m_HmdHandle, feature, ref result);
- return result;
- }
-
-
- public bool Destroy()
- {
- NativeResult result = NativeApi.NRHMDDestroy(m_HmdHandle);
- NativeErrorListener.Check(result, this, "Destroy");
- return result == NativeResult.Success;
- }
-
- private struct NativeApi
- {
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDCreate(ref UInt64 out_hmd_handle);
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetDeviceType(UInt64 hmd_handle, ref NRDeviceType out_device_type);
-
-
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDIsFeatureSupported(UInt64 hmd_handle, NRSupportedFeature feature, ref bool out_is_supported);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDPause(UInt64 hmd_handle);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDResume(UInt64 hmd_handle);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetEyePoseFromHead(UInt64 hmd_handle, int eye, ref NativeMat4f outEyePoseFromHead);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- [Obsolete]
- public static extern NativeResult NRHMDGetEyeFov(UInt64 hmd_handle, int eye, ref NativeFov4f out_eye_fov);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetEyeFovInCoord(UInt64 hmd_handle, int eye, ref NativeFov4f out_eye_fov);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetCameraIntrinsicMatrix(
- UInt64 hmd_handle, int eye, ref NativeMat3f out_intrinsic_matrix);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetCameraDistortionParams(
- UInt64 hmd_handle, int eye, ref NRDistortionParams out_params);
-
-
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDGetEyeResolution(UInt64 hmd_handle, int eye, ref NativeResolution out_eye_resolution);
-
-
-
- [DllImport(NativeConstants.NRNativeLibrary)]
- public static extern NativeResult NRHMDDestroy(UInt64 hmd_handle);
- };
- }
- }
|