I am writing a OpenGL game engine and also an editor for the engine. In my editor, I can import 3D models from FBX/Collada as a scene graph. Now I want to implement the option for the user to rotate and the camera in the viewport using mouse.
I found many links to rotate the camera by some angle based on the delta x and delta y of the mouse. This is fine. But my problem is selecting the axis for rotation.
For example, if the user moves the mouse in the x axis, I am changing the camera's local rotation angle along y axis (the up axis). But this is not always working. In case if the camera node's parent node is rotated 90 degree in the x axis, when I change the camera's local y axis rotation angle, the scene is rotating in wrong direction. So in this case I have to rotate the camera's z axis angle.
This is my problem. So how can I ensure the camera always finally rotate left and right (whatever the parent nodes' angles are rotated) when the user moves the mouse horizontally?
Also I want to mention that when the user moves mouse up and down, I want the camera to rotate up and down always.