/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal
{
#if UNITY_EDITOR
using System;
using UnityEngine;
using System.Runtime.InteropServices;
[Obsolete]
internal partial class NativeEmulator
{
/// Default constructor.
public NativeEmulator()
{
}
/// Handle of the tracking.
private UInt64 m_TrackingHandle;
/// Handle of the controller.
private UInt64 m_ControllerHandle;
#region Tracking
/// Creates simulation tracking.
/// True if it succeeds, false if it fails.
public bool CreateSIMTracking()
{
NativeResult result = NativeApi.NRSIMTrackingCreate(ref m_TrackingHandle);
return result == NativeResult.Success;
}
/// Sets head tracking pose.
/// The position.
/// The rotation.
/// True if it succeeds, false if it fails.
public bool SetHeadTrackingPose(Vector3 position, Quaternion rotation)
{
NativeVector3f nativeVector3F = new NativeVector3f(new Vector3(position.x, position.y, -position.z));
NativeVector4f nativeVector4F = new NativeVector4f(new Vector4(rotation.x, rotation.y, -rotation.z, -rotation.w));
NativeResult result = NativeApi.NRSIMTrackingSetHeadTrackingPose(m_TrackingHandle, ref nativeVector3F, ref nativeVector4F);
return result == NativeResult.Success;
}
/// Updates the trackable image data.
/// The center position.
/// The center qua.
/// The extent x coordinate.
/// The extent z coordinate.
/// The identifier.
/// The state.
/// True if it succeeds, false if it fails.
public bool UpdateTrackableImageData(Vector3 centerPos, Quaternion centerQua, float extentX, float extentZ, UInt32 identifier, TrackingState state)
{
NativeVector3f pos = new NativeVector3f(new Vector3(centerPos.x, centerPos.y, -centerPos.z));
NativeVector4f qua = new NativeVector4f(new Vector4(-centerQua.x, -centerQua.y, centerQua.z, centerQua.w));
NativeResult result = NativeApi.NRSIMTrackingUpdateTrackableImageData(m_TrackingHandle, ref pos, ref qua, extentX, extentZ, identifier, (int)state);
return result == NativeResult.Success;
}
/// Updates the trackable plane data.
/// The center position.
/// The center qua.
/// The extent x coordinate.
/// The extent z coordinate.
/// The identifier.
/// The state.
/// True if it succeeds, false if it fails.
public bool UpdateTrackablePlaneData(Vector3 centerPos, Quaternion centerQua, float extentX, float extentZ, UInt32 identifier, TrackingState state)
{
NativeVector3f pos = new NativeVector3f(new Vector3(centerPos.x, centerPos.y, -centerPos.z));
NativeVector4f qua = new NativeVector4f(new Vector4(-centerQua.x, -centerQua.y, centerQua.z, centerQua.w));
NativeResult result = NativeApi.NRSIMTrackingUpdateTrackablePlaneData(m_TrackingHandle, ref pos, ref qua, extentX, extentZ, identifier, (int)state);
return result == NativeResult.Success;
}
/// Set the trackables data for Unity Editor develop.
/// Generic type parameter.
/// The center position.
/// The center qua.
/// The extent x coordinate.
/// The extent z coordinate.
/// The identifier.
/// The state.
/// True if it succeeds, false if it fails.
public bool UpdateTrackableData(Vector3 centerPos, Quaternion centerQua, float extentX, float extentZ, System.UInt32 identifier, TrackingState state) where T : NRTrackable
{
if (typeof(NRTrackablePlane).Equals(typeof(T)))
{
return NREmulatorTrackableProvider.UpdateTrackablePlaneData(centerPos, centerQua, extentX, extentZ, identifier, state);
}
else if (typeof(NRTrackableImage).Equals(typeof(T)))
{
return NREmulatorTrackableProvider.UpdateTrackableImageData(centerPos, centerQua, extentX, extentZ, identifier, state);
}
else
{
return false;
}
}
#endregion
#region Controller
/// Creates simulation controller.
/// True if it succeeds, false if it fails.
public bool CreateSIMController()
{
NativeResult result = NativeApi.NRSIMControllerCreate(ref m_ControllerHandle);
return result == NativeResult.Success;
}
/// Determines if we can destory simulation controller.
/// True if it succeeds, false if it fails.
public bool DestorySIMController()
{
NativeResult result = NativeApi.NRSIMControllerDestroyAll();
return result == NativeResult.Success;
}
/// Sets controller timestamp.
/// The timestamp.
/// True if it succeeds, false if it fails.
public bool SetControllerTimestamp(UInt64 timestamp)
{
NativeResult result = NativeApi.NRSIMControllerSetTimestamp(m_ControllerHandle, timestamp);
return result == NativeResult.Success;
}
/// Sets controller position.
/// The postion.
/// True if it succeeds, false if it fails.
public bool SetControllerPosition(Vector3 postion)
{
NativeVector3f nv3 = new NativeVector3f(postion);
NativeResult result = NativeApi.NRSIMControllerSetPosition(m_ControllerHandle, ref nv3);
return result == NativeResult.Success;
}
/// Sets controller rotation.
/// The quaternion.
/// True if it succeeds, false if it fails.
public bool SetControllerRotation(Quaternion quaternion)
{
NativeVector4f nv4 = new NativeVector4f(new Vector4(quaternion.x, quaternion.y, -quaternion.z, -quaternion.w));
NativeResult result = NativeApi.NRSIMControllerSetRotation(m_ControllerHandle, ref nv4);
return result == NativeResult.Success;
}
/// Sets controller accelerometer.
/// The accel.
/// True if it succeeds, false if it fails.
public bool SetControllerAccelerometer(Vector3 accel)
{
NativeVector3f nv3 = new NativeVector3f(accel);
NativeResult result = NativeApi.NRSIMControllerSetAccelerometer(m_ControllerHandle, ref nv3);
return result == NativeResult.Success;
}
/// Sets controller button state.
/// State of the button.
/// True if it succeeds, false if it fails.
public bool SetControllerButtonState(Int32 buttonState)
{
NativeResult result = NativeApi.NRSIMControllerSetButtonState(m_ControllerHandle, buttonState);
return result == NativeResult.Success;
}
/// Sets controller is touching.
/// True if is touching, false if not.
/// True if it succeeds, false if it fails.
public bool SetControllerIsTouching(bool isTouching)
{
NativeResult result = NativeApi.NRSIMControllerSetIsTouching(m_ControllerHandle, isTouching);
return result == NativeResult.Success;
}
/// Sets controller touch point.
/// The x coordinate.
/// The y coordinate.
/// True if it succeeds, false if it fails.
public bool SetControllerTouchPoint(float x, float y)
{
NativeVector3f nv3 = new NativeVector3f(new Vector3(x, y, 0f));
NativeResult result = NativeApi.NRSIMControllerSetTouchPoint(m_ControllerHandle, ref nv3);
return result == NativeResult.Success;
}
/// Sets controller submit.
/// True if it succeeds, false if it fails.
public bool SetControllerSubmit()
{
NativeResult result = NativeApi.NRSIMControllerSubmit(m_ControllerHandle);
return result == NativeResult.Success;
}
#endregion
private partial struct NativeApi
{
/// Nrsim tracking create.
/// [in,out] Handle of the out tracking.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMTrackingCreate(ref UInt64 out_tracking_handle);
/// Nrsim tracking set head tracking pose.
/// Handle of the tracking.
/// [in,out] The position.
/// [in,out] The rotation.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMTrackingSetHeadTrackingPose(UInt64 tracking_handle,
ref NativeVector3f position, ref NativeVector4f rotation);
/// Nrsim tracking update trackable image data.
/// Handle of the tracking.
/// [in,out] The center position.
/// [in,out] The center rotation.
/// The extent x coordinate.
/// The extent z coordinate.
/// The identifier.
/// The state.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMTrackingUpdateTrackableImageData
(UInt64 tracking_handle, ref NativeVector3f center_pos, ref NativeVector4f center_rotation,
float extent_x, float extent_z, UInt32 identifier, int state);
/// Nrsim tracking update trackable plane data.
/// Handle of the tracking.
/// [in,out] The center position.
/// [in,out] The center rotation.
/// The extent x coordinate.
/// The extent z coordinate.
/// The identifier.
/// The state.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMTrackingUpdateTrackablePlaneData(UInt64 tracking_handle,
ref NativeVector3f center_pos, ref NativeVector4f center_rotation,
float extent_x, float extent_z, UInt32 identifier, int state);
/// Controller.
/// [in,out] Handle of the out controller.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerCreate(ref UInt64 out_controller_handle);
/// Nrsim controller destroy all.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerDestroyAll();
/// Nrsim controller set timestamp.
/// Handle of the controller.
/// The timestamp.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetTimestamp(UInt64 controller_handle, UInt64 timestamp);
/// Nrsim controller set position.
/// Handle of the controller.
/// [in,out] The position.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetPosition(UInt64 controller_handle, ref NativeVector3f position);
/// Nrsim controller set rotation.
/// Handle of the controller.
/// [in,out] The rotation.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetRotation(UInt64 controller_handle, ref NativeVector4f rotation);
/// Nrsim controller set accelerometer.
/// Handle of the controller.
/// [in,out] The accel.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetAccelerometer(UInt64 controller_handle, ref NativeVector3f accel);
/// Nrsim controller set button state.
/// Handle of the controller.
/// State of the button.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetButtonState(UInt64 controller_handle, Int32 buttonState);
/// Nrsim controller set is touching.
/// Handle of the controller.
/// True if is touching, false if not.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetIsTouching(UInt64 controller_handle, bool isTouching);
/// Nrsim controller set touch point.
/// Handle of the controller.
/// [in,out] The point.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSetTouchPoint(UInt64 controller_handle, ref NativeVector3f point);
/// Nrsim controller submit.
/// Handle of the controller.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRSIMControllerSubmit(UInt64 controller_handle);
/// Free library.
/// The module.
/// True if it succeeds, false if it fails.
[DllImport("kernel32", SetLastError = true)]
public static extern bool FreeLibrary(IntPtr hModule);
}
}
#endif
}