Thread: [PyOpenGL-Users] gluUnProject Projection Failed
Brought to you by:
mcfletch
From: Eleftherios G. <gar...@gm...> - 2010-04-12 17:57:13
|
Hello, I am using the pyopengl version 3.0.0 in Ubuntu 9.10 and I am trying to get a pick ray when I press 'p' in the keyboard. To do that I found that is well suggested to use gluUnProject. if key == 'p': modelviewmatrix=gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX) print 'ModelViewMatrix' print modelviewmatrix projectionmatrix=gl.glGetDoublev(gl.GL_PROJECTION_MATRIX) print 'ProjectionMatrix' print projectionmatrix viewport=gl.glGetDoublev(gl.GL_VIEWPORT) print 'Viewport' print viewport print float(x), viewport[3]-float(y) wx,wy,wz= glu.gluUnProject(float(x),viewport[3]-float(y),0., modelviewmatrix, projectionmatrix, viewport) print 'World Coordinate' print wx,wy,wz And the output is giving me a value error projection failed as you can see below ModelViewMatrix [[ 1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. -150. 1.]] ProjectionMatrix [[ 1.28300059 0. 0. 0. ] [ 0. 1.73205078 0. 0. ] [ 0. 0. -1.00010002 -1. ] [ 0. 0. -0.20001 0. ]] Viewport [ 0. 0. 1080. 800.] 693.0 489.0 Traceback (most recent call last): File "_ctypes/callbacks.c", line 295, in 'calling callback function' File "scene.py", line 294, in keystroke viewport) File "/usr/lib/pymodules/python2.6/OpenGL/lazywrapper.py", line 9, in __call__ return wrapper( baseFunction, *args, **named ) File "/usr/lib/pymodules/python2.6/OpenGL/GLU/projection.py", line 60, in gluUnProject raise ValueError( """Projection failed!""" ) ValueError: Projection failed! Any ideas? Best wishes, Eleftherios |
From: Greg E. <gre...@ca...> - 2010-04-13 10:30:13
|
Eleftherios Garyfallidis wrote: > wx,wy,wz= glu.gluUnProject(float(x),viewport[3]-float(y),0., > modelviewmatrix, > projectionmatrix, > viewport) I don't think that 0 is a valid value for the z coordinate when you're unprojecting in a perspective projection. Also, to get a ray, you need to know *two* points in the scene. The way I do it is to call gluUnProject twice, once with z = the near plane, and once with z = the far plane. A line between the two resulting points gives you your pick ray. -- Greg |
From: Eleftherios G. <gar...@gm...> - 2010-04-14 09:59:29
|
Hello, Thank you again for your response. - Show quoted text - On Tue, Apr 13, 2010 at 11:20 AM, Greg Ewing <gre...@ca...>wrote: > Eleftherios Garyfallidis wrote: > > to get > >> the near plane I believe you need to gluUnProject with z=0. and to get the >> far plane you need to gluUnProject with z=1 >> > > You're quite right, I was misremembering, sorry. > > > Surprisingly, when I do glu.gluUnProject(x,viewport[3]-y,0.) and >> glu.gluUnProject(x,viewport[3]-y,1.) in PyOpenGL it seems it works fine but >> when I am feeding the transformation matrices by myself I am getting this >> error "Projection Failed". >> > > That sounds like there is something wrong with your matrices. > How are you getting them? Are you getting them directly from > OpenGL, or calculating them yourself? If you're calculating them > yourself, you might be making a mistake somewhere. > > What happens if you retrieve the relevant matrices from OpenGL > and feed them to gluUnProject? If that works, compare them with > your own matrices to see if there is a difference. > Yes this is what I am doing just calculating these matrices using the following PyOpenGL functions import OpenGL.GL as gl modelviewmatrix=gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX) projectionmatrix=gl.glGetDoublev(gl.GL_PROJECTION_MATRIX) viewport=gl.glGetDoublev(gl.GL_VIEWPORT) These matrices are numpy arrays do you think that it might be a problem when we put these as input in gluUnProject? Should I transform them into something else perhaps? By the way I do confirm that when using gluUnProject without feeding in the transformation matrices as in glu.gluUnProject(x,viewport[3] -y,0.) does work correctly :-) I made some tests with picking planes and the accuracy of picking was excellent!!! The tests involved checking if the segment AB (where A is near and B is far) intersects with planes. For my application I need to check against many planes so I made a function for this in cython. The link for the code is here http://github.com/Garyfallidis/Fos/blob/master/fos/core/collision.pyx Best wishes, Eleftherios |
From: Gary H. <gh...@di...> - 2010-04-14 16:47:54
|
Eleftherios Garyfallidis wrote: > Hello, > > Thank you again for your response. > > - Show quoted text - > On Tue, Apr 13, 2010 at 11:20 AM, Greg Ewing > <gre...@ca... <mailto:gre...@ca...>> wrote: > > Eleftherios Garyfallidis wrote: > > to get > > the near plane I believe you need to gluUnProject with z=0. > and to get the far plane you need to gluUnProject with z=1 > > > You're quite right, I was misremembering, sorry. > > > Surprisingly, when I do glu.gluUnProject(x,viewport[3]-y,0.) > and glu.gluUnProject(x,viewport[3]-y,1.) in PyOpenGL it seems > it works fine but when I am feeding the transformation > matrices by myself I am getting this error "Projection Failed". > > > That sounds like there is something wrong with your matrices. > How are you getting them? Are you getting them directly from > OpenGL, or calculating them yourself? If you're calculating them > yourself, you might be making a mistake somewhere. > > > What happens if you retrieve the relevant matrices from OpenGL > and feed them to gluUnProject? If that works, compare them with > your own matrices to see if there is a difference. > > > Yes this is what I am doing just calculating these matrices using > the following PyOpenGL functions > > import OpenGL.GL as gl > > modelviewmatrix=gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX) > > projectionmatrix=gl.glGetDoublev(gl.GL_PROJECTION_MATRIX) > > viewport=gl.glGetDoublev(gl.GL_VIEWPORT) I have not followed this thread at all -- so I don't know the history. Nevertheless, I see a potential problem. The call to gluUnProject expects the viewport to be passed in as integers (GLint*) so you should be using glGetIntegerv not glGetDoublev to get the viewport as an array of integers. Here's gluUnProject's spec: GLint gluUnProject( GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble * model, const GLdouble * proj, const GLint * view, // !!!!! GLdouble* objX, GLdouble* objY, GLdouble* objZ); Using glGetDoublev for the two matricies and glGetIntegerv for the viewport as input to gluUnProject has always worked well for me. > > These matrices are numpy arrays do you think that it might be a > problem when we put these as input in gluUnProject? Should I transform > them into something else perhaps? > > By the way I do confirm that when using gluUnProject without feeding > in the transformation matrices as in glu.gluUnProject(x,viewport[3] > -y,0.) does work correctly :-) I made some tests with picking planes > and the accuracy of picking was excellent!!! The tests involved > checking if the segment AB (where A is near and B is far) intersects > with planes. For my application I need to check against many planes so > I made a function for this in cython. The link for the code is here > > http://github.com/Garyfallidis/Fos/blob/master/fos/core/collision.pyx > > Best wishes, > Eleftherios > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > ------------------------------------------------------------------------ > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 |