Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Positional audio - up vector  (Read 3415 times)

0 Members and 1 Guest are viewing this topic.

Pyotr

  • Newbie
  • *
  • Posts: 1
    • View Profile
Positional audio - up vector
« on: June 28, 2010, 12:49:08 am »
SFML is currently unable to set the up vector of the listener. This is important because the sound changes depending on the orientation of the head and it is now impossible to adjust the "roll" of the head (rotation around the axis of listener  location <-> target).

An up vector also allows one to use a coordinate system different from the default one. For instance in my game I have to transpose all coordinates like this: x' = x, y' = z, z' = -y. By specifiying an up vector of (0,0,1) that is no longer necessary.

One can obviously work around this limitation by transforming all sound positions manually but that defeats the purpose of a settable listener position and orientation.

As OpenAL already supports setting the up vector, implementing it should be easy. I've used the following patch successfully:

Code: [Select]
Index: include/SFML/Audio/Listener.hpp
===================================================================
--- include/SFML/Audio/Listener.hpp     (revision 1527)
+++ include/SFML/Audio/Listener.hpp     (working copy)
@@ -94,7 +94,7 @@
     /// \param X, Y, Z : Position of the point the listener must look at
     ///
     ////////////////////////////////////////////////////////////
-    static void SetTarget(float X, float Y, float Z);
+    static void SetTarget(float X, float Y, float Z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f);

     ////////////////////////////////////////////////////////////
     /// Change the orientation of the listener (the point
Index: src/SFML/Audio/Listener.cpp
===================================================================
--- src/SFML/Audio/Listener.cpp (revision 1527)
+++ src/SFML/Audio/Listener.cpp (working copy)
@@ -86,9 +86,9 @@
 /// Change the orientation of the listener (the point
 /// he must look at) (take 3 values)
 ////////////////////////////////////////////////////////////
-void Listener::SetTarget(float X, float Y, float Z)
+void Listener::SetTarget(float X, float Y, float Z, float upX, float upY, float upZ)
 {
-    float Orientation[] = {X, Y, Z, 0.f, 1.f, 0.f};
+    float Orientation[] = {X, Y, Z, upX, upY, upZ};
     ALCheck(alListenerfv(AL_ORIENTATION, Orientation));
 }


This quick hack is source compatible with older versions, but I think for the real thing binary compatibility would be required. I propose new Get/SetUpVector() methods.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Positional audio - up vector
« Reply #1 on: June 28, 2010, 08:13:46 am »
Thanks.

I don't care about binary or API compatibility, the next version is 2.0 ;)
Laurent Gomila - SFML developer