You would simply need to update the direction in which your camera is looking. You don't have to change the world matrix, the openGL "gluLookAt()" method does that for you automatically behind the scenes.
If you have a camera class setup, simply create a function to set the camera's up direction vector which you will need to obtain calculate based on a float/double value (i assume) from the iPhone's compass. When your camera update's it's lookAt() position it should change the camera to look in the correct location.
This is not that much different to what you do when you rotate your camera in an FPS based game. The difference is that you want to rotate the camera along the X-Axis instead of along the Y-Axis.
Take a look at how a camera class performs rotation for moving the camera left or right with the keyboard, then modify it to work using your compass direction values.
Here is some C++ code I wrote which may give you an insight as to how your camera class should be working:
/* This reshapes the camera using the perspective projection */
void Camera::ReshapePerspectiveForPicking( void )
{
glMatrixMode(GL_PROJECTION);
// Sets the clipping volume
gluPerspective( m_FieldOfView, (float)m_width/(float)m_height, m_zNear, m_zFar );
gluLookAt( camPos.x, camPos.y, camPos.z,
camPos.x + camView.x, camPos.y + camView.y, camPos.z + camView.z,
0.0f, 1.0f, 0.0f );
glMatrixMode( GL_MODELVIEW );
}
Take note to the line above (0.0f, 1.0f, 0.0f). This is the UP direction vector.
It was static for my game because the camera never needed to look down.
You would simply need to change this vector by created a new up vector on the compass orientation.
The method below was simply an alternative method we needed to sometimes update the camera by passing it a special vector. You can probably ignore it, I just included it so you could learn from it.
/* This updates the camera to look at the changed camera position. This uses a passed in camPosition and camView GameMath::Vector */
void Camera::Update( GameMath::Vector camPos, GameMath::Vector camView )
{
glMatrixMode( GL_PROJECTION );
gluLookAt( camPos.x, camPos.y, camPos.z,
camPos.x + camView.x, camPos.y + camView.y, camPos.z + camView.z,
0.0f, 1.0f,0.0f );
}
Here is my method for rotating the camera along the Y-Axis (Remember you want to rotate along the X-Axis) --I would rewrite this method now because it's kinda dodgey (I wrote it years ago) but it's enough to show you how it can be done.
void Camera::Rotate( void )
{
if ( m_rotateCamera == true )
{
// Keep the radians within 2 pi, roughly
float minimumRadiansRotate = 0.00;
float maximumRadiansRotate = 6.2831853072;
m_YRotateAngle = GameMath::Wrap( m_YRotateAngle, minimumRadiansRotate, maximumRadiansRotate );
m_YRotateAngle += m_rotateSpeed * m_rotateDirection; // Add to the camera's current angle value
camView.x = sin( m_YRotateAngle );
camView.z = -cos( m_YRotateAngle );
}
}
It's a bit difficult to provide you with a specific piece of code to do what you want to do because your camera class is probably different to mine, although this should get you to understand what needs to be done.
The CoreLocation framework contains the bits of code you will need to read values from the compass incase you haven't coded that part as yet.
Good luck.