VAUListener.cs 1.48 KB
Newer Older
1 2 3 4 5 6 7 8
using UnityEngine;
using System;
using System.Collections;
using VA;


public class VAUListener : MonoBehaviour {

9 10 11 12
    public string listenername = "MyListener";
    public int auramode = 123;
    private int Listener;
    private VANet _VA = null;
13 14 15 16
    private Vector3 viewvec;
    private Vector3 upvec;
    private Quaternion q;
    private Transform t;
17 18 19
    // Use this for initialization
    void Start()
    {
20 21 22
        upvec.Set(0, 1, 0);
        viewvec.Set(0, 0, 1);
        
23 24
        _VA = VAUAdapter.VA;
        Listener = _VA.CreateListener(listenername, auramode, VAUAdapter.DefaultHRIR);
25
        _VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR);
26 27 28 29 30
    }
	
	// Update is called once per frame
	void Update ()
    {
31 32 33 34 35 36 37
        t = GetComponent<Transform>();
        q = t.rotation;
        Vector3 up = q * upvec;
        Vector3 view = q * viewvec;
        Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
        Vector3 up_ogl = new Vector3(up.x, up.y, -up.z);

38
        _VA.SetListenerPosition(Listener, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
39 40 41 42 43
        _VA.SetListenerOrientationVU(Listener, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
        //Quaternion q_ogl = new Quaternion(q.x, q.y, -q.z, -q.w);
        //Vector3 t1 = new Vector3(0, 0, 1);
        //Vector3 t1_ogl = ( q_ogl * t1 ); // result: 0 0 -1
       // Debug.Log(t1_ogl);
44 45
    }

46
  
47 48 49 50
    //void OnDestroy()
    //{
    //    _VA.DeleteListener(Listener);
    //}
51

52 53

}