Re: WebAudio question

Aprone's trig is overcomplicated to the extreme and wrong in some places, followed by him making up for it by correcting before and/or after the fact.

The AudioListener has 3 parameters: the position, the forward vector, and the up vector.  You're supposed to set the position to where the listener is at, the forward vector to where the listener is facing, and the up vector out the top of the listener's head.  You're not finding convenient formulas because it's not convenient, it's designed for full 3d space, not 2d space, and it's a kind of standard representation.

The way this works is that at cross up gives right, then you can use at, up, right, and position to form a standard 3d transformation matrix.  This is the standard way of representing orientation in a  lot of stuff.  But I suspect that's not helpful to you, so the 2d shortcut:

Set the forward vector to (0, 1, 0) and the up vector to (0, 0, 1)  Now positive y is forward, positive x is right, positive z is up.  As long as the up vector is (0, 0, 1), you can think of y as north/south and x as east/west, and those example values configured the listener to face north.

Degrees to radians is angle / 180.0 * pi.  To get this to be clockwise from north instead of counterclockwise from east, you use the (cos(theta), sin(theta) formula but swap it to be (sin(theta), cos(theta)).  So to turn the listener leave the up vector alone after you set it the first time and then set the listener's forward vector to (sin(theta), cos(theta), 0).  Z will always be 0 unless you start playing with facing the listener up and/or down, at which point there isn't a shortcut and you'll need to understand spherical coordinates and unit vector stuff properly.

Also note that in early-enough versions of Chrome you need to use the deprecated functions to set the orientation and position stuff instead of the new properties, because the new properties are broken.  So if it seems that things aren't moving at all try that.

If you just want to pan a source (i.e. ui stuff, things that always follow the player), I believe there's a way to turn off the application of the listener's vectors, but in that case you'll need to deal with the coordinate system being flipped so that negative z is forward, positive x is right, and positive y is up.  I haven't done WebAudio enough that I don't remember how to do it, if it can be done; I got disenchanted by the limitations and started on synthizer instead.  But OpenAL and most other libs offer this as a function.

-- 
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

Reply via email to