cAudio  2.3.0
3d Audio Engine
cListener.cpp
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #include "cListener.h"
6 #include "cEFXFunctions.h"
7 #include "cOpenALUtil.h"
8 
9 namespace cAudio
10 {
12  {
13  cAudioMutexBasicLock lock(Mutex);
14  Position = pos;
15  alListener3f(AL_POSITION, Position.x, Position.y, Position.z);
16  checkALError();
17  }
19  {
20  cAudioMutexBasicLock lock(Mutex);
21  Direction = dir;
22  float orient[6] = {Direction[0], Direction[1], Direction[2], UpVector[0], UpVector[1], UpVector[2]};
23  alListenerfv(AL_ORIENTATION, orient);
24  checkALError();
25  }
27  {
28  cAudioMutexBasicLock lock(Mutex);
29  UpVector = up;
30  float orient[6] = {Direction[0], Direction[1], Direction[2], UpVector[0], UpVector[1], UpVector[2]};
31  alListenerfv(AL_ORIENTATION, orient);
32  checkALError();
33  }
35  {
36  cAudioMutexBasicLock lock(Mutex);
37  Velocity = vel;
38  alListener3f(AL_VELOCITY, Velocity.x, Velocity.y, Velocity.z);
39  checkALError();
40  }
41  void cListener::setMasterVolume(const float& volume)
42  {
43  cAudioMutexBasicLock lock(Mutex);
44  MasterGain = volume;
45  alListenerf(AL_GAIN, MasterGain);
46  checkALError();
47  }
48  void cListener::move(const cVector3& pos)
49  {
50  cAudioMutexBasicLock lock(Mutex);
51  Velocity = pos - Position;
52  Position = pos;
53 
54  alListener3f(AL_POSITION, Position.x, Position.y, Position.z);
55  alListener3f(AL_VELOCITY, Velocity.x, Velocity.y, Velocity.z);
56  checkALError();
57  }
58 #if CAUDIO_EFX_ENABLED == 1
59  void cListener::setMetersPerUnit(const float& meters)
60  {
61  cAudioMutexBasicLock lock(Mutex);
62  alListenerf(AL_METERS_PER_UNIT, meters);
63  checkALError();
64  }
65 
66  float cListener::getMetersPerUnit(void) const
67  {
68  float value = 1.0f;
69  alGetListenerf(AL_METERS_PER_UNIT, &value);
70  return value;
71  }
72 #endif
73 };
virtual void setPosition(const cVector3 &pos)
Sets the position of the listener.
Definition: cListener.cpp:11
virtual void move(const cVector3 &pos)
Convenience function to automatically set the velocity and position for you in a single call.
Definition: cListener.cpp:48
virtual void setDirection(const cVector3 &dir)
Sets the direction the listener is facing.
Definition: cListener.cpp:18
virtual void setVelocity(const cVector3 &vel)
Sets the current velocity of the listener for doppler effects.
Definition: cListener.cpp:34
Class for manipulating vectors in 3D space.
Definition: cVector3.h:22
virtual void setMasterVolume(const float &volume)
Sets the global volume modifier (will effect all sources)
Definition: cListener.cpp:41
virtual void setUpVector(const cVector3 &up)
Sets the up vector to use for the listener.
Definition: cListener.cpp:26
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15