# OpenAL and Irrlicht

## Recommended Posts

Amarth    122
I have this tiny problem with a testing program implementing Irrlicht and OpenAL.
void updateListener(ICameraSceneNode* cam){
ALfloat pos[3];
ALfloat ori[6];
pos[0] = cam->getPosition().X;
pos[1] = cam->getPosition().Y;
pos[2] = cam->getPosition().Z;

ori[0] = cam->getTarget().X;
ori[1] = cam->getTarget().Y;
ori[2] = cam->getTarget().Z;
ori[3] = cam->getUpVector().X;
ori[4] = cam->getUpVector().Y;
ori[5] = cam->getUpVector().Z;
alListenerfv(AL_POSITION,pos);
alListenerfv(AL_ORIENTATION,ori);
}


I know I could condense this a bit without the arrays, doesn't matter. The problem is that sound seems reversed, left and right are switched. I use this in a tiny program where I load a TestSceneNode and travel around with a CameraNodeFPS. There's nothing special... Initialisation is done with ALUT, everything seems to be alright. It *could* of course be that the device driver is wrong, or that my stereo system is just set up wrong, but I higly doubt it. I can post the full source to the program is that is any more helpful. It ain't that much bigger, but I don't think it's important. Most other variables are left at defaults. Any views on this? Thanks!

##### Share on other sites
owiley    257
maybe its that openal uses different coor

##### Share on other sites
Amarth    122
What the...

You're right.

I didn't quite expect Irrlicht to have a left-handed coordinate system.

Anyway, now for a solution...

[EDIT] Am I right in that I only need to change one sign of my lookat vector?
void updateListener(ICameraSceneNode* cam){	ALfloat pos[3];	ALfloat ori[6];	pos[0] = cam->getPosition().X;	pos[1] = cam->getPosition().Y;	pos[2] = cam->getPosition().Z;	ori[0] = cam->getTarget().X;	ori[1] = cam->getTarget().Y;	ori[2] = cam->-getTarget().Z;  //LHS to RHS	ori[3] = cam->getUpVector().X;	ori[4] = cam->getUpVector().Y;	ori[5] = cam->getUpVector().Z;	alListenerfv(AL_POSITION,pos);	alListenerfv(AL_ORIENTATION,ori);}

[Edited by - Amarth on April 24, 2006 2:13:49 PM]

##### Share on other sites
owiley    257
I think that should work did you take a look at the openal wrapper on the wiki site? my bad thats from site ogre. I'll see if i can code it up for you some time tommor im busy with work right now

##### Share on other sites
Amarth    122
I think the solution has to be to flip *all* the Z signs.

However, this doesn't solve it. It feels as if listener orientation doesn't change a thing... If I turn around, nothing changes, while the sound should be in the 'other ear'.

##### Share on other sites
Amarth    122
Finally solved it. getTarget() does not return the direction vector, but the actual target.
void updateListener(ICameraSceneNode* cam){	ALfloat pos[3];	ALfloat ori[6];	pos[0] = cam->getPosition().X;	pos[1] = cam->getPosition().Y;	pos[2] = -cam->getPosition().Z;	ori[0] = cam->getTarget().X - cam->getPosition().X;	ori[1] = cam->getTarget().Y - cam->getPosition().Y;	ori[2] = -(cam->getTarget().Z - cam->getPosition().Z);	ori[3] = cam->getUpVector().X;	ori[4] = cam->getUpVector().Y;	ori[5] = -cam->getUpVector().Z;	alListenerfv(AL_POSITION,pos);	alListenerfv(AL_ORIENTATION,ori);}

Hope this helps someone else.

##### Share on other sites
Guest Anonymous Poster
It helps me, thanks !

These at and up vectors are a nightmare, it's badly explained in the documentation.

##### Share on other sites
kburkhart84    3187
I use Irrlicht myself. I used to use it with OpenGL, which uses the same coordinate system as OpenAL, which I also used for a time. I got to liking DirectX's sound stuff a little better and since I only use windows, it works for me. I switched to Irrlicht to learn that positive Z is now in front instead of behind like in OpenAL/GL. It wasn't hard to switch, but yeah, using OpenAL for sound with it adds in a little bit of complication but for the most part, just switching the Z axis around should do the trick, but you have to do it for everything, not just sound positions.