创建修剪立方体Pyg的平面

2024-04-25 22:28:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个移动,缩放,旋转的立方体,我需要创建一个平面来修剪立方体,就像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()

Tags: andself绘图back平面frontglpgl
1条回答
网友
1楼 · 发布于 2024-04-25 22:28:32

使用Legacy OpenGL固定函数管道,可以设置剪裁平面。你知道吗

可以有多个剪辑平面,这些平面必须由^{}启用。你知道吗

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

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页。
注意,当前模型视图矩阵的逆矩阵在指定时应用于剪裁平面系数。你知道吗

参见基于问题代码的示例:

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()

相关问题 更多 >