问题描述
我正在使用pyglet在python中进行3d可视化,并且需要检索modelview和投影矩阵以进行一些选择.我使用以下命令定义窗口:
I'm doing 3d visualization in python using pyglet, and need to retrieve the modelview and projection matrices to do some picking. I define my window using:
from pyglet.gl import *
from pyglet.window import *
win = Window(fullscreen=True, visible=True, vsync=True)
然后定义所有窗口事件:
I then define all of my window events:
@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
当我单击时,它将打印...
When I click, it will print...
1.0
Segmentation fault
并崩溃.使用GL_MODELVIEW_MATRIX调用glGetFloatv应该返回16个值,但我不确定如何处理.我尝试定义a = GLfloat * 16,但出现以下错误:
and crash. Calling glGetFloatv with GL_MODELVIEW_MATRIX is supposed to return 16 values, and I'm not exactly sure how to handle that. I tried defining a = GLfloat*16 but I get the following error:
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_c_float instance instead of _ctypes.PyCArrayType
如何检索这些矩阵?
推荐答案
您需要传递16个元素的float数组.为此,请使用以下代码:
You need to pass 16 element float array. To do that use following code:
a = (GLfloat * 16)()
mvm = glGetFloatv(GL_MODELVIEW_MATRIX, a)
print list(a)
当然,您可以使用[0]语法访问"a"的各个元素.
Of course, you can access individual elements of "a" by using a[0] syntax.
这篇关于使用glGetFloatv检索pyglet中的modelview矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!