RotateOnAxes_MRCalib.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Rotates the object along its axes consistently.
  6. /// Because its using local axes, it affects the angle of other axes going forward, resulting in wild
  7. /// but possibly desired behavior if multiple axes are rotating at once.
  8. /// Used in the ZED Dark Room example scene to rotate lights.
  9. /// </summary><remarks>
  10. /// This is an exact copy of RotateOnAxes from the Dark Room sample, created so that the
  11. /// Mixed Reality Calibration scene doesn't depend on the user importing the Dark Room sample.
  12. /// </remarks>
  13. public class RotateOnAxes_MRCalib : MonoBehaviour
  14. {
  15. /// <summary>
  16. /// How far it spins on the X axis (pitch) per frame.
  17. /// </summary>
  18. [Tooltip("How far it spins on the X axis (pitch) per frame. ")]
  19. public float xRevolutionsPerSecond = 0;
  20. /// <summary>
  21. /// How far it spins on the Y axis (yaw) per frame.
  22. /// </summary>
  23. [Tooltip("How far it spins on the Y axis (yaw) per frame. ")]
  24. public float yRevolutionsPerSecond = 0.25f;
  25. /// <summary>
  26. /// How far it spins on the Z axis (roll) per frame.
  27. /// </summary>
  28. [Tooltip("How far it spins on the Z axis (roll) per frame. ")]
  29. public float zRevolutionsPerSecond = 0;
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. //Rotate on the axes. Note that the order this occurs is important as each rotation changes transform.localRotation.
  34. transform.Rotate(transform.localRotation * Vector3.right, xRevolutionsPerSecond * 360 * Time.deltaTime); //Pitch
  35. transform.Rotate(transform.localRotation * Vector3.up, yRevolutionsPerSecond * 360 * Time.deltaTime); //Yaw
  36. transform.Rotate(transform.localRotation * Vector3.forward, zRevolutionsPerSecond * 360 * Time.deltaTime); //Roll
  37. }
  38. }