using UnityEngine; using System.Collections; public class Controller_Rotations : MonoBehaviour { Quaternion curr_Rotation_1 = Quaternion.identity; Quaternion curr_Rotation_2 = Quaternion.identity; public GameObject Ctrl; public float rota_Rate_1; public float rota_Rate_2; private float x_Rota; private float y_Rota; private float z_Rota; private HMD_Ctrl_Tracking hmd_Ctrl_Tracking; void Start () { hmd_Ctrl_Tracking = HMD_Ctrl_Tracking.Instance; } void Update () { if (hmd_Ctrl_Tracking.isCtrl_1_Active() && hmd_Ctrl_Tracking.isCtrl_2_Active()) { Quaternion qI = Quaternion.Inverse(HMD_Ctrl_Tracking.Instance.getSteamVR_PlayArea().transform.rotation) * Ctrl.transform.rotation; curr_Rotation_1 = Quaternion.Slerp(curr_Rotation_1, qI, rota_Rate_1 * Time.deltaTime); curr_Rotation_2 = Quaternion.Slerp(curr_Rotation_2, qI, rota_Rate_2 * Time.deltaTime); Quaternion diffQ = Quaternion.Inverse(curr_Rotation_1) * curr_Rotation_2; Vector3 euler = diffQ.eulerAngles; x_Rota = euler.x; y_Rota = euler.y; z_Rota = euler.z; pollish_rota(ref x_Rota); pollish_rota(ref y_Rota); pollish_rota(ref z_Rota); } } private void pollish_rota(ref float rota) { if (rota > 180) { rota = rota - 360; } } public float get_x_Rota() { return x_Rota; } public float get_y_Rota() { return y_Rota; } public float get_z_Rota() { return z_Rota; } }