VAUSoundReceiverTracking.cs 1.43 KB
Newer Older
1 2 3 4 5 6 7 8
using UnityEngine;
using System.Linq;
using System.Collections;
using VA;


public class VAUSoundReceiverTracking : MonoBehaviour
{    
9 10 11 12 13 14 15 16 17 18
	[Tooltip("Set the corresponding receiver that should be updated")]
	public VAUSoundReceiver Receiver = null;

	[Tooltip("Updates position of user")]
	public bool PositionTracking = true;

	[Tooltip("Updates orientation of user")]
	public bool OrientationTracking = true;


19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

    void Start()
    {
        if( Receiver && Receiver.ID > 0 )
			SetSoundReceiverRealWorldHeadPose();
    }

    void OnEnable()
    {
    }

    void Update()
    {
        if( Receiver && Receiver.ID > 0 )
			SetSoundReceiverRealWorldHeadPose();
    }

	protected void SetSoundReceiverRealWorldHeadPose()
    {
		Vector3 p = GetComponent<Transform>().transform.position; // Unity coordinate system
        VAVec3 v3PosOpenGL = new VAVec3(p.x, p.y, -p.z); // OpenGL coordinate system

		Quaternion q = GetComponent<Transform>().transform.rotation; // Unity coordinate system
		VAQuat qOrientOpenGL = new VAQuat( q.x, q.y, -q.z, q.w ); // OpenGL coordinate system

44 45 46 47 48 49 50 51 52 53
		if( !PositionTracking )
		{
			v3PosOpenGL = VAUAdapter.VA.GetSoundReceiverRealWorldPosition (Receiver.ID);
		}
		if( !OrientationTracking )
		{
			qOrientOpenGL = VAUAdapter.VA.GetSoundReceiverRealWorldOrientation (Receiver.ID);
		}

		VAUAdapter.VA.SetSoundReceiverRealWorldHeadPose (Receiver.ID, v3PosOpenGL, qOrientOpenGL);
54 55 56 57 58 59
    }

    private void OnDestroy()
    {
    }
}