aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-04-16 02:09:53 -0700
committerChris Robinson <[email protected]>2010-04-16 02:09:53 -0700
commitfc2473f8264a6b6677306fcfec35180d58827203 (patch)
treeb70960bbe027c719498e126c5e35e7af5dcb79c2
parent000d848f0b668a2a5048ee7c7d1ab71e69f3ddb3 (diff)
Translate the source position separately
This is to handle the case where an app specifies the same values for the source and listener, and expects centered panning. This fails due to floating- point errors in the matrix, causing the result to be ever-so-slightly off of 0. This error would normally be hidden by the position normalization, which will not lengthen a distance shorter than the reference distance so the panning would be nearly imperceptible. But that also fails if the reference distance is set to 0, causing the position to expand to a full unit. Keep the 4x4 matrix calculations, however. It will still be useful for the requested listener matrix extension.
-rw-r--r--Alc/ALu.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 2deb993d..2bc5cde2 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -580,7 +580,7 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
//1. Translate Listener to origin (convert to head relative)
if(ALSource->bHeadRelative==AL_FALSE)
{
- ALfloat U[3],V[3],N[3],P[3];
+ ALfloat U[3],V[3],N[3];
// Build transform matrix
memcpy(N, ALContext->Listener.Forward, sizeof(N)); // At-vector
@@ -589,19 +589,15 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource)
aluNormalize(V); // Normalized Up-vector
aluCrossproduct(N, V, U); // Right-vector
aluNormalize(U); // Normalized Right-vector
- P[0] = -(ALContext->Listener.Position[0]*U[0] + // Translation
- ALContext->Listener.Position[1]*U[1] +
- ALContext->Listener.Position[2]*U[2]);
- P[1] = -(ALContext->Listener.Position[0]*V[0] +
- ALContext->Listener.Position[1]*V[1] +
- ALContext->Listener.Position[2]*V[2]);
- P[2] = -(ALContext->Listener.Position[0]*-N[0] +
- ALContext->Listener.Position[1]*-N[1] +
- ALContext->Listener.Position[2]*-N[2]);
Matrix[0][0] = U[0]; Matrix[0][1] = V[0]; Matrix[0][2] = -N[0]; Matrix[0][3] = 0.0f;
Matrix[1][0] = U[1]; Matrix[1][1] = V[1]; Matrix[1][2] = -N[1]; Matrix[1][3] = 0.0f;
Matrix[2][0] = U[2]; Matrix[2][1] = V[2]; Matrix[2][2] = -N[2]; Matrix[2][3] = 0.0f;
- Matrix[3][0] = P[0]; Matrix[3][1] = P[1]; Matrix[3][2] = P[2]; Matrix[3][3] = 1.0f;
+ Matrix[3][0] = 0.0f; Matrix[3][1] = 0.0f; Matrix[3][2] = 0.0f; Matrix[3][3] = 1.0f;
+
+ // Translate position
+ Position[0] -= ALContext->Listener.Position[0];
+ Position[1] -= ALContext->Listener.Position[1];
+ Position[2] -= ALContext->Listener.Position[2];
// Transform source position and direction into listener space
aluMatrixVector(Position, 1.0f, Matrix);