本文整理汇总了Python中pipeline.Pipeline.set_camera方法的典型用法代码示例。如果您正苦于以下问题:Python Pipeline.set_camera方法的具体用法?Python Pipeline.set_camera怎么用?Python Pipeline.set_camera使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pipeline.Pipeline
的用法示例。
在下文中一共展示了Pipeline.set_camera方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_display
# 需要导入模块: from pipeline import Pipeline [as 别名]
# 或者: from pipeline.Pipeline import set_camera [as 别名]
def on_display(self):
"""
Rendering callback.
"""
self._camera.render()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self._scale += 0.1
pipeline = Pipeline(rotation=[0, self._scale, 0],
translation=[0, 0, 6],
projection=self._projection)
pipeline.set_camera(self._camera)
self._effect.set_wvp(pipeline.get_wvp())
self._effect.set_directional_light(
self._dir_light_color, self._dir_light_ambient_intensity)
position, tex_coord = 0, 1
glEnableVertexAttribArray(position)
glEnableVertexAttribArray(tex_coord)
glBindBuffer(GL_ARRAY_BUFFER, self._vbo)
glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 20, ctypes.c_void_p(0))
glVertexAttribPointer(tex_coord, 2, GL_FLOAT, GL_FALSE, 20, ctypes.c_void_p(12))
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self._ibo)
self._texture.bind(GL_TEXTURE0)
glDrawElements(GL_TRIANGLES, 18, GL_UNSIGNED_INT, ctypes.c_void_p(0))
glDisableVertexAttribArray(position)
glDisableVertexAttribArray(tex_coord)
glutSwapBuffers()
示例2: display
# 需要导入模块: from pipeline import Pipeline [as 别名]
# 或者: from pipeline.Pipeline import set_camera [as 别名]
def display():
CAMERA.render()
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
nonlocal scale
scale_location = gl.glGetUniformLocation(program, "gScale")
assert scale_location != 0xffffffff
world_location = gl.glGetUniformLocation(program, "gWorld")
assert world_location != 0xffffffff
scale += 0.01
pipeline = Pipeline(rotation=[0.0, 30*scale, 0.0],
# scaling=[math.sin(scale)] * 3,
translation=[0, 0, 6],
projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0, 60.0))
pipeline.set_camera(CAMERA)
gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE, pipeline.get_wvp())
gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
glut.glutSwapBuffers()
示例3: GlPlotWidget
# 需要导入模块: from pipeline import Pipeline [as 别名]
# 或者: from pipeline.Pipeline import set_camera [as 别名]
class GlPlotWidget(QGLWidget):
width, height = 600, 600
def __init__(self):
super(GlPlotWidget, self).__init__()
self.vbo = None
self.ibo = None
self.pipeline = None
self.camera = None
self.data = np.array([])
self.index = np.array([])
self.count = 0
self.step = 0.0
self.shaders = {
GL_VERTEX_SHADER: os.path.join('qtwindow', 'vs.glsl'),
GL_FRAGMENT_SHADER: os.path.join('qtwindow', 'fs.glsl')
}
self.program = None
self.initializeGL()
def set_data(self, data, index):
self.data = data
self.index = index
self.count = data.shape[0]
def initializeGL(self):
glClear(GL_COLOR_BUFFER_BIT)
glClearColor(0, 0, 0, 1)
self.vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
glBufferData(GL_ARRAY_BUFFER,
self.data.nbytes, self.data, GL_STATIC_DRAW)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(0))
self.ibo = glGenBuffers(1)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
self.index.nbytes, self.index, GL_STATIC_DRAW)
# load and compile shaders
self.program = glCreateProgram()
for t, path in self.shaders.items():
shader = glCreateShader(t)
with open(path, 'r') as sh:
glShaderSource(shader, sh.read())
glCompileShader(shader)
if not glGetShaderiv(shader, GL_COMPILE_STATUS):
info = glGetShaderInfoLog(shader)
print("{} shader error occurred".format(os.path.basename(path)))
print(bytes.decode(info))
sys.exit(1)
glAttachShader(self.program, shader)
# glDeleteShader(shader)
glLinkProgram(self.program)
glUseProgram(self.program)
# init camera
camera_pos = [0.0, 0.0, 0.0] # camera position
camera_target = [0.0, 0.0, 1.0] # "look at" direction
camera_up = [0.0, 1.0, 0.0] # camera vertical axis
def warp_pointer(cx, cy):
c = self.cursor()
self.cursor()
c.setPos(self.mapToGlobal(QPoint(cx, cy)))
c.setShape(Qt.BlankCursor)
self.setCursor(c)
self.camera = Camera(camera_pos, camera_target, camera_up,
self.width, self.height, warp_pointer)
#self.pipeline.set_camera(self.camera)
def paintGL(self):
self.step += 0.1
self.camera.render()
projection = ProjParams(self.width, self.height, 1.0, 100.0, 60.0)
self.pipeline = Pipeline(rotation=[0, 30*self.step, 0],
translation=[0, 0, 3],
projection=projection)
self.pipeline.set_camera(self.camera)
glClear(GL_COLOR_BUFFER_BIT)
glEnableVertexAttribArray(0)
world_location = glGetUniformLocation(self.program, "gWorld")
glUniformMatrix4fv(world_location, 1, GL_TRUE, self.pipeline.get_wvp())
glDrawElements(GL_TRIANGLES, self.index.shape[0],
GL_UNSIGNED_INT, ctypes.c_void_p(0))
glDisableVertexAttribArray(0)
def resizeGL(self, width, height):
self.width, self.height = width, height
glViewport(0, 0, self.width, self.height)