Sounds in 3D space
The most interesting part about sound effects is yet to come. An immersive atmosphere only builds up if sounds are properly located within the game world. Like graphical objects, sounds can have a position.
The coordinate system for sounds is three-dimensional. SFML's sound API works with the sf::Vector3f
type, a 3D vector with the members x
, y
, and z
. SFML internally uses Open Audio Library (OpenAL), an interface for low-level audio functionality, which is also the origin of the sound spatialization concepts we are going to discuss here.
Spatializing sounds means nothing more than to locate them in the 3D space, that is, to give them a spatial representation.
The listener
The audition of spatial sound effects depends on the listener. A useful analogy is to compare the listener with your head. The listener's location and orientation can be described with the following three 3D vectors:
Position: This vector describes where the listener is located in 3D space.
Up: This vector...