VAUListener.cs 2.11 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
    public string listenername = "Listener";
10
11
    private int Listener;
    private VANet _VA = null;
12
13
    private Quaternion q;
    private Transform t;
14
15
16
17
18
19
20
21
22

    public int ID
    {
        get
        {
            return Listener;
        }
    }

23
24
25
    // Use this for initialization
    void Start()
    {
26
        _VA = VAUAdapter.VA;
27
        Listener = _VA.CreateListener(listenername, 0, VAUAdapter.DefaultHRIR);
28
        listenername += " " + Listener;
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
29
        _VA.SetListenerAuralizationMode(Listener, "all");
30
        Debug.Log(listenername + " created");
31
        _VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR);
32
        SetListenerPositionOrientation();
33
34
        if (GetComponent<VAUAuralizationMode>() != null)
            GetComponent<VAUAuralizationMode>().AuraStringChanged += OnListenerAuralizationModeChanged;
35
        
36
37
38
39
    }
	
	// Update is called once per frame
	void Update ()
40
41
42
    {
        SetListenerPositionOrientation();
    }
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
43
    //uses the View- and Up-Vector to transmit the position of the listener to VA
44
    void SetListenerPositionOrientation()
45
    {
46
47
        t = GetComponent<Transform>();
        q = t.rotation;
48
49
        Vector3 up = q * Vector3.up;
        Vector3 view = q * Vector3.forward;
50
51
        Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
        Vector3 up_ogl = new Vector3(up.x, up.y, -up.z);
52
        _VA.SetListenerPosition(Listener, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
53
        _VA.SetListenerOrientationVU(Listener, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
54
    }
55
56
57
58
59

    void OnListenerAuralizationModeChanged(string AuraMode)
    {
        _VA.SetListenerAuralizationMode(Listener, AuraMode);
    }
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
60

61
62
63
64
65
    void OnDisable()
    {
        if (GetComponent<VAUAuralizationMode>() != null)
            GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnListenerAuralizationModeChanged;
    }
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
66

Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
67
68
69
70
71
72
73
    void OnDestroy()
    {
        if (_VA.IsConnected())
        {
            _VA.DeleteListener(Listener);
        }
    }
74
}