Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_SCREEN_2_OBJECT_H
00002 #define OPENTISSUE_UTILITY_GL_GL_SCREEN_2_OBJECT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013
00014 namespace OpenTissue
00015 {
00016
00017 namespace gl
00018 {
00019
00031 inline void Screen2Object( int sx, int sy, double & ox, double & oy, double & oz )
00032 {
00033 GLdouble projMatrix[ 16 ];
00034 GLdouble modelViewMatrix[ 16 ];
00035 GLint viewPort[ 4 ];
00036
00037 glGetDoublev( GL_MODELVIEW_MATRIX, modelViewMatrix );
00038 glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
00039 glGetIntegerv( GL_VIEWPORT, viewPort );
00040
00041 GLfloat wx = sx;
00042 GLfloat wy = viewPort[ 3 ] - sy;
00043 GLfloat wz = 0;
00044
00045
00046 glReadPixels( static_cast<int>( wx ), static_cast<int>( wy ), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &wz );
00047
00048 gluUnProject(
00049 wx, wy, wz
00050 , modelViewMatrix, projMatrix, viewPort
00051 , &ox, &oy, &oz
00052 );
00053 }
00054
00055 }
00056
00057 }
00058
00059
00060 #endif