Properly make the source velocity relative to the listener velocity

This commit is contained in:
Chris Robinson 2012-03-09 23:53:45 -08:00
parent 7db29a2332
commit f5f519aa80

View File

@ -354,11 +354,12 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALboolean WetGainAuto; ALboolean WetGainAuto;
ALboolean WetGainHFAuto; ALboolean WetGainHFAuto;
enum Resampler Resampler; enum Resampler Resampler;
ALfloat Matrix[4][4];
ALfloat Pitch; ALfloat Pitch;
ALuint Frequency; ALuint Frequency;
ALint NumSends; ALint NumSends;
ALfloat cw; ALfloat cw;
ALint i; ALint i, j;
DryGainHF = 1.0f; DryGainHF = 1.0f;
for(i = 0;i < MAX_SENDS;i++) for(i = 0;i < MAX_SENDS;i++)
@ -443,17 +444,15 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->Params.Send[i].Slot = Slot; ALSource->Params.Send[i].Slot = Slot;
} }
for(i = 0;i < 4;i++)
{
for(j = 0;j < 4;j++)
Matrix[i][j] = ALContext->Listener.Matrix[i][j];
}
//1. Translate Listener to origin (convert to head relative) //1. Translate Listener to origin (convert to head relative)
if(ALSource->bHeadRelative == AL_FALSE) if(ALSource->bHeadRelative == AL_FALSE)
{ {
ALfloat Matrix[4][4];
for(i = 0;i < 4;i++)
{
ALint i2;
for(i2 = 0;i2 < 4;i2++)
Matrix[i][i2] = ALContext->Listener.Matrix[i][i2];
}
/* Translate position */ /* Translate position */
Position[0] -= ALContext->Listener.Position[0]; Position[0] -= ALContext->Listener.Position[0];
Position[1] -= ALContext->Listener.Position[1]; Position[1] -= ALContext->Listener.Position[1];
@ -463,14 +462,17 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
aluMatrixVector(Position, 1.0f, Matrix); aluMatrixVector(Position, 1.0f, Matrix);
aluMatrixVector(Direction, 0.0f, Matrix); aluMatrixVector(Direction, 0.0f, Matrix);
aluMatrixVector(Velocity, 0.0f, Matrix); aluMatrixVector(Velocity, 0.0f, Matrix);
/* Transform listener vectors into listener space */ /* Transform listener velocity into listener space */
aluMatrixVector(ListenerVel, 0.0f, Matrix); aluMatrixVector(ListenerVel, 0.0f, Matrix);
} }
else else
{ {
ListenerVel[0] = 0.0f; /* Transform listener velocity into listener space */
ListenerVel[1] = 0.0f; aluMatrixVector(ListenerVel, 0.0f, Matrix);
ListenerVel[2] = 0.0f; /* Offset the source velocity to be relative of the listener velocity */
Velocity[0] += ListenerVel[0];
Velocity[1] += ListenerVel[1];
Velocity[2] += ListenerVel[2];
} }
SourceToListener[0] = -Position[0]; SourceToListener[0] = -Position[0];