I'm just starting out teaching myself openGL and now adding openAL to the mix.
I have some planets scattered around in 3D space and when I touch the screen, I'm assigning a sound to a random planet and then slowly and smoothly flying the "camera" over to look at it and listen to it. The animation/tweening part is working perfectly, but the openAL piece isn't quiet right. I move the camera around by doing a tiny translate() and gluLookAt() for every frame to keep things smooth (tweening the camera position and lookAt coords). The trouble seems to be with the stereo image I'm getting out of the headphones.. it seems like the left/right/up/down is mixed up sometimes after the camera rolls or spins. I am pretty sure the trouble is here:
ALfloat listenerPos[]={camera->currentX,camera->currentY,camera->currentZ};
ALfloat listenerOri[]={camera->currentLookX,
camera->currentLookY,
camera->currentLookZ,
0.0,//Camera Up X <--- here
0.1,//Camera Up Y <--- here
0.0}//Camera Up Z <--- and here
alListenerfv(AL_POSITION,listenerPos);
alListenerfv(AL_ORIENTATION,listenerOri);
I'm wondering if I need to recompute the UP vector for the camera after each gluLookAt() to straighten out the audio positioning problem.. That seems like it could be the missing ingredient, but the math involved seems so advanced I'm not even sure where to begin..
1) Is it correct that I'll need to recalculate the up vector after each gluLookAt()?
2) Could someone teach me how to calculate an up vector?
So would this be a correct way to get the up vector of the camera after the gluLookAt()?
gluLookAt(cam->currentX,
cam->currentY,
cam->currentZ,
cam->currentLookX,
cam->currentLookY,
cam->currentLookZ,
cam->upX,
cam->upY,
cam->upZ);
//Get the up vector
glGetFloatv( GL_MODELVIEW_MATRIX, cam->modelViewMatrix);
cam->upX = cam->modelViewMatrix[4];
cam->upY = cam->modelViewMatrix[5];
cam->upZ = cam->modelViewMatrix[6];