VAUSoundReceiverTracking.cs 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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
using UnityEngine;
using System.Linq;
using System.Collections;
using VA;


public class VAUSoundReceiverTracking : MonoBehaviour
{    
    [Tooltip("Set the corresponding receiver that should be updated")]
    public VAUSoundReceiver Receiver = null;

    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

		VAUAdapter.VA.SetSoundReceiverRealWorldHeadPose(Receiver.ID, v3PosOpenGL, qOrientOpenGL );
		Debug.Log( "performed update, new q:" + p + q );
    }

    private void OnDestroy()
    {
    }
}