look at // openAL

Hi
I’ve a camera which always point to the center. Now how could I set openAl listener orientation?

//get current view matrix

double mMatrix[16];

glGetDoublev(GL_MODELVIEW_MATRIX,mMatrix);



//set listener orientation, first 3 numbers are for the forward vector, last three are for the up vector

SetListenerOrientation(-mMatrix[2],-mMatrix[6],-mMatrix[10],mMatrix[1],mMatrix[5],mMatrix[9]);

This doesn’t work. Any help?
Many thanks
Michael

Short answer: yes your code appears to be correct.

Long answer below:

First ensure you are using OpenAL-Soft, so you’ll know for sure that the OpenAL implementation you use is not full of bugs:

http://kcat.strangesoft.net/openal.html

Then ensure your application is actually using the OpenAL-Soft software renderer by selecting the proper device.

I mention this because there are few hardware OpenAL drivers from Creative/Realtek that actually gets the listener orientation right (believe it or not). I have wasted weeks only to find out that nothing was wrong with my code. Always use software audio, hardware is long dead and highly unreliable.


OpenAL listener orientation requires two parameters stored in a single array; a forward facing vector and ‘up-vector’, both in world space orientation.

Pseudo code from our engine:


 float m[16]; // world space camera transform

 vec3 position = vec3( m[12], m[13], m[14] );  // world space position
 vec3 up       = vec3( m[4], m[5], m[6] );     // world space up vector
 vec3 front    = vec3( -m[8], -m[9], -m[10] ); // vector facing forward from camera/listener position

 float ori[6];
 ori[0] = fr.x;
 ori[1] = fr.y;
 ori[2] = fr.z;
 ori[3] = up.x;
 ori[4] = up.y;
 ori[5] = up.z;

 alListenerfv(AL_POSITION, pos);
 alListenerfv(AL_ORIENTATION, ori);

Keep in mind that ‘m’ here, is a regular transformation matrix (e.g. the same you use to transform an entity to it’s world space position).
So you have to take the inverse of GL_MODELVIEW_MATRIX (or the transpose if you are only interested in the rotation part, which is much much easier to compute).

For reference, this is how the view transform is set up in the same engine:


 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(camera->fov, asp, camera->nearplane, camera->farplane);

 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 glMultMatrixf( camera->transform->GetInverse() );

Hope that helps.

Many thanks for your answer. I’ll try again tomorrow. I’ve spent over a week on this:
http://www.xsquawkbox.net/xpsdk/mediawiki/ScreenCoordinates#Aircraft_Coordinates

Still only a mess…But I’m on Linux, should I still use your link? Anyway later also on Mac & Win.
Any ideas on how to set sound positions using the above? Should move accordingly with the airplane. I also have a moving camera x,y,z and heading.
Regards Michael

As for now it looks like the sources are not moved. Do i need anything else as?
alSourcefv(Sources[1], AL_POSITION, SourcesPos[1]);
Thanks

PS: On Ubuntu I’ve the latest OpenAL

Apologies for late response.

In the situation I posted above: in our engine we use Y=up, positive X-axis is to the right, and positive Z is pointing towards the rear of the viewer.

OpenAL source position is in world space if you set AL_SOURCE_RELATIVE to false:


alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcefv(source, AL_POSITION, pos);

To play local sounds (for example for GUI button clicks, music etc):


alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcefv(source, AL_POSITION, vec3(0,0,0) );

As for audio drivers, I haven’t used Ubuntu in a while, but if your drivers are from Creative Labs, Realtek etc, I wouldn’t trust it. I think OpenAL-Soft is distributed with some major distros (or at least readily available).

Think of OpenAL-Soft as reference implementation. Creative Labs’ own reference implementation is depreciated by their own programmers (and thankfully no longer available). If you can get it to work with OpenAL-Soft, it should be correct.