1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System.Collections;
- using System.Collections.Generic;
- using NRKernal;
- using UnityEngine;
- public class followrotation : MonoBehaviour
- {
- public GameObject Reboot;
- public float bfloatx;
- public int nowindex;
- public GameObject head;
- public List<GameObject> endList;
- bool isa;
- bool isp;
- public GameObject fgo;
- private void Start()
- {
- // fgo = Reboot;
- nowindex = endList.Count-1;
- yidong();
- }
- public void yidong()
- {
- // return;
- if(endList.Count> nowindex)
- {
- Vector3 v3 = endList[nowindex].transform.position - OpenXRCamera.Instance.head.transform.localPosition;
- head.transform.position = new Vector3(v3.x, OpenXRCamera.Instance.head.transform.position.y, v3.z);
- }
- nowindex++;
- isa = false;
- isp = false;
- // Debug.Log("yidong===");
- }
- // Update is called once per frame
- void Update()
- {
- if(Input.GetKeyDown(KeyCode.O))
- {
- yidong();
- }
- // Pose poseInAPIWorld = new Pose(NRInput.GetPosition(ControllerHandEnum.Right), NRInput.GetRotation(ControllerHandEnum.Right));
- // Pose pose = ApplyWorldMatrix(poseInAPIWorld);
- // transform.position = Vector3.zero;// NRInput.CameraCenter.TransformPoint(m_DefaultLocalOffset);
- // transform.rotation = pose.rotation;
- this.transform.localEulerAngles = fgo.transform.localEulerAngles;
- float xx = this.transform.localEulerAngles.x;
- if (this.transform.localEulerAngles.x>180)
- {
- xx= this.transform.localEulerAngles.x - 360f ;
- }
- if(!isa)
- {
- if((xx) > 10)
- {
- isa = true;
- bfloatx = xx;
- }
- // Debug.Log("yidong==1="+ (xx));
- }
- if(!isp&& isa)
- {
- if ((bfloatx-20)> (xx))
- {
- isa = false;
- yidong();
- }
- // Debug.Log((xx) +"=====yidong==2=" + (bfloatx - 40));
- }
- }
- private Matrix4x4 m_CachedWorldMatrix = Matrix4x4.identity;
- /// <summary> Apply world transform. </summary>
- private Pose ApplyWorldMatrix(Pose pose)
- {
- var objectMatrix = ConversionUtility.GetTMatrix(pose.position, pose.rotation);
- var object_in_world = m_CachedWorldMatrix * objectMatrix;
- return new Pose(ConversionUtility.GetPositionFromTMatrix(object_in_world),
- ConversionUtility.GetRotationFromTMatrix(object_in_world));
- }
- }
|