1 module armos.audio.listener;
2 
3 import derelict.openal.al;
4 import armos.math;
5 
6 /++
7 +/
8 class Listener {
9     public{
10         ///
11         Listener position(V)(in V p)if(isVector!(V) && V.dimention >= 3){
12             alListener3f(AL_POSITION, V[0], V[1], V[2]);
13             _position[3] = 1f;
14             foreach (int i, e; p.elements) {
15                 _position[i] = e;
16             }
17             return this;
18         }
19         
20         ///
21         Listener velocity (V)(in V v)if(isVector!(V) && V.dimention >= 3){
22             alListener3f(AL_VELOCITY, V[0], V[1], V[2]);
23             _velocity[3] = 0f;
24             foreach (int i, e; v.elements) {
25                 _velocity[i] = e;
26             }
27             return this;
28         }
29         
30         ///
31         Listener at(V)(in V v)if(isVector!(V) && V.dimention >= 3){
32             ALfloat[6] orientation = [v[0],  v[1],  v[2],
33                                       up[0], up[1], up[2]];
34             alListenerfv(AL_ORIENTATION, orientation.ptr);
35             _at[3] = 0f;
36             foreach (int i, e; v.elements) {
37                 _at[i] = e;
38             }
39             return this;
40         }
41         
42         ///
43         Listener up(V)(in V v)if(isVector!(V) && V.dimention >= 3){
44             ALfloat[6] orientation = [at[0], at[1], at[2],
45                                       v[0],  v[1],  v[2]];
46             alListenerfv(AL_ORIENTATION, orientation.ptr);
47             _up[3] = 0f;
48             foreach (int i, e; v.elements) {
49                 _up[i] = e;
50             }
51             return this;
52         }
53         
54         /// 
55         Vector4f position()const{
56             return _position;
57         }
58         
59         /// 
60         Vector4f velocity()const{
61             return _velocity;
62         }
63         
64         /// 
65         Vector4f at()const{
66             return _at;
67         }
68         
69         /// 
70         Vector4f up()const{
71             return _up;
72         }
73         
74         ///
75         Listener gain(in float g){
76             alListenerf(AL_GAIN, g);
77             _gain = g;
78             return this;
79         }
80         
81         ///
82         float gain(){return _gain;}
83     }//public
84 
85     private{
86         Vector4f _position = Vector4f(0, 0, 0, 1); 
87         Vector4f _velocity = Vector4f(0, 0, 0, 0); ;
88         Vector4f _at = Vector4f(0, 0, -1, 0);
89         Vector4f _up = Vector4f(0, 1, 0, 0);
90         float _gain = 1f;
91     }//private
92 }//class Listener