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

Author Topic: sf::Sound SetPosition, how does it work?  (Read 7481 times)

0 Members and 1 Guest are viewing this topic.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
sf::Sound SetPosition, how does it work?
« on: March 05, 2009, 06:13:03 am »
I'm having trouble getting the SetPosition thing to work.  I'm thinking my problem is my z value, but I'm not exactly sure.  I define a position by doing a sound.setPosition(x,y,0), x and y being the position of the drawable at initialization.  I tried changing the 0 to a 1 or a -1 and it still didn't work (no sound was played).  what am I doing wrong? It's probably something real stupid...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Sound SetPosition, how does it work?
« Reply #1 on: March 05, 2009, 07:48:42 am »
In 3D, Y is the "up" vector. I guess you want to use X and Z to map your 2D view.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
sf::Sound SetPosition, how does it work?
« Reply #2 on: March 05, 2009, 03:39:37 pm »
oh makes sense, thanks!

This is the reason why I stick to 2D game programming...I'm directionally dyslexic.


EDIT: What do I have to set the Y value then to get it to work? It still doesn't play the sound when I do sound.SetPosition(x,value,y) where value is a number (I tried 0,1,-1,100,etc).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Sound SetPosition, how does it work?
« Reply #3 on: March 05, 2009, 03:53:05 pm »
If you can show me a minimal and complete example that reproduces the problem, I'll try it myself.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
sf::Sound SetPosition, how does it work?
« Reply #4 on: March 05, 2009, 04:11:13 pm »
I just do:
sound.SetPosition(x,value,y);
where value is a value that I experimented with and x and y are the initial position of the object on the screen.  

I did a quick test on a test program and it seems that only small values seem to work.  (It seems that If the x and y values go too far away they are just not heard).  

What units are a sound's position measured in? Because I think I'm using pixel positions to try to map them.  Also is 0,0 the Center of the screen (this could also be a problem with my current code)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Sound SetPosition, how does it work?
« Reply #5 on: March 05, 2009, 04:24:34 pm »
There's no absolute unit. The origin is given by position of the listener, and the "scale" is given by the attenuation. Just find the proper values for your application.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Sound SetPosition, how does it work?
« Reply #6 on: June 07, 2009, 04:57:24 pm »
I found a very useful homepage where 2D sound spatialization with SFML (!) is explained. I thought I'd share it, in case one should come across this thread.

-> Link
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
sf::Sound SetPosition, how does it work?
« Reply #7 on: June 07, 2009, 09:32:20 pm »
Wow that article is really helpful, thanks!

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
sf::Sound SetPosition, how does it work?
« Reply #8 on: June 08, 2009, 06:42:57 pm »
Yey! I wrote that :D
I'm glad it helped!

You might encounter some degree of engrishness  :P

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Sound SetPosition, how does it work?
« Reply #9 on: June 08, 2009, 08:52:10 pm »
Quote from: "nitram_cero"
Yey! I wrote that :D
I'm glad it helped!
Ah, I didn't know that. Very nice work, thanks a lot. :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: