[openal] distance model questions

Chris Robinson chris.kcat at gmail.com
Mon May 25 03:54:25 EDT 2015


On 05/25/2015 12:34 AM, Victorious wrote:
> I've just implemented it, and it works very well for simulating
> axis-aligned planes/lines/solids, except for the fast panning. How do
> I do the interpolation for this case to prevent it? There are 3
> values - x/y/z range, 1 sound radius value for each axis.

In that case, you can combine the two methods, first clamping the source 
position to the area then lerping based on distance:

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

x = clamp(listenerX, center_x - x_range, center_x + x_range);
y = clamp(listenerY, center_y - y_range, center_y + y_range);
z = clamp(listenerZ, center_z - z_range, center_z + z_range);

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

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

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


More information about the openal mailing list