Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to rotate listenerOrientation #41

Open
craigbrett17 opened this issue Dec 17, 2017 · 0 comments
Open

How to rotate listenerOrientation #41

craigbrett17 opened this issue Dec 17, 2017 · 0 comments

Comments

@craigbrett17
Copy link

Hi there. Love the library - think it's my favourite way of doing web audio. But... I'm having a little trouble with 3D sound, in particular rotating the listener position, representing turning the player around, etc.

From looking at the example, it's very Thre.JS specific. However, the reason I came to sono was that I found Three.js a bit too heavy for just doing simple 3D sound in the web when you're not using any visuals. So I've been trying to crack it without it. I think when I understand this all a bit more I might try upping the documentation of it a bit.

So far, I've been minorly successful making a sound pan from left to right when I rotate, except the jump is huge and it doesn't go all the way around for some reason. I think my maths is wrong here.

Here's what I have, with pov being an instance of my PointOfView class.

In index.ts:

function inGameKeyPressHandler(ev: KeyboardEvent): void {
  switch (ev.which) {
    case Key.LeftArrow:
      pov.rotateLeft(45)
      console.log("Orientation: ", pov.OrientationX, pov.OrientationY, pov.OrientationZ)
      break
    case Key.RightArrow:
      pov.rotateRight(45)
      console.log("Orientation: ", pov.OrientationX, pov.OrientationY, pov.OrientationZ)
      break
  }
}

And in PointOfView class I have:

    /** The orientation X direction of the POV */
    OrientationX: number
    /** The orientation Y direction of the POV */
    OrientationY: number
    /** The orientation Z direction of the POV */
    OrientationZ: number

    rotateLeft(degrees: number) {
        this.OrientationX -= degrees * Math.PI / 180
        sono.panner.setListenerOrientation(this.OrientationX, this.OrientationY, this.OrientationZ)        
    }

    rotateRight(degrees: number) {
        this.OrientationX += degrees * Math.PI / 180
        sono.panner.setListenerOrientation(this.OrientationX, this.OrientationY, this.OrientationZ)        
    }

Am I even close?

Sorry if this isn't the right forum to ask questions on library use, happy to move it if needs be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant