aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alListener.h1
-rw-r--r--OpenAL32/Include/alu.h28
-rw-r--r--OpenAL32/alListener.c32
3 files changed, 60 insertions, 1 deletions
diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h
index 0f399e5f..0e69f6c5 100644
--- a/OpenAL32/Include/alListener.h
+++ b/OpenAL32/Include/alListener.h
@@ -13,6 +13,7 @@ typedef struct ALlistener_struct
volatile ALfloat Velocity[3];
volatile ALfloat Forward[3];
volatile ALfloat Up[3];
+ volatile ALfloat Matrix[4][4];
volatile ALfloat Gain;
volatile ALfloat MetersPerUnit;
} ALlistener;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index ffc8fa39..a3584775 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -260,6 +260,34 @@ static __inline void RestoreFPUMode(int state)
}
+static __inline void aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector)
+{
+ outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
+ outVector[1] = inVector1[2]*inVector2[0] - inVector1[0]*inVector2[2];
+ outVector[2] = inVector1[0]*inVector2[1] - inVector1[1]*inVector2[0];
+}
+
+static __inline ALfloat aluDotproduct(const ALfloat *inVector1, const ALfloat *inVector2)
+{
+ return inVector1[0]*inVector2[0] + inVector1[1]*inVector2[1] +
+ inVector1[2]*inVector2[2];
+}
+
+static __inline void aluNormalize(ALfloat *inVector)
+{
+ ALfloat length, inverse_length;
+
+ length = aluSqrt(aluDotproduct(inVector, inVector));
+ if(length > 0.0f)
+ {
+ inverse_length = 1.0f/length;
+ inVector[0] *= inverse_length;
+ inVector[1] *= inverse_length;
+ inVector[2] *= inverse_length;
+ }
+}
+
+
ALvoid aluInitPanning(ALCdevice *Device);
ALint aluCart2LUTpos(ALfloat re, ALfloat im);
diff --git a/OpenAL32/alListener.c b/OpenAL32/alListener.c
index 37982b5c..32a12cfb 100644
--- a/OpenAL32/alListener.c
+++ b/OpenAL32/alListener.c
@@ -142,14 +142,44 @@ AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
isfinite(pflValues[2]) && isfinite(pflValues[3]) &&
isfinite(pflValues[4]) && isfinite(pflValues[5]))
{
+ ALfloat U[3], V[3], N[3];
+
+ /* AT then UP */
+ N[0] = pflValues[0];
+ N[1] = pflValues[1];
+ N[2] = pflValues[2];
+ aluNormalize(N);
+ V[0] = pflValues[3];
+ V[1] = pflValues[4];
+ V[2] = pflValues[5];
+ aluNormalize(V);
+ /* Build and normalize right-vector */
+ aluCrossproduct(N, V, U);
+ aluNormalize(U);
+
LockContext(Context);
- // AT then UP
Context->Listener.Forward[0] = pflValues[0];
Context->Listener.Forward[1] = pflValues[1];
Context->Listener.Forward[2] = pflValues[2];
Context->Listener.Up[0] = pflValues[3];
Context->Listener.Up[1] = pflValues[4];
Context->Listener.Up[2] = pflValues[5];
+ Context->Listener.Matrix[0][0] = U[0];
+ Context->Listener.Matrix[0][1] = V[0];
+ Context->Listener.Matrix[0][2] = -N[0];
+ Context->Listener.Matrix[0][3] = 0.0f;
+ Context->Listener.Matrix[1][0] = U[1];
+ Context->Listener.Matrix[1][1] = V[1];
+ Context->Listener.Matrix[1][2] = -N[1];
+ Context->Listener.Matrix[1][3] = 0.0f;
+ Context->Listener.Matrix[2][0] = U[2];
+ Context->Listener.Matrix[2][1] = V[2];
+ Context->Listener.Matrix[2][2] = -N[2];
+ Context->Listener.Matrix[2][3] = 0.0f;
+ Context->Listener.Matrix[3][0] = 0.0f;
+ Context->Listener.Matrix[3][1] = 0.0f;
+ Context->Listener.Matrix[3][2] = 0.0f;
+ Context->Listener.Matrix[3][3] = 1.0f;
Context->UpdateSources = AL_TRUE;
UnlockContext(Context);
}