[openal] distance model questions

Chris Robinson chris.kcat at gmail.com
Sun May 17 19:22:13 EDT 2015

On 05/17/2015 10:29 AM, Victorious wrote:
> I've tried it, but it doesn't seem to work properly and creates weird
> panning effects. Here's what my source setPosition function looks
> like.
> ...

The first thing I notice is that you're calculating the distance and 
lerp using the listener position instead of the source position. Another 
thing is that you'll want to use the upper polar position when the sound 
is above the listener, and the lower polar position when it's below. 
This is luckily all fairly easy when the listener up orientation is 
{0,1,0}. So, like this:

     float listenerX, listenerY, listenerZ;
     alGetListener3f(AL_POSITION, &listenerX, &listenerY, &listenerZ);

     math::float3 listenerPos(listenerX, listenerY, listenerZ);
     math::float3 sourcePos(x, y, z);

     float dist = polarPos.Distance(sourcePos);
     if(dist < 1)
         math::float3 polarPos;
         if(sourcePos.z >= listenerPos.z)
             polarPos = listenerPos + math::float3(0, 1, 0);
             polarPos = listenerPos - math::float3(0, 1, 0);

         math::float3 lerped = polarPos.Lerp(sourcePos, dist);
         x = lerped.x;
         y = lerped.y;
         z = lerped.z;
alSource3f(source, AL_POSITION, x, y, z);

More information about the openal mailing list