public bool GetHeadPose(ref Pose pose, UInt64 timestamp = 0, UInt64 predict = 0) { UInt64 headPoseHandle = 0; UInt64 hmd_nanos = 0; NativeApi.NRTrackingGetHMDTimeNanos(m_NativeInterface.TrackingHandle, ref hmd_nanos); if (timestamp != 0) { hmd_nanos = timestamp; } else if (predict != 0) { hmd_nanos -= predict; } else { UInt64 predict_time = 0; NativeApi.NRHeadTrackingGetRecommendPredictTime(m_NativeInterface.TrackingHandle, headTrackingHandle, ref predict_time); hmd_nanos += predict_time; } var acquireTrackingPoseResult = NativeApi.NRHeadTrackingAcquireTrackingPose(m_NativeInterface.TrackingHandle, headTrackingHandle, hmd_nanos, ref headPoseHandle); NativeMat4f headpos_native = new NativeMat4f(Matrix4x4.identity); var getPoseResult = NativeApi.NRTrackingPoseGetPose(m_NativeInterface.TrackingHandle, headPoseHandle, ref headpos_native); ConversionUtility.ApiPoseToUnityPose(headpos_native, out pose); NativeApi.NRTrackingPoseDestroy(m_NativeInterface.TrackingHandle, headPoseHandle); return((acquireTrackingPoseResult == NativeResult.Success) && (getPoseResult == NativeResult.Success)); }
public static void ApiPoseToUnityMatrix(NativeMat4f apiPose, out Matrix4x4 unityMatrix) { Matrix4x4 glWorld_T_glLocal = apiPose.ToUnityMat4f(); Matrix4x4 unityWorld_T_glWorld = Matrix4x4.Scale(new Vector3(1, 1, -1)); Matrix4x4 unityWorld_T_unityLocal = unityWorld_T_glWorld * glWorld_T_glLocal * unityWorld_T_glWorld.inverse; unityMatrix = unityWorld_T_unityLocal; }
public bool DoRender(IntPtr left_eye_texture, IntPtr right_eye_texture, ref NativeMat4f head_pose) { #if UNITY_ANDROID && !UNITY_EDITOR var result = NativeApi.NRRenderingDoRender(m_RenderingHandle, left_eye_texture, right_eye_texture, ref head_pose); return(result == NativeResult.Success); #else return(true); #endif }
public Pose GetCenterPose(UInt64 trackble_handle) { Pose pose = Pose.identity; NativeMat4f center_native_pos = NativeMat4f.identity; NativeApi.NRTrackablePlaneGetCenterPose(m_NativeInterface.TrackingHandle, trackble_handle, ref center_native_pos); ConversionUtility.ApiPoseToUnityPose(center_native_pos, out pose); return(pose); }
public bool GetProjectionMatrix(ref Matrix4x4 outLeftProjectionMatrix, ref Matrix4x4 outRightProjectionMatrix) { NativeMat4f projectmatrix = new NativeMat4f(Matrix4x4.identity); NativeResult result_left = NativeApi.NRInternalGetProjectionMatrix((int)NativeEye.LEFT, ref projectmatrix); outLeftProjectionMatrix = projectmatrix.ToUnityMat4f(); NativeResult result_right = NativeApi.NRInternalGetProjectionMatrix((int)NativeEye.RIGHT, ref projectmatrix); outRightProjectionMatrix = projectmatrix.ToUnityMat4f(); return(result_left == NativeResult.Success && result_right == NativeResult.Success); }
public static void ApiPoseToUnityPose(NativeMat4f apiPose, out Pose unityPose) { Matrix4x4 glWorld_T_glLocal = apiPose.ToUnityMat4f(); Matrix4x4 unityWorld_T_glWorld = Matrix4x4.Scale(new Vector3(1, 1, -1)); Matrix4x4 unityWorld_T_unityLocal = unityWorld_T_glWorld * glWorld_T_glLocal * unityWorld_T_glWorld.inverse; Vector3 position = unityWorld_T_unityLocal.GetColumn(3); Quaternion rotation = unityWorld_T_unityLocal.rotation; unityPose = new Pose(position, rotation); }
public Pose GetAnchorPose(UInt64 anchor_handle) { NativeMat4f nativePose = NativeMat4f.identity; NativeApi.NRAnchorGetPose(m_NativeInterface.TrackingHandle, anchor_handle, ref nativePose); Pose unitypose; ConversionUtility.ApiPoseToUnityPose(nativePose, out unitypose); return(unitypose); }
public Pose GetPose(int controllerIndex) { Pose controllerPos = Pose.identity; NativeMat4f mat4f = new NativeMat4f(Matrix4x4.identity); NativeResult result = NativeApi.NRControllerStateGetPose(m_StateHandles[controllerIndex], ref mat4f); if (result == NativeResult.Success) { ConversionUtility.ApiPoseToUnityPose(mat4f, out controllerPos); } return(controllerPos); }
public Pose GetEyePoseFromHead(NativeEye eye) { Pose outEyePoseFromHead = Pose.identity; NativeMat4f mat4f = new NativeMat4f(Matrix4x4.identity); NativeResult result = NativeApi.NRHMDGetEyePoseFromHead(m_HmdHandle, (int)eye, ref mat4f); if (result == NativeResult.Success) { ConversionUtility.ApiPoseToUnityPose(mat4f, out outEyePoseFromHead); } return(outEyePoseFromHead); }
public NativeResult GetEyePose(ref Pose outLeftEyePose, ref Pose outRightEyePose) { NativeMat4f lefteyepos = new NativeMat4f(Matrix4x4.identity); NativeMat4f righteyepos = new NativeMat4f(Matrix4x4.identity); NativeResult result = NativeApi.NRHeadTrackingGetEyePose(m_NativeInterface.TrackingHandle, headTrackingHandle, ref lefteyepos, ref righteyepos); if (result == NativeResult.Success) { ConversionUtility.ApiPoseToUnityPose(lefteyepos, out outLeftEyePose); ConversionUtility.ApiPoseToUnityPose(righteyepos, out outRightEyePose); } NRDebugger.Log("[NativeHeadTracking] GetEyePose :" + result); return(result); }
public static void UnityPoseToApiPose(Pose unityPose, out NativeMat4f apiPose) { Matrix4x4 glWorld_T_glLocal = Matrix4x4.TRS(unityPose.position, unityPose.rotation, Vector3.one); Matrix4x4 unityWorld_T_glWorld = Matrix4x4.Scale(new Vector3(1, 1, -1)); Matrix4x4 unityWorld_T_unityLocal = unityWorld_T_glWorld * glWorld_T_glLocal * unityWorld_T_glWorld.inverse; Vector3 position = unityWorld_T_unityLocal.GetColumn(3); Quaternion rotation = Quaternion.LookRotation(unityWorld_T_unityLocal.GetColumn(2), unityWorld_T_unityLocal.GetColumn(1)); Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, Vector3.one); apiPose = new NativeMat4f(matrix); }
public static NativeMat4f GetProjectionMatrixFromFov(NativeFov4f fov, float z_near, float z_far) { NativeMat4f pm = NativeMat4f.identity; float l = -fov.left_tan; float r = fov.right_tan; float t = fov.top_tan; float b = -fov.bottom_tan; pm.column0.X = 2f / (r - l); pm.column1.Y = 2f / (t - b); pm.column2.X = (r + l) / (r - l); pm.column2.Y = (t + b) / (t - b); pm.column2.Z = (z_near + z_far) / (z_near - z_far); pm.column2.W = -1f; pm.column3.Z = (2 * z_near * z_far) / (z_near - z_far); pm.column3.W = 0f; return(pm); }
public Pose GetHeadPose() { UInt64 headPoseHandle = 0; UInt64 hmd_nanos = 0; var result = NativeApi.NRTrackingGetHMDTimeNanos(m_NativeInterface.TrackingHandle, ref hmd_nanos); UInt64 predict_time = 0; NativeApi.NRHeadTrackingGetRecommendPredictTime(m_NativeInterface.TrackingHandle, headTrackingHandle, ref predict_time); hmd_nanos += predict_time; result = NativeApi.NRHeadTrackingAcquireTrackingPose(m_NativeInterface.TrackingHandle, headTrackingHandle, hmd_nanos, ref headPoseHandle); //NRDebug.Log("[NativeHeadTracking Create :]" + m_NativeInterface.TrackingHandle + " head tracking handle:" + headTrackingHandle.ToString()); NativeMat4f headpos_native = new NativeMat4f(Matrix4x4.identity); result = NativeApi.NRTrackingPoseGetPose(m_NativeInterface.TrackingHandle, headPoseHandle, ref headpos_native); Pose head_pose = Pose.identity; if (result == NativeResult.Success) { ConversionUtility.ApiPoseToUnityPose(headpos_native, out head_pose); } NativeApi.NRTrackingPoseDestroy(m_NativeInterface.TrackingHandle, headPoseHandle); return(head_pose); }
public static extern NativeResult NRAnchorGetPose(UInt64 tracking_handle, UInt64 anchor_handle, ref NativeMat4f out_pose);
public FrameInfo(IntPtr left, IntPtr right, NativeMat4f p) { this.leftTex = left; this.rightTex = right; this.pose = p; }
public static extern NativeResult NRHeadTrackingGetEyePose(UInt64 session_handle, UInt64 head_tracking_handle, ref NativeMat4f left_eye, ref NativeMat4f right_eye);
public static extern NativeResult NRTrackingAcquireNewAnchor( UInt64 tracking_handle, NativeMat4f pose, ref UInt64 out_anchor_handle);
public static extern NativeResult NRInternalGetProjectionMatrix(int index, ref NativeMat4f eye);
public static extern NativeResult NRControllerStateGetPose(UInt64 controller_state_handle, ref NativeMat4f out_controller_pose);
public static extern NativeResult NRTrackingPoseGetPose(UInt64 tracking_handle, UInt64 tracking_pose_handle, ref NativeMat4f out_pose);
public static extern NativeResult NRControllerSetHeadPose(UInt64 controller_handle, ref NativeMat4f out_controller_pose);
public static extern NativeResult NRHMDGetEyePoseFromHead(UInt64 hmd_handle, int eye, ref NativeMat4f outEyePoseFromHead);
public static extern NativeResult NRTrackablePlaneGetCenterPose(UInt64 session_handle, UInt64 trackable_handle, ref NativeMat4f out_center_pose);
public static extern NativeResult NRRenderingDoRender(UInt64 rendering_handle, IntPtr left_eye_texture, IntPtr right_eye_texture, ref NativeMat4f head_pose);