I have a simple scene rendered in OpenGL that contains grid plane, same as you'd find in any 3D modeling app. I set the initial lookat position using a lookat matrix to point to the center of the scene (0,0). What I want to do is rotate the entire scene with the ground plane around 0,0 without affecting the Z orientation of the "camera." The way it is now, I detect the mouse position and use that to transform the scene via a rotation matrix. However, depending on the angle, the plane will cant fore/aft and won't stay perfectly level. I'm sure I'm missing some math to correct for the angles based on the eye position. I did some searching and found references to atan2(), which appears to be used to correct the angles but I'm not sure how to implement it. Here's what I have:
//set up lookat matrix once when app initializes to give some nice perspective
glMatrixMode(GL_MODELVIEW);
glMultMatrixf(lookat);
//rotate view around the scene
//x,y,z struct members are from the mouse position
glRotatef(userinput.rot.angle, userinput.rot.x, userinput.rot.y, userinput.rot.z);