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.

135 lines
5.5 KiB

  1. // Daydream Headset|SDK_Daydream|003
  2. namespace VRTK
  3. {
  4. #if VRTK_DEFINE_SDK_DAYDREAM
  5. using UnityEngine;
  6. using System.Collections.Generic;
  7. #endif
  8. /// <summary>
  9. /// The Daydream Headset SDK script provides dummy functions for the headset.
  10. /// </summary>
  11. [SDK_Description(typeof(SDK_DaydreamSystem))]
  12. public class SDK_DaydreamHeadset
  13. #if VRTK_DEFINE_SDK_DAYDREAM
  14. : SDK_BaseHeadset
  15. #else
  16. : SDK_FallbackHeadset
  17. #endif
  18. {
  19. #if VRTK_DEFINE_SDK_DAYDREAM
  20. private Quaternion previousHeadsetRotation;
  21. private Quaternion currentHeadsetRotation;
  22. /// <summary>
  23. /// The ProcessUpdate method enables an SDK to run logic for every Unity Update
  24. /// </summary>
  25. /// <param name="options">A dictionary of generic options that can be used to within the update.</param>
  26. public override void ProcessUpdate(Dictionary<string, object> options)
  27. {
  28. var device = GetHeadset();
  29. previousHeadsetRotation = currentHeadsetRotation;
  30. currentHeadsetRotation = device.transform.rotation;
  31. }
  32. /// <summary>
  33. /// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
  34. /// </summary>
  35. /// <param name="options">A dictionary of generic options that can be used to within the fixed update.</param>
  36. public override void ProcessFixedUpdate(Dictionary<string, object> options)
  37. {
  38. }
  39. /// <summary>
  40. /// The GetHeadset method returns the Transform of the object that is used to represent the headset in the scene.
  41. /// </summary>
  42. /// <returns>A transform of the object representing the headset in the scene.</returns>
  43. public override Transform GetHeadset()
  44. {
  45. cachedHeadset = GetSDKManagerHeadset();
  46. if (cachedHeadset == null)
  47. {
  48. var foundCamera = Camera.main; //assume native support
  49. if (foundCamera)
  50. {
  51. cachedHeadset = foundCamera.transform;
  52. }
  53. }
  54. return cachedHeadset;
  55. }
  56. /// <summary>
  57. /// The GetHeadsetCamera/0 method returns the Transform of the object that is used to hold the headset camera in the scene.
  58. /// </summary>
  59. /// <returns>A transform of the object holding the headset camera in the scene.</returns>
  60. public override Transform GetHeadsetCamera()
  61. {
  62. return Camera.main.transform; //assume native support
  63. }
  64. /// <summary>
  65. /// The GetHeadsetType method returns a string representing the type of headset connected.
  66. /// </summary>
  67. /// <returns>The string of the headset connected.</returns>
  68. public override string GetHeadsetType()
  69. {
  70. return CleanPropertyString("googledaydream");
  71. }
  72. /// <summary>
  73. /// The GetHeadsetVelocity method is used to determine the current velocity of the headset.
  74. /// </summary>
  75. /// <returns>A Vector3 containing the current velocity of the headset.</returns>
  76. public override Vector3 GetHeadsetVelocity()
  77. {
  78. return Vector3.zero; //has no positional tracking
  79. }
  80. /// <summary>
  81. /// The GetHeadsetAngularVelocity method is used to determine the current angular velocity of the headset.
  82. /// </summary>
  83. /// <returns>A Vector3 containing the current angular velocity of the headset.</returns>
  84. public override Vector3 GetHeadsetAngularVelocity()
  85. {
  86. var deltaRotation = currentHeadsetRotation * Quaternion.Inverse(previousHeadsetRotation);
  87. return new Vector3(Mathf.DeltaAngle(0, deltaRotation.eulerAngles.x), Mathf.DeltaAngle(0, deltaRotation.eulerAngles.y), Mathf.DeltaAngle(0, deltaRotation.eulerAngles.z));
  88. }
  89. /// <summary>
  90. /// The HeadsetFade method is used to apply a fade to the headset camera to progressively change the colour.
  91. /// </summary>
  92. /// <param name="color">The colour to fade to.</param>
  93. /// <param name="duration">The amount of time the fade should take to reach the given colour.</param>
  94. /// <param name="fadeOverlay">Determines whether to use an overlay on the fade.</param>
  95. public override void HeadsetFade(Color color, float duration, bool fadeOverlay = false)
  96. {
  97. VRTK_ScreenFade.Start(color, duration);
  98. }
  99. /// <summary>
  100. /// The HasHeadsetFade method checks to see if the given game object (usually the camera) has the ability to fade the viewpoint.
  101. /// </summary>
  102. /// <param name="obj">The Transform to check to see if a camera fade is available on.</param>
  103. /// <returns>Returns true if the headset has fade functionality on it.</returns>
  104. public override bool HasHeadsetFade(Transform obj)
  105. {
  106. if (obj.GetComponentInChildren<VRTK_ScreenFade>())
  107. {
  108. return true;
  109. }
  110. return false;
  111. }
  112. /// <summary>
  113. /// The AddHeadsetFade method attempts to add the fade functionality to the game object with the camera on it.
  114. /// </summary>
  115. /// <param name="camera">The Transform to with the camera on to add the fade functionality to.</param>
  116. public override void AddHeadsetFade(Transform camera)
  117. {
  118. if (camera && !camera.GetComponent<VRTK_ScreenFade>())
  119. {
  120. camera.gameObject.AddComponent<VRTK_ScreenFade>();
  121. }
  122. }
  123. #endif
  124. }
  125. }