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

Author Topic: Listener Orientation  (Read 5202 times)

0 Members and 2 Guests are viewing this topic.

lucasncv

  • Newbie
  • *
  • Posts: 15
    • View Profile
Listener Orientation
« on: October 11, 2011, 04:25:51 am »
Hello! I've just started using the Audio module of SFML2 and so far everything is fine, I'd just like to know why isn't there an option to set the up vector of the Listener's orientation.

sf::Listener::SetDirection assumes it's (0, 1, 0), but my game, for example, is entirely built around the (0, -1, 0) up vector.

Code: [Select]
////////////////////////////////////////////////////////////
void Listener::SetDirection(float x, float y, float z)
{
    priv::EnsureALInit();

    float orientation[] = {x, y, z, 0.f, 1.f, 0.f};
    ALCheck(alListenerfv(AL_ORIENTATION, orientation));
}


For now I'm using a modified version of SFML with an overloaded SetDirection that takes another sf::Vector3f as the Up vector. So, why isn't this implemented?  :?:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Listener Orientation
« Reply #1 on: October 11, 2011, 07:59:42 am »
What does a (0, -1, 0) up vector represents? Someone walking on its hands? :P

And if it doesn't change the direction of other axes, it shouldn't matter, does it?
Laurent Gomila - SFML developer

lucasncv

  • Newbie
  • *
  • Posts: 15
    • View Profile
Listener Orientation
« Reply #2 on: October 11, 2011, 03:58:08 pm »
What do you mean?  :?  In my scenario, using the (0, 1, 0) up vector makes objects to the left of the listener emit sounds through the right speaker.

As an example, the listener is at (0, 0, -10), looking at the +Z axis, and the object is at (-5, 0, 0) for example. Now, using the default up vector (0, 1, 0), makes the listener's head point down, what I don't want.

I could, of course, put the listener at (0, 0, 10), but it's just that +Y being down makes more sense when using a physics engine.

Other use I could think of is to do a rotation effect of the entire screen, think about it, imagine rotating the entire game world, hard. Now imagine rotating just the graphics with a simple transformation and rotating the listener's up vector, both can be done easily. It's a cool effect, by the way.  :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Listener Orientation
« Reply #3 on: October 11, 2011, 04:28:42 pm »
You should read this, to make sure that you're not misunderstanding anything about the audio module and the coordinates system:
http://www.sfml-dev.org/forum/viewtopic.php?t=1225
Laurent Gomila - SFML developer

lucasncv

  • Newbie
  • *
  • Posts: 15
    • View Profile
Listener Orientation
« Reply #4 on: October 11, 2011, 07:43:53 pm »
I apologize if I'm not being entirely clear  :oops:  But even nitram_cero mentions what I'm talking about, and I'm already using this system on my game, it works the way I said, even the cool effect works fine...

Quote from: "nitram_cero"

Quote
To me it's ok to have the up vector hard-coded, this is like a physical constant (just like gravity for example).

In 3D, gives you the hability to roll your head (e.g. Peeking from a corner of a wall).

In 2D gives you freedom to define which sound-coordinate axis is associated with a screen-coordinate counterpart. I like using x for x and y for y, it's more confortable to work this way.

Also to let you "reverse" the speakers (Up = -Up), for configuration and also could be used for a weird powerup effect.


Now, how could I implement the effect I mentioned with the current implementation of sf::Listener? Imagine a sound coming from the right speaker, I want it to rotate around the "front" axis, in clockwise direction. So the sound would be heard from top, then from the left, ending by being heard from below.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Listener Orientation
« Reply #5 on: October 11, 2011, 10:15:48 pm »
Indeed, "rolling" the listener is not supported in SFML.

But this:
Quote
using the (0, 1, 0) up vector makes objects to the left of the listener emit sounds through the right speaker

is not normal and could be solved without hacking in SFML.
Laurent Gomila - SFML developer

lucasncv

  • Newbie
  • *
  • Posts: 15
    • View Profile
Listener Orientation
« Reply #6 on: October 11, 2011, 10:58:10 pm »
Quote from: "Laurent"
is not normal and could be solved without hacking in SFML.


I know, I said that:

Quote from: "lucasncv"
I could, of course, put the listener at (0, 0, 10), but it's just that +Y being down makes more sense when using a physics engine.


I'm just asking that you consider this feature. Not to solve my problem (that's not really a problem per se), but because it's useful, as my example shows you.

Perhaps a sf::Listener::SetListenerOrientation? One that does the same thing as SetListenerDirection, but with the option to also change the up vector, the default would still be (0, 1, 0).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Listener Orientation
« Reply #7 on: October 12, 2011, 07:53:49 am »
Quote
I'm just asking that you consider this feature.

Oh, ok :)

I'll do.
Laurent Gomila - SFML developer

lucasncv

  • Newbie
  • *
  • Posts: 15
    • View Profile
Listener Orientation
« Reply #8 on: October 12, 2011, 03:45:51 pm »
Thank you for considering it and also for your patience  :)

 

anything