The direction of rotations is given as a change in the viewing orientation with respect to the scene or object coordinate frame.
The unit vector describing the viewing orientation is related to the reference vector as: view = R * ref_view, where the ref_view = {0,0,1}. Additionally, the rotation angle around the view vector needs to be given.
The Euler angles defined as R(psi,theta,phi) = R(psi)*R(theta)*R(phi) with the individual angles taken around the z-, y- and z-axes, respectively, are related to the view vector and rotation angle around that vector as:
phi = arctan(view_y/view_x)
theta = arccos(view_z)
psi = angle - phi
Given Euler angles, the view vector and rotation angle is calculated as:
view_x = cos(phi) * sin(theta)
view_y = sin(phi) * sin(theta)
view_z = cos(theta)
angle = psi + phi
All calculations are passed through quaternion intermediates to avoid numerical instabilities in using Euler angles directly.