Skip to content

Instantly share code, notes, and snippets.

@v3c70r
Last active October 6, 2015 17:17
Show Gist options
  • Save v3c70r/0660c29992f241271435 to your computer and use it in GitHub Desktop.
Save v3c70r/0660c29992f241271435 to your computer and use it in GitHub Desktop.
rotationAxis.md

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:

  1. Picking three points in screen space, with same depth value. For example p0(0.0, 0.0, 0.0), p1(1.0, 0.0, 0.0), p2(0.0, 1.0, 0.0).

  2. Call gluUnproject() three times to unproject those points to object space. Assuming the three unprojected points are p1', p2', p3'.

  3. rotation axis = normalize( cross(p1'-p0', p2'-p0') );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment