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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Pyotr

Pages: [1]
1
Feature requests / 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.

Pages: [1]