gpt4 book ai didi

python - 创建一个修剪立方体 Pyglet 的平面

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:31 25 4
gpt4 key购买 nike

我有一个移动、缩放、旋转的立方体,我需要创建一个平面来像那样修剪立方体 enter image description here

下面是绘图代码

pgl.glLoadIdentity()
pgl.glViewport(650, 500, 650, 500)
pgl.glMatrixMode(ogl.GL_PROJECTION)
pgl.glLoadIdentity()

pgl.gluPerspective(self.dist, 1.3, 1, 1000)

pgl.glMatrixMode(ogl.GL_MODELVIEW)

pgl.glTranslatef(0, 0, -400)

pgl.glPushMatrix()
pgl.glTranslatef(self.x, self.y, self.z)
pgl.glRotatef(self.xRotation, 1, 0, 0)
pgl.glRotatef(self.yRotation, 0, 1, 0)
pgl.glRotatef(self.zRotation, 0, 0, 1)
pgl.glScalef(self.zoom, self.zoom, self.zoom)


if not transparant:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
else:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)

draw_big()

pgl.glPopMatrix()

最佳答案

Legacy OpenGL固定功能管道,你可以设置一个裁剪平面。

可以有超过 1 个裁剪平面,这些平面必须由 glEnable(GL_CLIP_PLANEi) 启用.

平面由glClipPlane设置.剪切平面的参数被解释为 Plane Equation .平面方程的前 3 个分量是剪切平面的法向量。第 4 个分量是到原点的距离:

plane = plane = [-1.0, -1.0, -1.0, -280]
ogl.glClipPlane(pgl.GL_CLIP_PLANE0, plane)

有关详细规范,请参阅 OpenGL 4.6 API Compatibility Profile Specification - 13.7. PRIMITIVE CLIPPING ;第 537 页。
请注意,当前模型 View 矩阵的逆在指定时应用于裁剪平面系数。

看例子,是根据问题的代码:

def on_draw(self) :

self.clear()
pgl.glClear(pgl.GL_COLOR_BUFFER_BIT | pgl.GL_DEPTH_BUFFER_BIT)

pgl.glViewport(0, 0, 500, 500)

pgl.glMatrixMode(ogl.GL_PROJECTION)
pgl.glLoadIdentity()
pgl.gluPerspective(45, 1, 1, 1000)

pgl.glMatrixMode(ogl.GL_MODELVIEW)
pgl.glLoadIdentity()
pgl.glTranslatef(0, 0, -400)

pgl.glPushMatrix()
pgl.glTranslatef(self.x, self.y, self.z)
pgl.glRotatef(self.xRotation, 1, 0, 0)
pgl.glRotatef(self.yRotation, 0, 1, 0)
pgl.glRotatef(self.zRotation, 0, 0, 1)
pgl.glScalef(self.zoom, self.zoom, self.zoom)

if not transparant:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
else:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)

# set and enable clip plane
plane = plane = [-1.0, -1.0, -1.0, -280]
ogl.glEnable(pgl.GL_CLIP_PLANE0)
ogl.glClipPlane(pgl.GL_CLIP_PLANE0, plane)

draw_big()
ogl.glDisable(pgl.GL_CLIP_PLANE0)

pgl.glPopMatrix()

关于python - 创建一个修剪立方体 Pyglet 的平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55147297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com