Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在三维空间中移动图像_Python_Opengl_Pyglet - Fatal编程技术网

Python 在三维空间中移动图像

Python 在三维空间中移动图像,python,opengl,pyglet,Python,Opengl,Pyglet,我正在尝试用python创建一个徽标可视化,我想在3D空间中设置一些图像的动画,这样图像总是“面向”屏幕的中心,并且图像在某个固定路径上移动。我以前使用python做过这项工作,但是,我希望在“免费”和跨平台的环境中完成这项工作 使用pyglet获取图像映射四边形的句柄(我可以操纵所述四边形的位置和方向)最快(读取的代码量最短)是什么?以下是我能想到的最简单的代码,它允许我将图像定位在位置(0,0,-10): 我发现最困难的部分是必须替换on_resize函数,才能像我预期的那样工作,因为默认的

我正在尝试用python创建一个徽标可视化,我想在3D空间中设置一些图像的动画,这样图像总是“面向”屏幕的中心,并且图像在某个固定路径上移动。我以前使用python做过这项工作,但是,我希望在“免费”和跨平台的环境中完成这项工作


使用pyglet获取图像映射四边形的句柄(我可以操纵所述四边形的位置和方向)最快(读取的代码量最短)是什么?

以下是我能想到的最简单的代码,它允许我将图像定位在位置(0,0,-10):

我发现最困难的部分是必须替换on_resize函数,才能像我预期的那样工作,因为默认的正交投影不起作用

我发现其中的一个最有帮助

完整的徽标可视化代码可以在我刚刚写的一篇题为“.”的博客中找到

#!/usr/bin/env python                                                           
import pyglet
from pyglet.gl import *

window = pyglet.window.Window()
glEnable(GL_DEPTH_TEST)

image = pyglet.image.load('imgs/appfolio.png')
texture = image.get_texture()
glEnable(texture.target)
glBindTexture(texture.target, texture.id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width, image.height,
             0, GL_RGBA, GL_UNSIGNED_BYTE,
             image.get_image_data().get_data('RGBA', image.width * 4))

rect_w = float(image.width) / image.height
rect_h = 1

@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glTranslatef(0, 0, -10)
    glBindTexture(texture.target, texture.id)
    glBegin(GL_QUADS)
    glTexCoord2f(0.0, 0.0); glVertex3f(-rect_w, -rect_h, 0.0)
    glTexCoord2f(1.0, 0.0); glVertex3f( rect_w, -rect_h, 0.0)
    glTexCoord2f(1.0, 1.0); glVertex3f( rect_w,  rect_h, 0.0)
    glTexCoord2f(0.0, 1.0); glVertex3f(-rect_w,  rect_h, 0.0)
    glEnd()

def on_resize(width, height):
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(65.0, width/float(height), 0.1, 1000.0)
    glMatrixMode(GL_MODELVIEW)

window.on_resize = on_resize # we need to replace so can't use @window.event    
pyglet.app.run()