Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Listener.cpp
Go to the documentation of this file.
1 //
2 // C++ Implementation: Audio::Source
3 //
4 
5 #include "Listener.h"
6 #include "config.h"
7 
8 #include <math.h>
9 
10 namespace Audio {
11 
12  Listener::Listener() throw() :
13  cosAngleRange(-1,-1),
14  position(0,0,0),
15  atDirection(0,0,-1),
16  upDirection(0,1,0),
17  velocity(0,0,0),
18  radius(1),
19  gain(1),
20  worldToLocal(1) // set to identity, given default settings
21  {
22  }
23 
25  {
26  }
27 
29  {
30  return Range<Scalar>(Scalar(acos(cosAngleRange.min)),
31  Scalar(acos(cosAngleRange.max)));
32  }
33 
35  {
36  cosAngleRange.min = Scalar(cos(r.min));
37  cosAngleRange.max = Scalar(cos(r.max));
38  dirty.attributes = 1;
39  }
40 
41  void Listener::update(int flags) throw()
42  {
43  if (!dirty.attributes)
44  flags &= ~RenderableListener::UPDATE_ATTRIBUTES;
45  if (!dirty.location)
46  flags &= ~RenderableListener::UPDATE_LOCATION;
47  if (!dirty.gain)
48  flags &= ~RenderableListener::UPDATE_GAIN;
49 
50  if (getRenderable().get() != 0)
51  getRenderable()->update(flags);
52 
54  dirty.attributes = 0;
56  dirty.gain = 0;
58  worldToLocal =
59  Matrix3(
60  atDirection.cross(upDirection),
61  upDirection,
62  -atDirection
63  ).inverse();
64  dirty.location = 0;
65  }
66  }
67 
69  {
70  return worldToLocal * dir;
71  }
72 
73 };