Well the OpenAL panning problem has reared its ugly head once again. Turns the reason it seemed to be fixed was that I had mis-diagnosed the problem. My assumtion had been that it was a source-related problem, but it turns out that it is in fact a listener-related problem. It has something to do with when the listener moves, its orientation gets thrown off. The code I'm using for this is directly out of a book I bought, and it seems to be written correctly. I've been googling and wracking my brains for hours, but I can not figure out what the problem is! I've posted a question on the lwjgl forum, so hopefully someone over there can point me in the right direction. I'll post the code here, as well, in case any of you guys can see anything obvious like a math or logic error:
Create the Listener:
private synchronized void initListener()
{
// Listener is at the origin, facing along the z axis, no velocity:
listenerPosition = BufferUtils.createFloatBuffer( 3 ).put(
new float[] { 0.0f, 0.0f, 0.0f } );
listenerOrientation = BufferUtils.createFloatBuffer( 6 ).put (
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f } );
listenerVelocity = BufferUtils.createFloatBuffer( 3 ).put (
new float[] { 0.0f, 0.0f, 0.0f } );
// Flip the buffers, so they can be used:
listenerPosition.flip();
listenerOrientation.flip();
listenerVelocity.flip();
AL10.alListener( AL10.AL_POSITION, listenerPosition );
AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );
AL10.alListener( AL10.AL_VELOCITY, listenerVelocity );
}
Move the listener:
private void moveListener( float x, float y, float z )
{
float xOffset = x - listenerPosition.get( 0 );
float yOffset = y - listenerPosition.get( 1 );
float zOffset = z - listenerPosition.get( 2 );
listenerPosition.put( 0, x );
listenerPosition.put( 1, y );
listenerPosition.put( 2, z );
AL10.alListener( AL10.AL_POSITION, listenerPosition );
// Keep the listener facing the same direction by
// moving the "look at" point by the offset values:
listenerOrientation.put( 0, listenerOrientation.get( 0 ) + xOffset );
listenerOrientation.put( 1, listenerOrientation.get( 1 ) + yOffset );
listenerOrientation.put( 2, listenerOrientation.get( 2 ) + zOffset );
AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );
}
And turn the listener:
public void setListenerAngle( float angle )
{
float xOffset = -1.0f * (float) Math.sin( angle );
float zOffset = -1.0f * (float) Math.cos( angle );
listenerOrientation.put( 0, listenerPosition.get( 0 ) + xOffset);
listenerOrientation.put( 2, listenerPosition.get( 2 ) + zOffset);
AL10.alListener( AL10.AL_ORIENTATION, listenerOrientation );
}