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

Author Topic: Spatialization doubt  (Read 3447 times)

0 Members and 1 Guest are viewing this topic.

kazyamof

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Spatialization doubt
« on: October 18, 2016, 01:13:39 pm »
Well, as always, spatialization audio is driving me crazy.
I can't found a good tutorial where this really works! I read a lot of answers on the forum, but I'm missing a step-by-step guide where some clear and simple information is presented. So I expected someone can answer me as simple as possible.

My cenario is:

Screen is 800x600.
My player moves on X screen. He spawns at Vector2(100, 500).
I wanna put a sound at Vector2(300, 500).

1 - What Position shoud I set to Sound? Vector3(300, 0, 500)?

2 - What Direction and Position I should set on Listener to make him hear the sound on right speaker while Player.Position.X < Sound.Position.X, and then on the left speaker when Player.Position.X > Sound.Position.X?
« Last Edit: October 18, 2016, 02:16:50 pm by kazyamof »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Spatialization doubt
« Reply #1 on: October 18, 2016, 02:40:27 pm »
Quote
1 - What Position shoud I set to Sound? Vector3(300, 0, 500)?
Yes

Quote
2 - What Direction and Position I should set on Listener to make him hear the sound on right speaker while Player.Position.X < Sound.Position.X, and then on the left speaker when Player.Position.X > Sound.Position.X?
Vector3(Player.Position.X, 0, Player.Position.Y) for position.
The direction depends on where the player is facing. I'd say it should face negative Z to ear the sound as you describe it.

You see, nothing complicated ;)
« Last Edit: October 18, 2016, 02:43:58 pm by Laurent »
Laurent Gomila - SFML developer

kazyamof

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Spatialization doubt
« Reply #2 on: October 18, 2016, 03:10:21 pm »
You see, nothing complicated ;)

Finally is working with this set up and the Direction facing -Z.

Listener.Direction = new Vector3f(0, 0, -1)

Thank you, I think I'm getting the audio's fell I want now.
This works for a platform game where -x/+x avatar's displacement fits with the 'logical' position of left/right speakers.

But what if I decide to make a topdown 2D game, where the avatar's receive rotations, I think this setup will not work anymore, right?
The avatar is rotated so the sound is on his left side, like the second section of this figure.


How should I configure the Listener.Direction and Listener.VectorUp to this setup? Direction = Vector3(cos(90), 0, sin(90)) and VectorUp(0, 1, 0) ?
« Last Edit: October 18, 2016, 03:15:59 pm by kazyamof »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Spatialization doubt
« Reply #3 on: October 18, 2016, 03:29:53 pm »
Actually, I had the "top down style" in mind when I answered you, so that should work the same way.
Laurent Gomila - SFML developer