use*_*904 2 python opengl pyglet ray-picking
我正在使用pyglet在python中进行三维可视化,并且需要检索模型视图和投影矩阵来进行一些拾取.我使用以下方法定义窗口:
from pyglet.gl import *
from pyglet.window import *
win = Window(fullscreen=True, visible=True, vsync=True)
Run Code Online (Sandbox Code Playgroud)
然后我定义了所有窗口事件:
@win.event
def on_draw():
# All of the drawing happens here
@win.event
def on_mouse_release(x, y, button, modifiers):
if button == mouse.LEFT:
# This is where I'm having problems
a = GLfloat()
mvm = glGetFloatv(GL_MODELVIEW_MATRIX, a)
print a.value
Run Code Online (Sandbox Code Playgroud)
当我点击它,它将打印...
1.0
Segmentation fault
Run Code Online (Sandbox Code Playgroud)
和崩溃.用GL_MODELVIEW_MATRIX调用glGetFloatv应该返回16个值,我不确定如何处理它.我尝试定义一个= GLfloat*16,但是我收到以下错误:
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_c_float instance instead of _ctypes.PyCArrayType
Run Code Online (Sandbox Code Playgroud)
我该如何检索这些矩阵?
您需要传递16个元素的float数组.为此,请使用以下代码:
a = (GLfloat * 16)()
mvm = glGetFloatv(GL_MODELVIEW_MATRIX, a)
print list(a)
Run Code Online (Sandbox Code Playgroud)
当然,您可以使用[0]语法访问"a"的各个元素.