Merge pull request #196 from xorw/master

Finished doppler shift support (added listener's velocity update)
This commit is contained in:
Yamagi 2017-05-12 17:58:04 +02:00 committed by GitHub
commit 8af427b0c9
3 changed files with 16 additions and 2 deletions

View file

@ -933,3 +933,13 @@ CL_GetEntitySoundVelocity(int ent, vec3_t vel)
VectorSubtract(old->current.origin, old->prev.origin, vel);
}
void
CL_GetViewVelocity(vec3_t vel)
{
// restore value from 12.3 fixed point
const float scale_factor = 1.0f / 8.0f;
vel[0] = (float)cl.frame.playerstate.pmove.velocity[0] * scale_factor;
vel[1] = (float)cl.frame.playerstate.pmove.velocity[1] * scale_factor;
vel[2] = (float)cl.frame.playerstate.pmove.velocity[2] * scale_factor;
}

View file

@ -55,5 +55,6 @@ struct sfx_s *S_FindName(char *name, qboolean create);
dynamically re-spatialized */
void CL_GetEntitySoundOrigin(int ent, vec3_t org);
void CL_GetEntitySoundVelocity(int ent, vec3_t vel);
void CL_GetViewVelocity(vec3_t vel);
#endif

View file

@ -607,6 +607,7 @@ AL_Update(void)
int i;
channel_t *ch;
vec_t orientation[6];
vec3_t listener_velocity;
paintedtime = cls.realtime;
@ -617,8 +618,10 @@ 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));
CL_GetViewVelocity(listener_velocity);
// xorw: sounds funky if not scaled down a lot
VectorScale(listener_velocity, 0.05f, listener_velocity);
qalListener3f(AL_VELOCITY, AL_UnpackVector(listener_velocity));
/* update spatialization for dynamic sounds */
ch = channels;