SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
5.0 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// Describes session relative data for an anchor.
  7. /// </summary>
  8. /// <seealso cref="XRAnchorSubsystem"/>
  9. [StructLayout(LayoutKind.Sequential)]
  10. public struct XRAnchor : ITrackable, IEquatable<XRAnchor>
  11. {
  12. /// <summary>
  13. /// Gets a default-initialized <see cref="XRAnchor"/>. This may be
  14. /// different from the zero-initialized version, e.g., the <see cref="pose"/>
  15. /// is <c>Pose.identity</c> instead of zero-initialized.
  16. /// </summary>
  17. public static XRAnchor defaultValue => s_Default;
  18. static readonly XRAnchor s_Default = new XRAnchor
  19. {
  20. m_Id = TrackableId.invalidId,
  21. m_Pose = Pose.identity,
  22. m_SessionId = Guid.Empty
  23. };
  24. /// <summary>
  25. /// Constructs the session relative data for an anchor.
  26. /// This is typically provided by an implementation of the <see cref="XRAnchorSubsystem"/>
  27. /// and not invoked directly.
  28. /// </summary>
  29. /// <param name="trackableId">The <see cref="TrackableId"/> associated with this anchor.</param>
  30. /// <param name="pose">The <c>Pose</c>, in session space, of the anchor.</param>
  31. /// <param name="trackingState">The <see cref="TrackingState"/> of the anchor.</param>
  32. /// <param name="nativePtr">A native pointer associated with the anchor. The data pointed to by
  33. /// this pointer is implementation-specific.</param>
  34. public XRAnchor(
  35. TrackableId trackableId,
  36. Pose pose,
  37. TrackingState trackingState,
  38. IntPtr nativePtr)
  39. {
  40. m_Id = trackableId;
  41. m_Pose = pose;
  42. m_TrackingState = trackingState;
  43. m_NativePtr = nativePtr;
  44. m_SessionId = Guid.Empty;
  45. }
  46. /// <summary>
  47. /// Constructs the session relative data for anchor.
  48. /// This is typically provided by an implementation of the <see cref="XRAnchorSubsystem"/>
  49. /// and not invoked directly.
  50. /// </summary>
  51. /// <param name="trackableId">The <see cref="TrackableId"/> associated with this anchor.</param>
  52. /// <param name="pose">The <c>Pose</c>, in session space, of the anchor.</param>
  53. /// <param name="trackingState">The <see cref="TrackingState"/> of the anchor.</param>
  54. /// <param name="nativePtr">A native pointer associated with the anchor. The data pointed to by
  55. /// this pointer is implementation-specific.</param>
  56. /// <param name="sessionId">The session from which this anchor originated.</param>
  57. public XRAnchor(
  58. TrackableId trackableId,
  59. Pose pose,
  60. TrackingState trackingState,
  61. IntPtr nativePtr,
  62. Guid sessionId)
  63. : this(trackableId, pose, trackingState, nativePtr)
  64. {
  65. m_SessionId = sessionId;
  66. }
  67. /// <summary>
  68. /// Get the <see cref="TrackableId"/> associated with this anchor.
  69. /// </summary>
  70. public TrackableId trackableId => m_Id;
  71. /// <summary>
  72. /// Get the <c>Pose</c>, in session space, for this anchor.
  73. /// </summary>
  74. public Pose pose => m_Pose;
  75. /// <summary>
  76. /// Get the <see cref="TrackingState"/> of this anchor.
  77. /// </summary>
  78. public TrackingState trackingState => m_TrackingState;
  79. /// <summary>
  80. /// A native pointer associated with the anchor.
  81. /// The data pointed to by this pointer is implementation-specific.
  82. /// </summary>
  83. public IntPtr nativePtr => m_NativePtr;
  84. /// <summary>
  85. /// The id of the session from which this anchor originated.
  86. /// </summary>
  87. public Guid sessionId => m_SessionId;
  88. public override int GetHashCode()
  89. {
  90. unchecked
  91. {
  92. var hashCode = m_Id.GetHashCode();
  93. hashCode = hashCode * 486187739 + m_Pose.GetHashCode();
  94. hashCode = hashCode * 486187739 + m_TrackingState.GetHashCode();
  95. hashCode = hashCode * 486187739 + m_NativePtr.GetHashCode();
  96. hashCode = hashCode * 486187739 + m_SessionId.GetHashCode();
  97. return hashCode;
  98. }
  99. }
  100. public bool Equals(XRAnchor other)
  101. {
  102. return
  103. m_Id.Equals(other.m_Id) &&
  104. m_Pose.Equals(other.m_Pose) &&
  105. m_TrackingState == other.m_TrackingState &&
  106. m_NativePtr == other.m_NativePtr &&
  107. m_SessionId.Equals(other.m_SessionId);
  108. }
  109. public override bool Equals(object obj) => obj is XRAnchor && Equals((XRAnchor)obj);
  110. public static bool operator==(XRAnchor lhs, XRAnchor rhs) => lhs.Equals(rhs);
  111. public static bool operator!=(XRAnchor lhs, XRAnchor rhs) => !lhs.Equals(rhs);
  112. TrackableId m_Id;
  113. Pose m_Pose;
  114. TrackingState m_TrackingState;
  115. IntPtr m_NativePtr;
  116. Guid m_SessionId;
  117. }
  118. }