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.

111 lines
4.0 KiB

  1. // HyperealVR Boundaries|SDK_HyperealVR|005
  2. namespace VRTK
  3. {
  4. #if VRTK_DEFINE_SDK_HYPEREALVR
  5. using UnityEngine;
  6. using Hypereal;
  7. #endif
  8. /// <summary>
  9. /// The HyperealVR Boundaries SDK script provides a bridge to the HyperealVR SDK play area.
  10. /// </summary>
  11. [SDK_Description(typeof(SDK_HyperealVRSystem))]
  12. public class SDK_HyperealVRBoundaries
  13. #if VRTK_DEFINE_SDK_HYPEREALVR
  14. : SDK_BaseBoundaries
  15. #else
  16. : SDK_FallbackBoundaries
  17. #endif
  18. {
  19. #if VRTK_DEFINE_SDK_HYPEREALVR
  20. protected HyRender cachedHyperealVRPlayArea;
  21. private const float thickness = 0.1f;
  22. /// <summary>
  23. /// The InitBoundaries method is run on start of scene and can be used to initialse anything on game start.
  24. /// </summary>
  25. public override void InitBoundaries()
  26. {
  27. }
  28. /// <summary>
  29. /// The GetPlayArea method returns the Transform of the object that is used to represent the play area in the scene.
  30. /// </summary>
  31. /// <returns>A transform of the object representing the play area in the scene.</returns>
  32. public override Transform GetPlayArea()
  33. {
  34. cachedPlayArea = GetSDKManagerPlayArea();
  35. if (cachedPlayArea == null)
  36. {
  37. GameObject myHeadGO = VRTK_SharedMethods.FindEvenInactiveGameObject<HyHead>(null, true);
  38. cachedPlayArea = (myHeadGO != null ? myHeadGO.transform.parent : null);
  39. }
  40. return cachedPlayArea;
  41. }
  42. /// <summary>
  43. /// The GetPlayAreaVertices method returns the points of the play area boundaries.
  44. /// </summary>
  45. /// <returns>A Vector3 array of the points in the scene that represent the play area boundaries.</returns>
  46. public override Vector3[] GetPlayAreaVertices()
  47. {
  48. int count = 0;
  49. HyperealApi.GetPlayAreaVertexCount(ref count);
  50. if (count > 0)
  51. {
  52. float outer = 1f;
  53. float inner = outer - thickness;
  54. Vector3[] vertices = new Vector3[8];
  55. vertices[0] = new Vector3(inner, 0f, -inner);
  56. vertices[1] = new Vector3(-inner, 0f, -inner);
  57. vertices[2] = new Vector3(-inner, 0f, inner);
  58. vertices[3] = new Vector3(inner, 0f, inner);
  59. vertices[4] = new Vector3(outer, 0f, -outer);
  60. vertices[5] = new Vector3(-outer, 0f, -outer);
  61. vertices[6] = new Vector3(-outer, 0f, outer);
  62. vertices[7] = new Vector3(outer, 0f, outer);
  63. return vertices;
  64. }
  65. return null;
  66. }
  67. /// <summary>
  68. /// The GetPlayAreaBorderThickness returns the thickness of the drawn border for the given play area.
  69. /// </summary>
  70. /// <returns>The thickness of the drawn border.</returns>
  71. public override float GetPlayAreaBorderThickness()
  72. {
  73. return thickness;
  74. }
  75. /// <summary>
  76. /// The IsPlayAreaSizeCalibrated method returns whether the given play area size has been auto calibrated by external sensors.
  77. /// </summary>
  78. /// <returns>Returns true if the play area size has been auto calibrated and set by external sensors.</returns>
  79. public override bool IsPlayAreaSizeCalibrated()
  80. {
  81. return true;
  82. }
  83. /// <summary>
  84. /// The GetDrawAtRuntime method returns whether the given play area drawn border is being displayed.
  85. /// </summary>
  86. /// <returns>Returns true if the drawn border is being displayed.</returns>
  87. public override bool GetDrawAtRuntime()
  88. {
  89. return false;
  90. }
  91. /// <summary>
  92. /// The SetDrawAtRuntime method sets whether the given play area drawn border should be displayed at runtime.
  93. /// </summary>
  94. /// <param name="value">The state of whether the drawn border should be displayed or not.</param>
  95. public override void SetDrawAtRuntime(bool value)
  96. {
  97. }
  98. #endif
  99. }
  100. }