followrotation.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NRKernal;
  4. using UnityEngine;
  5. public class followrotation : MonoBehaviour
  6. {
  7. public GameObject Reboot;
  8. public float bfloatx;
  9. public int nowindex;
  10. public GameObject head;
  11. public List<GameObject> endList;
  12. bool isa;
  13. bool isp;
  14. public GameObject fgo;
  15. private void Start()
  16. {
  17. // fgo = Reboot;
  18. nowindex = endList.Count-1;
  19. yidong();
  20. }
  21. public void yidong()
  22. {
  23. // return;
  24. if(endList.Count> nowindex)
  25. {
  26. Vector3 v3 = endList[nowindex].transform.position - OpenXRCamera.Instance.head.transform.localPosition;
  27. head.transform.position = new Vector3(v3.x, OpenXRCamera.Instance.head.transform.position.y, v3.z);
  28. }
  29. nowindex++;
  30. isa = false;
  31. isp = false;
  32. // Debug.Log("yidong===");
  33. }
  34. // Update is called once per frame
  35. void Update()
  36. {
  37. if(Input.GetKeyDown(KeyCode.O))
  38. {
  39. yidong();
  40. }
  41. // Pose poseInAPIWorld = new Pose(NRInput.GetPosition(ControllerHandEnum.Right), NRInput.GetRotation(ControllerHandEnum.Right));
  42. // Pose pose = ApplyWorldMatrix(poseInAPIWorld);
  43. // transform.position = Vector3.zero;// NRInput.CameraCenter.TransformPoint(m_DefaultLocalOffset);
  44. // transform.rotation = pose.rotation;
  45. this.transform.localEulerAngles = fgo.transform.localEulerAngles;
  46. float xx = this.transform.localEulerAngles.x;
  47. if (this.transform.localEulerAngles.x>180)
  48. {
  49. xx= this.transform.localEulerAngles.x - 360f ;
  50. }
  51. if(!isa)
  52. {
  53. if((xx) > 10)
  54. {
  55. isa = true;
  56. bfloatx = xx;
  57. }
  58. // Debug.Log("yidong==1="+ (xx));
  59. }
  60. if(!isp&& isa)
  61. {
  62. if ((bfloatx-20)> (xx))
  63. {
  64. isa = false;
  65. yidong();
  66. }
  67. // Debug.Log((xx) +"=====yidong==2=" + (bfloatx - 40));
  68. }
  69. }
  70. private Matrix4x4 m_CachedWorldMatrix = Matrix4x4.identity;
  71. /// <summary> Apply world transform. </summary>
  72. private Pose ApplyWorldMatrix(Pose pose)
  73. {
  74. var objectMatrix = ConversionUtility.GetTMatrix(pose.position, pose.rotation);
  75. var object_in_world = m_CachedWorldMatrix * objectMatrix;
  76. return new Pose(ConversionUtility.GetPositionFromTMatrix(object_in_world),
  77. ConversionUtility.GetRotationFromTMatrix(object_in_world));
  78. }
  79. }