[Openal] AL_DIRECTION // rotating source

Chris Robinson chris.kcat at gmail.com
Thu Jun 14 02:03:58 PDT 2012


On Wednesday, June 13, 2012 11:42:58 PM mike4linux wrote:
> Hi
> pPsi is the heading angle in degrees. I set soundpositions:
> 
> float hdgPv = fmod(pPsi + 180, 360);//front x position
> float hdgPh = fmod(pPsi, 360);//back
> 
> alSource3f(Sources[2], AL_POSITION, hdgPv/10, lY/10, lZ/10); //front
> 
> 
> now attenuation is fine for back but for front I get a interruption
> when angle goes from 360 - 0. Any
> idea on how to fix that? I was also looking for AL_DIRECTION but
> couldn't find any solution.
> Many thanks

Hi.

I'm a bit confused about what you're trying to do. Are you trying to move the 
sound around a certain point, or are you trying to change the direction the 
sound itself is facing (for the sound cones)?

If you have the heading angle in degrees, you can get the angle vector by 
converting to radians and using sin and cos:

float vec[3];
float rad = pPsi * M_PI/180.0f;
vec[0] = sin(rad);
vec[1] = 0.0f;
vec[2] = -cos(rad);

This makes it so pPsi=0 is front/forward, and incrementing goes clockwise. So 
if you're trying to move the sound, you set its position:

alSourcefv(Sources[2], AL_POSITION, vec);

Or if you're trying to set it's facing direction for sound cones, set 
AL_DIRECTION instead.

Hope that helps.


More information about the Openal mailing list