NRTrackable.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using UnityEngine;
  13. /// <summary>
  14. /// A Trackable in the real world detected by NRInternel. The base class of TrackablePlane and
  15. /// TrackableImage.Through this class, application can get the infomation of a trackable object. </summary>
  16. public abstract class NRTrackable
  17. {
  18. /// <summary> Handle of the trackable native. </summary>
  19. internal UInt64 TrackableNativeHandle = 0;
  20. private NRTrackableSubsystem m_TrackableSubsystem;
  21. internal NRTrackableSubsystem TrackableSubsystem
  22. {
  23. get
  24. {
  25. if (m_TrackableSubsystem == null)
  26. {
  27. m_TrackableSubsystem = NRSessionManager.Instance.TrackableFactory.TrackableSubsystem;
  28. }
  29. return m_TrackableSubsystem;
  30. }
  31. }
  32. /// <summary> Constructor. </summary>
  33. /// <param name="trackableNativeHandle"> Handle of the trackable native.</param>
  34. /// <param name="nativeinterface"> The nativeinterface.</param>
  35. internal NRTrackable(UInt64 trackableNativeHandle)
  36. {
  37. TrackableNativeHandle = trackableNativeHandle;
  38. }
  39. /// <summary> Get the id of trackable. </summary>
  40. /// <returns> The data base index. </returns>
  41. public int GetDataBaseIndex()
  42. {
  43. UInt32 identify = TrackableSubsystem.GetIdentify(TrackableNativeHandle);
  44. identify &= 0X0000FFFF;
  45. return (int)identify;
  46. }
  47. /// <summary> Get the tracking state of current trackable. </summary>
  48. /// <returns> The tracking state. </returns>
  49. public TrackingState GetTrackingState()
  50. {
  51. if (NRFrame.SessionStatus != SessionState.Running)
  52. {
  53. return TrackingState.Stopped;
  54. }
  55. return TrackableSubsystem.GetTrackingState(TrackableNativeHandle);
  56. }
  57. /// <summary> Type of the trackable. </summary>
  58. TrackableType trackableType;
  59. /// <summary> Get the tracking type of current trackable. </summary>
  60. /// <returns> The trackable type. </returns>
  61. public TrackableType GetTrackableType()
  62. {
  63. if (NRFrame.SessionStatus != SessionState.Running)
  64. {
  65. return trackableType;
  66. }
  67. trackableType = TrackableSubsystem.GetTrackableType(TrackableNativeHandle);
  68. return trackableType;
  69. }
  70. /// <summary> Get the center pose of current trackable. </summary>
  71. /// <returns> The center pose. </returns>
  72. public virtual Pose GetCenterPose()
  73. {
  74. return Pose.identity;
  75. }
  76. /// <summary> Creates an anchor attached to current trackable at given pose. </summary>
  77. /// <returns> The new anchor. </returns>
  78. public NRAnchor CreateAnchor()
  79. {
  80. return NRAnchor.Factory(this);
  81. }
  82. }
  83. }