Ok, I don't think the math in setListenerAngle is the problem. The problem is in the last line, where I tell OpenAL what the listener's orientation is. Here's why I think that line is the problem:
I created a simple method for setting the listener's orientation manually:
public void setListenerOrientation( float lookX, float lookY, float lookZ,
float upX, float upY, float upZ )
{
listenerOrientation.put( 0, lookX );
listenerOrientation.put( 1, lookY );
listenerOrientation.put( 2, lookZ );
listenerOrientation.put( 3, upX );
listenerOrientation.put( 4, upY );
listenerOrientation.put( 5, upZ );
AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );
}
Then I have a source at (50, 0, 250) as in my last example.
When I use:
mySoundSystem.moveListener( 0, 0, 250 );
mySoundSystem.setListenerOrientation( 0, 0, 251, 0, 1, 0 );
Sound plays out of the left speaker as expected.
But when I use:
mySoundSystem.moveListener( 0, 0, 250 );
mySoundSystem.setListenerOrientation( 0, 0, 249, 0, 1, 0 );
Sound still plays out of the left speaker, even though I should be facing the opposite direction!
This means I obviously do not understand how the listener orientation part of OpenAL works. Can anyone help explain this to me? Thanks in advance.
-- EDIT --
My thought is perhaps the lookAt direction needs to represent a normalized vector (distance=1 from the origin), like how the up direction works. I'll test this theory and let you know what I find out.
-- EDIT #2 --
Yes that appears to be the issue.
When I use:
mySoundSystem.moveListener( 0, 0, 250 );
mySoundSystem.setListenerOrientation( 0, 0, 1, 0, 1, 0 );
Then Sound is out of the left speaker.
And when I use:
mySoundSystem.moveListener( 0, 0, 250 );
mySoundSystem.setListenerOrientation( 0, 0, -1, 0, 1, 0 );
Then Sound is out of the right speaker.
I'll try changing my code with this in mind, and see if this solves the problem.