我很难开始gluLookAt
工作。我有以下代码可以按预期使用glTranslatef
:
import pyglet
from pyglet.gl import *
window = pyglet.window.Window()
def draw_square():
glBegin(GL_QUADS)
glVertex3f(0, 0, 0.0)
glVertex3f(100, 0, 0.0)
glVertex3f(100, 100, 0.0)
glVertex3f(0, 100, 0.0)
glEnd()
def on_draw():
window.clear()
draw_square()
from pyglet.window import key
@window.event
def on_key_press(symbol, modifiers):
SHIFT_X_BY = 5.5
if symbol == key.LEFT:
glTranslatef(-SHIFT_X_BY, 0.0, 0.0)
elif symbol == key.RIGHT:
glTranslatef(SHIFT_X_BY, 0.0, 0.0)
elif symbol == key.UP:
glTranslatef(0.0, SHIFT_X_BY, 0.0)
elif symbol == key.DOWN:
glTranslatef(0.0, -SHIFT_X_BY, 0.0)
window.on_draw = on_draw
pyglet.app.run()
glTranslatef
现在,我认为我可以移动相机而不是使用。我修改了代码来调用gluLookAt
:
import pyglet
from pyglet.gl import *
window = pyglet.window.Window(resizable=True)
def draw_square():
glBegin(GL_QUADS)
glVertex3f(0, 0, 0.0)
glVertex3f(100, 0, 0.0)
glVertex3f(100, 100, 0.0)
glVertex3f(0, 100, 0.0)
glEnd()
def on_draw():
window.clear()
draw_square()
pos = {'x': 0, 'y': 0, 'z': 0}
from pyglet.window import key
@window.event
def on_key_press(symbol, modifiers):
global pos
SHIFT_X_BY = 5.5
if symbol == key.LEFT:
pos['x'] = pos['x'] + SHIFT_X_BY
elif symbol == key.RIGHT:
pos['x'] = pos['x'] - SHIFT_X_BY
elif symbol == key.UP:
pos['y'] = pos['y'] + SHIFT_X_BY
elif symbol == key.DOWN:
pos['y'] = pos['y'] - SHIFT_X_BY
gluLookAt(pos['x'], pos['y'], pos['z'], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
window.on_draw = on_draw
pyglet.app.run()
但是,如果我现在按其中一个箭头键,方块就会消失。我打电话有什么问题gluLookAt
?
编辑以下on_draw()
功能也不起作用(我只是黑屏):
def on_draw():
glLoadIdentity()
gluLookAt(pos['x'], pos['y'], pos['z'], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
draw_square()