Assignment for RMIT Mixed Reality in 2020
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.

147 lines
5.2 KiB

  1. // WindowsMR Boundaries|SDK_WindowsMR|005
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. #if UNITY_2017_2_OR_NEWER
  7. using UnityEngine.XR;
  8. using UnityEngine.Experimental.XR;
  9. #if VRTK_DEFINE_SDK_WINDOWSMR
  10. using UnityEngine.XR.WSA;
  11. #endif
  12. #else
  13. using UnityEngine.VR;
  14. using XRDevice = UnityEngine.VR.VRDevice;
  15. #endif
  16. /// <summary>
  17. /// The WindowsMR Boundaries SDK script provides a bridge to the Windows Mixed Reality SDK play area.
  18. /// </summary>
  19. [SDK_Description(typeof(SDK_WindowsMR))]
  20. public class SDK_WindowsMRBoundaries
  21. #if VRTK_DEFINE_SDK_WINDOWSMR && UNITY_2017_2_OR_NEWER
  22. : SDK_BaseBoundaries
  23. #else
  24. : SDK_FallbackBoundaries
  25. #endif
  26. {
  27. #if VRTK_DEFINE_SDK_WINDOWSMR && UNITY_2017_2_OR_NEWER
  28. /// <summary>
  29. /// The GetDrawAtRuntime method returns whether the given play area drawn border is being displayed.
  30. /// </summary>
  31. /// <returns>Returns true if the drawn border is being displayed.</returns>
  32. public override bool GetDrawAtRuntime()
  33. {
  34. // TODO: Implement
  35. return false;
  36. }
  37. /// <summary>
  38. /// The GetPlayArea method returns the Transform of the object that is used to represent the play area in the scene.
  39. /// </summary>
  40. /// <returns>A transform of the object representing the play area in the scene.</returns>
  41. public override Transform GetPlayArea()
  42. {
  43. if (cachedPlayArea == null)
  44. {
  45. Transform headsetCamera = VRTK_DeviceFinder.HeadsetCamera();
  46. if (headsetCamera != null)
  47. {
  48. cachedPlayArea = headsetCamera.transform;
  49. }
  50. }
  51. if (cachedPlayArea != null && cachedPlayArea.parent != null)
  52. {
  53. cachedPlayArea = cachedPlayArea.parent;
  54. }
  55. return cachedPlayArea;
  56. }
  57. /// <summary>
  58. /// The GetPlayAreaBorderThickness returns the thickness of the drawn border for the given play area.
  59. /// </summary>
  60. /// <returns>The thickness of the drawn border.</returns>
  61. public override float GetPlayAreaBorderThickness()
  62. {
  63. // TODO: Implement - Needed?
  64. return 0.1f;
  65. }
  66. /// <summary>
  67. /// The GetPlayAreaVertices method returns the points of the play area boundaries.
  68. /// </summary>
  69. /// <returns>A Vector3 array of the points in the scene that represent the play area boundaries.</returns>
  70. public override Vector3[] GetPlayAreaVertices()
  71. {
  72. List<Vector3> boundaryGeometry = new List<Vector3>(0);
  73. #if UNITY_2017_2_OR_NEWER
  74. if (Boundary.TryGetGeometry(boundaryGeometry))
  75. {
  76. if (boundaryGeometry.Count > 0)
  77. {
  78. foreach (Vector3 point in boundaryGeometry)
  79. {
  80. return boundaryGeometry.ToArray();
  81. }
  82. }
  83. else
  84. {
  85. Debug.LogWarning("Boundary has no points");
  86. }
  87. }
  88. #endif
  89. return null;
  90. }
  91. /// <summary>
  92. /// The InitBoundaries method is run on start of scene and can be used to initialse anything on game start.
  93. /// </summary>
  94. public override void InitBoundaries()
  95. {
  96. bool isDisplayOpaque = false;
  97. #if UNITY_2017_2_OR_NEWER
  98. isDisplayOpaque = HolographicSettings.IsDisplayOpaque;
  99. #endif
  100. if (isDisplayOpaque)
  101. {
  102. // Defaulting coordinate system to RoomScale in immersive headsets.
  103. // This puts the origin 0,0,0 on the floor if a floor has been established during RunSetup via MixedRealityPortal
  104. XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
  105. }
  106. else
  107. {
  108. // Defaulting coordinate system to Stationary for HoloLens.
  109. // This puts the origin 0,0,0 at the first place where the user started the application.
  110. XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
  111. }
  112. Transform headsetCamera = VRTK_DeviceFinder.HeadsetCamera();
  113. if (headsetCamera != null)
  114. {
  115. cachedPlayArea = headsetCamera.transform;
  116. }
  117. }
  118. /// <summary>
  119. /// The IsPlayAreaSizeCalibrated method returns whether the given play area size has been auto calibrated by external sensors.
  120. /// </summary>
  121. /// <returns>Returns true if the play area size has been auto calibrated and set by external sensors.</returns>
  122. public override bool IsPlayAreaSizeCalibrated()
  123. {
  124. // TODO: Implement
  125. return false;
  126. }
  127. /// <summary>
  128. /// The SetDrawAtRuntime method sets whether the given play area drawn border should be displayed at runtime.
  129. /// </summary>
  130. /// <param name="value">The state of whether the drawn border should be displayed or not.</param>
  131. public override void SetDrawAtRuntime(bool value)
  132. {
  133. // TODO: Implement
  134. }
  135. #endif
  136. }
  137. }