gluLookAt unwanted rotation\spining

I’ve been programming for a while now on OpenGL and after implementing the gluLookAt function I found out that if the target goes 90 degrees sideways of the viewer (turn 90 degrees from original location) the camera spins sideways. If I were to change the Y axis the entire scene just rotates!

I’m well aware that this is a basic problem yet I’ve been unable to find on the web (and on this forum) any solution, and switching to rotation matrixes cant be a solution here.

I think there must be a solution involving the up vector, but I’ve got no idea as to the calculations needed to perform in order to “neutralize” the spining effect.

Thanks for the help

You may be experiencing gimbal lock if you are using euler angles.

As you noticed in the basic gluLookAt implementation, you can’t have view axis and up vector coinciding. You may have to implemnent rotations with quaternions to rotate around an arbitrary axis or just hack in gluLookAt code to change the up Vector to another one at runtime depending on your needs.