First, you need to find a plan that parallel to projection plan in object space. gluUnproject() function gonna do the trick for you.
GLint gluUnProject(
GLdouble winX,
GLdouble winY,
GLdouble winZ,
const GLdouble * model,
const GLdouble * proj,
const GLint * view,
GLdouble* objX,
GLdouble* objY,
GLdouble* objZ
);
winX, winY, winZ
are a point in your screen space, i.e. the screen coordinate. model, proj, view
are three matrices in OpenGL pipline, you can query them with glGetDobuleV().
Here is how to get the rotation axis:
-
Picking three points in
screen space
, with same depth value. For examplep0(0.0, 0.0, 0.0), p1(1.0, 0.0, 0.0), p2(0.0, 1.0, 0.0)
. -
Call
gluUnproject()
three times to unproject those points toobject space
. Assuming the three unprojected points arep1', p2', p3'
. -
rotation axis = normalize( cross(p1'-p0', p2'-p0') );