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.

121 lines
4.0 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// Represents the intersection of a raycast with a trackable.
  7. /// </summary>
  8. /// <seealso cref="XRRaycastSubsystem.Raycast(Ray, TrackableType, Unity.Collections.Allocator)"/>
  9. /// <seealso cref="XRRaycastSubsystem.Raycast(Vector2, TrackableType, Unity.Collections.Allocator)"/>
  10. /// <seealso cref="XRRaycastSubsystem.RaycastAsync(Ray, TrackableType)"/>
  11. [StructLayout(LayoutKind.Sequential)]
  12. public struct XRRaycastHit : IEquatable<XRRaycastHit>
  13. {
  14. static readonly XRRaycastHit s_Default = new XRRaycastHit(
  15. TrackableId.invalidId, Pose.identity, 0, TrackableType.None);
  16. /// <summary>
  17. /// A default-initialized raycast hit.
  18. /// This may be different from a zero-initialized raycast hit.
  19. /// </summary>
  20. public static XRRaycastHit defaultValue => s_Default;
  21. /// <summary>
  22. /// The <see cref="TrackableId"/> of the trackable which was hit. This may be <see cref="TrackableId.invalidId"/>
  23. /// as not all trackables have ids, e.g., feature points.
  24. /// </summary>
  25. public TrackableId trackableId
  26. {
  27. get { return m_TrackableId; }
  28. set { m_TrackableId = value; }
  29. }
  30. /// <summary>
  31. /// The session-space <c>Pose</c> of the intersection.
  32. /// </summary>
  33. public Pose pose
  34. {
  35. get { return m_Pose; }
  36. set { m_Pose = value; }
  37. }
  38. /// <summary>
  39. /// The session-space distance from the raycast origin to the intersection point.
  40. /// </summary>
  41. public float distance
  42. {
  43. get { return m_Distance; }
  44. set { m_Distance = value; }
  45. }
  46. /// <summary>
  47. /// The type(s) of trackables which were hit by the ray.
  48. /// </summary>
  49. public TrackableType hitType
  50. {
  51. get { return m_HitType; }
  52. set { m_HitType = value; }
  53. }
  54. /// <summary>
  55. /// Constructs an <see cref="XRRaycastHit"/>.
  56. /// </summary>
  57. /// <param name="trackableId">The <see cref="TrackableId"/> of the trackable which was hit.</param>
  58. /// <param name="pose">The session-space <c>Pose</c> of the intersection.</param>
  59. /// <param name="distance">The session-space distance from the raycast origin to the intersection point.</param>
  60. /// <param name="hitType">The type(s) of trackables which were hit by the ray.</param>
  61. public XRRaycastHit(
  62. TrackableId trackableId,
  63. Pose pose,
  64. float distance,
  65. TrackableType hitType)
  66. {
  67. m_TrackableId = trackableId;
  68. m_Pose = pose;
  69. m_Distance = distance;
  70. m_HitType = hitType;
  71. }
  72. public override int GetHashCode()
  73. {
  74. unchecked
  75. {
  76. var hash = m_TrackableId.GetHashCode();
  77. hash = hash * 486187739 + m_Pose.GetHashCode();
  78. hash = hash * 486187739 + m_Distance.GetHashCode();
  79. hash = hash * 486187739 + ((int)m_HitType).GetHashCode();
  80. return hash;
  81. }
  82. }
  83. public override bool Equals(object obj)
  84. {
  85. if (!(obj is XRRaycastHit))
  86. return false;
  87. return Equals((XRRaycastHit)obj);
  88. }
  89. public bool Equals(XRRaycastHit other)
  90. {
  91. return
  92. (m_TrackableId.Equals(other.m_TrackableId)) &&
  93. (m_Pose.Equals(other.m_Pose)) &&
  94. (m_Distance.Equals(other.m_Distance)) &&
  95. (m_HitType == other.m_HitType);
  96. }
  97. public static bool operator ==(XRRaycastHit lhs, XRRaycastHit rhs) { return lhs.Equals(rhs); }
  98. public static bool operator !=(XRRaycastHit lhs, XRRaycastHit rhs) { return !lhs.Equals(rhs); }
  99. TrackableId m_TrackableId;
  100. Pose m_Pose;
  101. float m_Distance;
  102. TrackableType m_HitType;
  103. }
  104. }