Skip to content

Instantly share code, notes, and snippets.

@Kailang
Last active February 10, 2018 04:18
Show Gist options
  • Save Kailang/366e45d2ddf835087638176858877593 to your computer and use it in GitHub Desktop.
Save Kailang/366e45d2ddf835087638176858877593 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class TestK : MonoBehaviour {
public Transform headTrans, lHandTrans, rHandTrans;
void OnDrawGizmosSelected() {
if (OVRManager.tracker == null) return;
OVRPose tracker = OVRManager.tracker.GetPose();
var trackerAnchorLocalPosition = tracker.position;
var trackerAnchorLocalRotation = tracker.orientation;
DrawAnchor (trackerAnchorLocalPosition, trackerAnchorLocalRotation);
var centerEyeAnchorLocalPosition = InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye);
var centerEyeAnchorLocalRotation = InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye);
DrawAnchor (centerEyeAnchorLocalPosition, centerEyeAnchorLocalRotation);
headTrans.localPosition = centerEyeAnchorLocalPosition;
headTrans.localRotation = centerEyeAnchorLocalRotation;
var leftEyeAnchorLocalPosition = InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.LeftEye);
var leftEyeAnchorLocalRotation = InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.LeftEye);
var rightEyeAnchorLocalPosition = InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.RightEye);
var rightEyeAnchorLocalRotation = InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.RightEye);
var leftHandAnchorLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
var leftHandAnchorLocalRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
DrawAnchor (leftHandAnchorLocalPosition, leftHandAnchorLocalRotation);
lHandTrans.localPosition = leftHandAnchorLocalPosition;
lHandTrans.localRotation = leftHandAnchorLocalRotation;
var leftHandIndexTriggerTouch = OVRInput.Get(OVRInput.RawTouch.LIndexTrigger
var rightHandAnchorLocalPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
var rightHandAnchorLocalRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
DrawAnchor (rightHandAnchorLocalPosition, rightHandAnchorLocalRotation);
rHandTrans.localPosition = rightHandAnchorLocalPosition;
rHandTrans.localRotation = rightHandAnchorLocalRotation;
}
void DrawAnchor(Vector3 position, Quaternion rotation) {
Gizmos.color = Color.green;
Gizmos.DrawWireSphere (position, 0.1f);
Gizmos.color = Color.red;
Gizmos.DrawRay (position, rotation * Vector3.forward * 0.5f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment