Python Opengl鼠标点击冻结
我正在尝试实现一个相机,当你点击并拖动时,它会移动。它使用glutMouseFunc注册鼠标点击,这只是:Python Opengl鼠标点击冻结,python,opengl,mouse,Python,Opengl,Mouse,我正在尝试实现一个相机,当你点击并拖动时,它会移动。它使用glutMouseFunc注册鼠标点击,这只是: def on_click(self, button, state, x, y): if button == GLUT_LEFT_BUTTON: if state == GLUT_DOWN: self.dragging = True self.drag_x_origin = x
def on_click(self, button, state, x, y):
if button == GLUT_LEFT_BUTTON:
if state == GLUT_DOWN:
self.dragging = True
self.drag_x_origin = x
self.drag_y_origin = y
else:
self.dragging = False
在GlutPassiveEmotionFunc中,它具有:
def mouse_movement(self, x, y):
print "----------------------"
if self.dragging:
print "+++++++++++"
此时应打印“++++++++++++++”,但出于某种原因。锁上了。当我运行这个程序时,我会得到一系列无休止的“-------------------------”,直到我点击,然后它就停止了。我在显示功能中有打印功能,该功能仍然有效,但由于某种原因,该功能锁定。有人知道为什么吗
基本完整的代码:
class Camera():
def __init__(self):
self.camera_angle_horizontal = 1.0
self.camera_angle_vertical = 1.0
self.drag_x_origin = 0.0
self.drag_y_origin = 0.0
self.dragging = False
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowSize(500, 500)
glutInitWindowPosition(100, 100)
glutCreateWindow('cube')
self.init()
glutMouseFunc(self.on_click)
glutPassiveMotionFunc(self.mouse_movement)
glutDisplayFunc(self.display)
glutReshapeFunc(self.reshape)
glutKeyboardFunc(self.keyboard)
glutMainLoop()
def init(self):
glClearColor(0.0, 0.0, 0.0, 0.0)
glShadeModel(GL_FLAT)
def display(self):
print self.dragging, self.camera_angle_vertical, self.camera_angle_horizontal
...
glutPostRedisplay()
def reshape(self, w, h):
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(40.0, w / h, 1.0, 20.0)
#glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
glMatrixMode(GL_MODELVIEW)
def on_click(self, button, state, x, y):
if button == GLUT_LEFT_BUTTON:
if state == GLUT_DOWN:
self.dragging = True
else:
self.dragging = False
def mouse_movement(self, x, y):
print "----------------------"
if self.dragging:
print "+++++++++++"
c = Camera()
我当时使用的是
glutpassivemootionfunc(self.mouse\u movement)
而我本应该只使用glutmootionfunc(self.mouse\u movement)