views:

34

answers:

1

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];
+1  A: 

In an Y-up world, the global "up" vector is the local "Y" vector. Or, put another way, if you put in "0, 1, 0" into the transform, it will come out pointing "up."

In an OpenGL matrix, this means that the second column is your "up" vector. You can extract it as follows:

float *myMatrix = ...;
myUpVector = Vector3(myMatrix[4], myMatrix[5], myMatrix[6]);
Jon Watte
this is a huge improvement, but it seems like I still may have something wrong. I tried always using an up of 0,1,0 in the gluLookAt() but that doesn't seem to work as well as re-using the previous cam->UP values pulled out of the matrix after the previous gluLookAt() as described.
It seems like should always pass the current UP vector to gluLookAt, and not send it 0,1,0 every time. I'm still getting the hang of this. I'm making an inch of progress every day now.. I hope the pace of learning picks up soon! Thanks for your help Jon.
Research shows that it takes about 10,000 hours of practice to become a master of any given subject.Good luck! :-)
Jon Watte