[openal] distance model questions
dtvictorious at gmail.com
Sun May 24 09:06:11 EDT 2015
I have a river on the left edge of a 10x10 grid. What I want to have is a single sound source for the river that plays towards the left when you're near the left edge (i.e a line segment of 10 units)
I have the following properties on sound objects: left/right/up/down/forward/backward range, which forms an axis-aligned box around the sound source. The river's sound source's RHS coords were set at (0.0, 0.0, -5.0), forward/backward range 5.0, all other ranges set to 0.
I tried the following to interpolate the sounds, but it doesn't work quite right.
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 distBox = distFromBoundingBox(x, y, z); // returns 0 if listener pos intersects or is inside the bounding box
float dist = listenerPos.Distance(sourcePos);
dist -= distBox;
if (sourcePos.y >= listenerPos.y)
polarPos = listenerPos + listenerUp;
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);
From: openal [mailto:openal-bounces at openal.org] On Behalf Of Chris Robinson
Sent: Tuesday, May 19, 2015 11:10 AM
To: openal mailing list
Subject: Re: [openal] distance model questions
On 05/18/2015 06:21 AM, Victorious wrote:
> I mean the former. For simplicity, I probably want a boxed shape, and
> the axis will always be in respect to the global x/y/z axis.
In that case, you need to calculate the distance to the nearest point on the bounding box when the point lies outside of it, and subtract that from the real distance and radius when calculating the interpolation factor.
Unfortunately the exact math to do that escapes me at the moment.
openal mailing list
openal at openal.org
More information about the openal