Merge pull request #193 from xorw/master

Add partial doppler shift support for 3D audio sources.
This commit is contained in:
Yamagi 2017-05-09 21:38:30 +02:00 committed by GitHub
commit e6d46eb452
3 changed files with 26 additions and 0 deletions

View file

@ -915,3 +915,21 @@ CL_GetEntitySoundOrigin(int ent, vec3_t org)
VectorCopy(old->lerp_origin, org);
}
/*
* Called to get the sound spatialization
*/
void
CL_GetEntitySoundVelocity(int ent, vec3_t vel)
{
centity_t *old;
if ((ent < 0) || (ent >= MAX_EDICTS))
{
Com_Error(ERR_DROP, "CL_GetEntitySoundVelocity: bad ent");
}
old = &cl_entities[ent];
VectorSubtract(old->current.origin, old->prev.origin, vel);
}

View file

@ -54,5 +54,6 @@ struct sfx_s *S_FindName(char *name, qboolean create);
entitiy position information, so entities can be
dynamically re-spatialized */
void CL_GetEntitySoundOrigin(int ent, vec3_t org);
void CL_GetEntitySoundVelocity(int ent, vec3_t vel);
#endif

View file

@ -199,6 +199,7 @@ static void
AL_Spatialize(channel_t *ch)
{
vec3_t origin;
vec3_t velocity;
if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult)
{
@ -218,6 +219,9 @@ AL_Spatialize(channel_t *ch)
{
CL_GetEntitySoundOrigin(ch->entnum, origin);
qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin));
CL_GetEntitySoundVelocity(ch->entnum, velocity);
qalSource3f(ch->srcnum, AL_VELOCITY, AL_UnpackVector(velocity));
return;
}
@ -613,6 +617,9 @@ AL_Update(void)
qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin));
qalListenerfv(AL_ORIENTATION, orientation);
// TODO(xorw): add current listener's velocity update
// qalListener3f(AL_VELOCITY, AL_UnpackVector(listener_velocity));
/* update spatialization for dynamic sounds */
ch = channels;