aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-10-30 05:47:14 -0700
committerChris Robinson <[email protected]>2011-10-30 05:47:14 -0700
commit50913948a07b8d3d75a0ca724e9d2289be6e017c (patch)
tree22db718f0b7a377bed79a13e4d6703791b8e1b23 /Alc
parenta5c02556e69667f897fcf16493e3a0ed14c3d543 (diff)
Don't transform/translate vectors with an invalid listener orientation
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index bc61e579..881d2583 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -57,18 +57,19 @@ static __inline ALfloat aluDotproduct(const ALfloat *inVector1, const ALfloat *i
inVector1[2]*inVector2[2];
}
-static __inline ALvoid aluNormalize(ALfloat *inVector)
+static __inline ALfloat aluNormalize(ALfloat *inVector)
{
ALfloat length, inverse_length;
length = aluSqrt(aluDotproduct(inVector, inVector));
- if(length != 0.0f)
+ if(length > 0.0f)
{
inverse_length = 1.0f/length;
inVector[0] *= inverse_length;
inVector[1] *= inverse_length;
inVector[2] *= inverse_length;
}
+ return length;
}
static __inline ALvoid aluMatrixVector(ALfloat *vector,ALfloat w,ALfloat matrix[4][4])
@@ -462,29 +463,32 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
N[0] = ALContext->Listener.Forward[0]; // At-vector
N[1] = ALContext->Listener.Forward[1];
N[2] = ALContext->Listener.Forward[2];
- aluNormalize(N); // Normalized At-vector
V[0] = ALContext->Listener.Up[0]; // Up-vector
V[1] = ALContext->Listener.Up[1];
V[2] = ALContext->Listener.Up[2];
- aluNormalize(V); // Normalized Up-vector
- aluCrossproduct(N, V, U); // Right-vector
- aluNormalize(U); // Normalized Right-vector
- 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] = 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);
- aluMatrixVector(Direction, 0.0f, Matrix);
- // Transform source and listener velocity into listener space
- aluMatrixVector(Velocity, 0.0f, Matrix);
- aluMatrixVector(ListenerVel, 0.0f, Matrix);
+ if(aluNormalize(N) > 0.0f && aluNormalize(V) > 0.0f)
+ {
+ /* Build and normalize right-vector */
+ aluCrossproduct(N, V, U);
+ if(aluNormalize(U) > 0.0f)
+ {
+ 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]=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 vectors into listener space */
+ aluMatrixVector(Position, 1.0f, Matrix);
+ aluMatrixVector(Direction, 0.0f, Matrix);
+ aluMatrixVector(Velocity, 0.0f, Matrix);
+ aluMatrixVector(ListenerVel, 0.0f, Matrix);
+ }
+ }
}
else
ListenerVel[0] = ListenerVel[1] = ListenerVel[2] = 0.0f;