OVRPose.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public struct OVRPose
  5. {
  6. public static OVRPose identity
  7. {
  8. get
  9. {
  10. return new OVRPose
  11. {
  12. position = Vector3.zero,
  13. orientation = Quaternion.identity
  14. };
  15. }
  16. }
  17. public override bool Equals(object obj)
  18. {
  19. return obj is OVRPose && this == (OVRPose)obj;
  20. }
  21. public override int GetHashCode()
  22. {
  23. return this.position.GetHashCode() ^ this.orientation.GetHashCode();
  24. }
  25. public static bool operator ==(OVRPose x, OVRPose y)
  26. {
  27. return x.position == y.position && x.orientation == y.orientation;
  28. }
  29. public static bool operator !=(OVRPose x, OVRPose y)
  30. {
  31. return !(x == y);
  32. }
  33. public static OVRPose operator *(OVRPose lhs, OVRPose rhs)
  34. {
  35. return new OVRPose
  36. {
  37. position = lhs.position + lhs.orientation * rhs.position,
  38. orientation = lhs.orientation * rhs.orientation
  39. };
  40. }
  41. public OVRPose Inverse()
  42. {
  43. OVRPose result;
  44. result.orientation = Quaternion.Inverse(this.orientation);
  45. result.position = result.orientation * -this.position;
  46. return result;
  47. }
  48. internal OVRPose flipZ()
  49. {
  50. OVRPose result = this;
  51. result.position.z = -result.position.z;
  52. result.orientation.z = -result.orientation.z;
  53. result.orientation.w = -result.orientation.w;
  54. return result;
  55. }
  56. internal OVRPlugin.Posef ToPosef()
  57. {
  58. return new OVRPlugin.Posef
  59. {
  60. Position = this.position.ToVector3f(),
  61. Orientation = this.orientation.ToQuatf()
  62. };
  63. }
  64. public Vector3 position;
  65. public Quaternion orientation;
  66. }