[openal] distance model questions

Victorious dtvictorious at gmail.com
Mon May 18 00:49:36 EDT 2015


Hmm, still isn't working. When doing
Float dist = polarPos.distance(...

It isn't declared/calculated yet as the calculation was done later on in the if statements. Then I tried replacing the distance calculation with source pos and listener pos.

if (isPlaying())
	{
		float listenerX, listenerY, listenerZ;
		alGetListener3f(AL_POSITION, &listenerX, &listenerY, &listenerZ);

		math::float3 listenerUp(0.0, 1.0, 0.0), listenerPos(listenerX, listenerY, listenerZ);
		math::float3 sourcePos(x, y, z); // the actual source position we want to set
			float dist = listenerPos.Distance(sourcePos);

		if (dist < 1) // < default reference distance
		{
			// lerp the source's position with polar pos
			math::float3 polarPos;
			if (sourcePos.z >= listenerPos.z)
			{
				polarPos = listenerPos + listenerUp;
			}
			else
			{
				polarPos = listenerPos - listenerUp;
			}

			math::float3 lerped = polarPos.Lerp(sourcePos, dist); // 0 replaces sourcePos with polarPos, 1 does the reverse
			x = lerped.x;
			y = lerped.y;
			z = lerped.z;
		}
	}

		alSource3f(source, AL_POSITION, x, y, z);
	

-----Original Message-----
From: openal [mailto:openal-bounces at openal.org] On Behalf Of Chris Robinson
Sent: Monday, May 18, 2015 7:22 AM
To: openal mailing list
Subject: Re: [openal] distance model questions

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:

if(isPlaying())
{
     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);
         else
             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);
_______________________________________________
openal mailing list
openal at openal.org
http://openal.org/mailman/listinfo/openal



More information about the openal mailing list