1"""glu[Un]Project[4] convenience wrappers""" 2from OpenGL.raw import GLU as _simple 3from OpenGL import GL 4from OpenGL.lazywrapper import lazy as _lazy 5import ctypes 6POINTER = ctypes.POINTER 7 8@_lazy( _simple.gluProject ) 9def gluProject( baseFunction, objX, objY, objZ, model=None, proj=None, view=None ): 10 """Convenience wrapper for gluProject 11 12 Automatically fills in the model, projection and viewing matrices 13 if not provided. 14 15 returns (winX,winY,winZ) doubles 16 """ 17 if model is None: 18 model = GL.glGetDoublev( GL.GL_MODELVIEW_MATRIX ) 19 if proj is None: 20 proj = GL.glGetDoublev( GL.GL_PROJECTION_MATRIX ) 21 if view is None: 22 view = GL.glGetIntegerv( GL.GL_VIEWPORT ) 23 winX = _simple.GLdouble( 0.0 ) 24 winY = _simple.GLdouble( 0.0 ) 25 winZ = _simple.GLdouble( 0.0 ) 26 result = baseFunction( 27 objX,objY,objZ, 28 model,proj,view, 29 winX,winY,winZ, 30 ) 31 # On Ubuntu 9.10 we see a None come out of baseFunction, 32 # despite it having a return-type specified of GLint! 33 if result is not None and result != _simple.GLU_TRUE: 34 raise ValueError( """Projection failed!""" ) 35 return winX.value, winY.value, winZ.value 36 37@_lazy( _simple.gluUnProject ) 38def gluUnProject( baseFunction, winX, winY, winZ, model=None, proj=None, view=None ): 39 """Convenience wrapper for gluUnProject 40 41 Automatically fills in the model, projection and viewing matrices 42 if not provided. 43 44 returns (objX,objY,objZ) doubles 45 """ 46 if model is None: 47 model = GL.glGetDoublev( GL.GL_MODELVIEW_MATRIX ) 48 if proj is None: 49 proj = GL.glGetDoublev( GL.GL_PROJECTION_MATRIX ) 50 if view is None: 51 view = GL.glGetIntegerv( GL.GL_VIEWPORT ) 52 objX = _simple.GLdouble( 0.0 ) 53 objY = _simple.GLdouble( 0.0 ) 54 objZ = _simple.GLdouble( 0.0 ) 55 result = baseFunction( 56 winX,winY,winZ, 57 model,proj,view, 58 ctypes.byref(objX),ctypes.byref(objY),ctypes.byref(objZ), 59 ) 60 if not result: 61 raise ValueError( """Projection failed!""" ) 62 return objX.value, objY.value, objZ.value 63@_lazy( _simple.gluUnProject4 ) 64def gluUnProject4( 65 baseFunction, 66 winX, winY, winZ, clipW, 67 model=None, proj=None, view=None, 68 near=0.0, far=1.0 69): 70 """Convenience wrapper for gluUnProject 71 72 Automatically fills in the model, projection and viewing matrices 73 if not provided. 74 75 returns (objX,objY,objZ) doubles 76 """ 77 if model is None: 78 model = GL.glGetDoublev( GL.GL_MODELVIEW_MATRIX ) 79 if proj is None: 80 proj = GL.glGetDoublev( GL.GL_PROJECTION_MATRIX ) 81 if view is None: 82 view = GL.glGetIntegerv( GL.GL_VIEWPORT ) 83 objX = _simple.GLdouble( 0.0 ) 84 objY = _simple.GLdouble( 0.0 ) 85 objZ = _simple.GLdouble( 0.0 ) 86 objW = _simple.GLdouble( 0.0 ) 87 result = baseFunction( 88 winX,winY,winZ, 89 model,proj,view, 90 ctypes.byref(objX),ctypes.byref(objY),ctypes.byref(objZ),ctypes.byref(objW) 91 ) 92 if not result: 93 raise ValueError( """Projection failed!""" ) 94 return objX.value, objY.value, objZ.value, objW.value 95 96__all__ = ( 97 'gluProject', 98 'gluUnProject', 99 'gluUnProject4', 100) 101