Listener.cpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
26// Headers
28#include <SFML/Audio/Listener.hpp>
29#include <SFML/Audio/OpenAL.hpp>
30
31
32namespace sf
33{
37void Listener::SetGlobalVolume(float Volume)
38{
39 ALCheck(alListenerf(AL_GAIN, Volume * 0.01f));
40}
41
42
47{
48 float Volume = 0.f;
49 ALCheck(alGetListenerf(AL_GAIN, &Volume));
50
51 return Volume;
52}
53
54
58void Listener::SetPosition(float X, float Y, float Z)
59{
60 ALCheck(alListener3f(AL_POSITION, X, Y, Z));
61}
62
63
67void Listener::SetPosition(const Vector3f& Position)
68{
69 SetPosition(Position.x, Position.y, Position.z);
70}
71
72
77{
78 Vector3f Position;
79 ALCheck(alGetListener3f(AL_POSITION, &Position.x, &Position.y, &Position.z));
80
81 return Position;
82}
83
84
89void Listener::SetTarget(float X, float Y, float Z)
90{
91 float Orientation[] = {X, Y, Z, 0.f, 1.f, 0.f};
92 ALCheck(alListenerfv(AL_ORIENTATION, Orientation));
93}
94
95
100void Listener::SetTarget(const Vector3f& Target)
101{
102 SetTarget(Target.x, Target.y, Target.z);
103}
104
105
111{
112 float Orientation[6];
113 ALCheck(alGetListenerfv(AL_ORIENTATION, Orientation));
114
115 return Vector3f(Orientation[0], Orientation[1], Orientation[2]);
116}
117
118} // namespace sf
static void SetGlobalVolume(float Volume)
Change the global volume of all the sounds.
Definition Listener.cpp:37
static Vector3f GetTarget()
Get the current orientation of the listener (the point he's looking at).
Definition Listener.cpp:110
static void SetTarget(float X, float Y, float Z)
Change the orientation of the listener (the point he must look at) (take 3 values).
Definition Listener.cpp:89
static Vector3f GetPosition()
Get the current position of the listener.
Definition Listener.cpp:76
static void SetPosition(float X, float Y, float Z)
Change the position of the listener (take 3 values).
Definition Listener.cpp:58
static float GetGlobalVolume()
Get the current value of the global volume of all the sounds.
Definition Listener.cpp:46
T z
Z coordinate of the vector.
Definition Vector3.hpp:62
T x
X coordinate of the vector.
Definition Vector3.hpp:60
T y
Y coordinate of the vector.
Definition Vector3.hpp:61