Re: WebAudio question

I don't see you setting the up vector, only the at vector.  If you aren't, that's your problem, but you only need to do it once, so maybe it's just not in your code.

Moving the listener's head is done in every first person game ever. If you're not doing first person stuff, then you won't have them move their head, otherwise at needs to be pointed in the direction the listener is facing.

You will have a much easier time if you express your simulation as it actually is (i.e. properly position sources, properly position the listener, etc) than trying to hack things into what you're trying to hack them into without knowing all the underlying math.  Let the engine work for you.

Your coordinatesInDirection function is expecting angles counterclockwise from east, not clockwise from north.  Replace cos with sin and sin with cos and I think it will do what you think; but if you just put start in listener.positionX, listener.positionY, you can use my formulas as-is and avoid all of this.  If you want angles counterclockwise from east (which is not at all unreasonable) then my formulas become (cos(theta), sin(theta)) and your function is right.  That said I'm not entirely sure what that function is supposed to do, I'm only guessing.

It might be possible to just control azimuth and elevation directly, you might want to do that instead.  And if you're doing a side-scroller or something, you can just drop HRTF and use a couple gain nodes for your panning (if you're wondering where WebAudio put simple stereo panning, where it put simple stereo panning is in 2 gain nodes and a channel merger).  I think it's also worth mentioning that if your game isn't going to allow the listener to turn then you're losing 75% of HRTF or something--HRTF is terrible beyond all belief at telling you if something just went from in front to behind if you can't turn to face it and are trying to aim east while "facing" north.  That said it looks kinda like you're trying to turn the world instead of the listener, which is fine as far as it goes and gets the same thing, it's just kinda hacky.

Aprone's trig works well enough for Swamp, but reading his tutorials I don't think he understands what he's doing and just beat on the formulas until he got the numbers to be right, and if I'd done it I'd have just pointed people at a transformation matrix library of some sort and gone through the trouble of explaining how to use it rather than trying to end up at the same place as that through what he did.  Transformation matrix libraries hide all of this from you and if you're sighted you can do all of what you're trying to do with about 0% of the required math knowledge, but the tutorials on their usage are very visual.  It's basically the example case of a picture is worth a thousand words.  Unfortunately I don't have the bandwidth to write a resource at this time and it can't be explained quickly.

It's also worth noting that DirectX uses a left-handed coordinate system, and is the only thing that does to my knowledge; to figure out if this mattered I'd have to follow through all of his math and reasoning.  I don't think it does in the 2D case because either he used the x-z plane as horizontal which in DirectX works out to what you'd expect, or he used the x-y plane as horizontal which works out to what you'd expect until you try to add vertical stuff at which point you discover that positive z is down.

Trig is hard enough that I might be doing this wrong too, though I've used the above formulas many times before, but either way I take his math with a grain of salt.  I'm not saying assume it's wrong, just check.  Take some numbers and put them into your functions and see if the functions spit out numbers that make sense for what you expect them to do.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector

Reply via email to