using Rokid.UXR.Native;
using Rokid.UXR.Utility;
using UnityEngine;
using UnityEngine.SpatialTracking;
namespace Rokid.UXR.Module
{
public class RKCameraRig : MonoBehaviour
{
///
/// This enum is used to indicate which parts of the pose will be applied to the parent transform
///
public enum HeadTrackingType
{
///
/// With this setting, both the pose's rotation and position will be applied to the parent transform
///
RotationAndPosition = 0,
///
/// With this setting, only the pose's rotation will be applied to the parent transform
///
RotationOnly = 1,
///
/// With this setting, only the pose's position will be applied to the parent transform
///
PositionOnly = 2,
///
/// With this setting, none value will be applied to the parent transform
///
None = 3
}
[SerializeField]
HeadTrackingType m_HeadTrackingType;
HeadTrackingType m_PreHeadTrackingType;
///
/// The tracking type being used by the tracked pose driver
///
public HeadTrackingType headTrackingType
{
get { return m_HeadTrackingType; }
set { m_HeadTrackingType = value; }
}
///
/// The update type being used by the tracked pose driver
///
public enum UpdateType
{
///
/// Sample input at both update, and directly before rendering. For smooth head pose tracking,
/// we recommend using this value as it will provide the lowest input latency for the device.
/// This is the default value for the UpdateType option
///
UpdateAndBeforeRender,
///
/// Only sample input during the update phase of the frame.
///
Update,
///
/// Only sample input directly before rendering
///
BeforeRender,
}
[SerializeField]
UpdateType m_UpdateType;
UpdateType m_PreUpdateType;
public UpdateType updateType
{
get
{
return m_UpdateType;
}
set
{
m_UpdateType = value;
}
}
private TrackedPoseDriver m_TrackedPoseDriver;
private void OnRenderImage(RenderTexture src, RenderTexture dest)
{
Graphics.Blit(src, dest);
}
private void Start()
{
if (Utils.IsAndroidPlatfrom())
{
// GetComponent().fieldOfView = NativeInterface.NativeAPI.GetVFov(true);
m_TrackedPoseDriver = gameObject.GetComponent();
if (m_TrackedPoseDriver == null)
{
m_TrackedPoseDriver = gameObject.AddComponent();
}
if (m_HeadTrackingType != HeadTrackingType.None)
{
switch (m_HeadTrackingType)
{
case HeadTrackingType.RotationAndPosition:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition;
break;
case HeadTrackingType.RotationOnly:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition;
break;
case HeadTrackingType.PositionOnly:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.PositionOnly;
break;
}
}
else
{
m_TrackedPoseDriver.enabled = false;
}
RKLog.Info($"====RKCameraRig====: SetHeadTrackingType :{m_HeadTrackingType}");
NativeInterface.NativeAPI.SetTrackingType((int)m_HeadTrackingType);
m_PreHeadTrackingType = m_HeadTrackingType;
m_PreUpdateType = m_UpdateType;
}
}
private void Update()
{
if (Utils.IsAndroidPlatfrom())
{
if (m_PreHeadTrackingType != m_HeadTrackingType)
{
m_PreHeadTrackingType = m_HeadTrackingType;
if (m_HeadTrackingType == HeadTrackingType.None)
{
m_TrackedPoseDriver.enabled = false;
}
else
{
m_TrackedPoseDriver.enabled = true;
switch (m_HeadTrackingType)
{
case HeadTrackingType.RotationAndPosition:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition;
break;
case HeadTrackingType.RotationOnly:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition;
break;
case HeadTrackingType.PositionOnly:
m_TrackedPoseDriver.trackingType = TrackedPoseDriver.TrackingType.PositionOnly;
break;
}
}
NativeInterface.NativeAPI.SetTrackingType((int)m_HeadTrackingType);
}
if (m_PreUpdateType != m_UpdateType)
{
m_PreUpdateType = m_UpdateType;
m_TrackedPoseDriver.updateType = (TrackedPoseDriver.UpdateType)m_UpdateType;
}
}
}
private void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus == false)
{
NativeInterface.NativeAPI.SetTrackingType((int)m_HeadTrackingType);
}
}
}
}