12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using NRKernal;
- using UnityEngine;
- public class FolloHand : MonoBehaviour
- {
- public GameObject righthand;
- private void Start()
- {
- NRInput.Hands.OnHandStatesUpdated += OnHandStatesUpdated;
- }
- private void OnHandStatesUpdated()
- {
- var handState = NRInput.Hands.GetHandState(HandEnum.RightHand);
- if (handState != null && handState.isTracked)
- {
- foreach (var jointID in handState.jointsPoseDict.Keys)
- {
- if(jointID==HandJointID.Palm)
- {
- if(righthand==null)
- righthand = CreateJointObj(jointID);
- righthand.transform.position = handState.jointsPoseDict[jointID].position;
- righthand.transform.eulerAngles =new Vector3( handState.jointsPoseDict[jointID].rotation.eulerAngles.z+180, handState.jointsPoseDict[jointID].rotation.eulerAngles.y-100, handState.jointsPoseDict[jointID].rotation.eulerAngles.x);
- }
-
- }
- }
- else
- {
- }
- }
- private GameObject CreateJointObj(HandJointID handJointID)
- {
- return new GameObject();
- }
- // Update is called once per frame
- void Update()
- {
- if(righthand!=null)
- {
- this.transform.localPosition = OpenXRCamera.Instance.head.InverseTransformPoint(righthand.transform.position);
- this.transform.localEulerAngles = righthand.transform.eulerAngles-new Vector3(0,OpenXRCamera.Instance.head.eulerAngles.y,0);
- }
- }
- }
|