diff --git a/src/client/cl_entities.c b/src/client/cl_entities.c index 1fd6eb79..dc34e904 100644 --- a/src/client/cl_entities.c +++ b/src/client/cl_entities.c @@ -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); +} + diff --git a/src/client/sound/header/sound.h b/src/client/sound/header/sound.h index b8f820c5..9defde89 100644 --- a/src/client/sound/header/sound.h +++ b/src/client/sound/header/sound.h @@ -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 diff --git a/src/client/sound/openal.c b/src/client/sound/openal.c index e8f5fb8d..d172b937 100644 --- a/src/client/sound/openal.c +++ b/src/client/sound/openal.c @@ -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;